annotate Lib/IMPL/DOM/Schema/NodeSet.pm @ 394:2c14f66efa08

minor changes
author cin
date Tue, 18 Feb 2014 18:17:20 +0400
parents 5aff94ba842f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
1 package IMPL::DOM::Schema::NodeSet;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
4
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
5 use IMPL::Const qw(:prop);
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
6 use IMPL::declare {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
7 require => {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
8 Label => 'IMPL::DOM::Schema::Label',
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
9 ValidationError => 'IMPL::DOM::Schema::ValidationError',
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
10 AnyNode => '-IMPL::DOM::Schema::AnyNode'
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
11 },
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
12 base => [
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
13 'IMPL::DOM::Node' => sub { nodeName => 'NodeSet' }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
14 ],
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
15 props => [
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
16 messageUnexpected => { get => 1, set => 1, dom => 1},
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
17 messageMax => { get => 1, set => 1, dom => 1},
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
18 messageMin => { get => 1, set => 1, dom => 1}
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
19 ]
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
20 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
21
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
22 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
23 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
24
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
25 $this->messageMax( $args{messageMax} || 'Too many %node.nodeName% nodes');
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
26 $this->messageMin( $args{messageMin} || '%schemaNode.name% nodes expected');
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
27 $this->messageUnexpected( $args{messageUnexpected} || 'A %node.nodeName% isn\'t allowed in %node.parentNode.path%');
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
28 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
29
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
30 sub Validate {
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
31 my ($this,$node,$ctx) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
32
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
33 my @errors;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
34
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
35 my %nodes;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
36 my $anyNode;
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
37
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
38 foreach (@{$this->childNodes}) {
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
39 if ($_->isa(AnyNode)) {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
40 $anyNode = {schemaNode => $_, min => $_->minOccur, max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur , seen => 0 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
41 } else {
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
42 $nodes{$_->name} = {schemaNode => $_, min => $_->minOccur, max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur , seen => 0 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
43 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
44 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
45
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
46 foreach my $child ( @{$node->childNodes} ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
47 if (my $info = $nodes{$child->nodeName} || $anyNode) {
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
48 $info->{seen}++;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
49 push @errors,ValidationError->new(
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
50 schemaNode => $info->{schemaNode},
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
51 node => $child,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
52 parent => $node,
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
53 message => $this->_MakeLabel($this->messageMax)
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
54 ) if ($info->{max} and $info->{seen} > $info->{max});
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
55
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
56 if (my @localErrors = $info->{schemaNode}->Validate($child)) {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
57 push @errors,@localErrors;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
58 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
59 } else {
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
60 push @errors, ValidationError->new(
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
61 node => $child,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
62 parent => $node,
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
63 message => $this->_MakeLabel($this->messageUnexpected)
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
64 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
65 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
66 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
67
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
68 foreach my $info (values %nodes) {
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
69 push @errors, ValidationError->new(
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
70 schemaNode => $info->{schemaNode},
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
71 parent => $node,
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
72 message => $this->_MakeLabel($this->messageMin)
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
73 ) if $info->{min} > $info->{seen};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
74 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
75
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
76 return @errors;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
77 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
78
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
79 sub _MakeLabel {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
80 my ($this,$label) = @_;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
81
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
82 if ($label =~ /^ID:(\w+)$/) {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
83 return Label->new($this->document->stringMap, $1);
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
84 } else {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
85 return $label;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
86 }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
87 }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
88
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
89 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
90
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
91 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
92
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
93 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
94
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
95 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
96
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
97 Содержимое для сложного узла. Порядок не важен. Дочерними элементами могут быть
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
98 только C<IMPL::DOM::Schema::ComplexNode> и C<IMPL::DOM::Schema::SimpleNode>.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
99
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
100 При проверке данного правила, проверяются имеющиеся элементы на соответсие схемы
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
101 и количества встречаемости, после чего проверяются количественные ограничения
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
102 для несуществующих элементов.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
103
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
104 =cut