annotate Lib/IMPL/DOM/Schema/NodeList.pm @ 404:9ef75f2029be default

sync
author cin
date Fri, 28 Aug 2015 19:54:53 +0300
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::NodeList;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
5
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
6 use IMPL::declare {
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
7 require => {
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
8 ValidationError => 'IMPL::DOM::Schema::ValidationError',
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
9 AnyNode => '-IMPL::DOM::Schema::AnyNode',
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
10 Label => 'IMPL::DOM::Schema::Label'
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
11 },
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
12 base => [
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
13 'IMPL::DOM::Node' => sub { nodeName => 'NodeList' }
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
14 ],
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
15 props => [
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
16 messageUnexpected => { get => 1, set => 1, dom => 1 },
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
17 messageNodesRequired => { get => 1, set => 1, dom => 1}
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
18 ]
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
19 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
20
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
21 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
22 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
23
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
24 $this->messageUnexpected($args{messageUnexpected} || 'A %node.nodeName% isn\'t allowed in %node.parentNode.path%');
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
25 $this->messageNodesRequired($args{messageNodesRequired} || 'A %schemaNode.name% is required in the node %parent.path%');
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
26 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
27
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
28 sub Validate {
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
29 my ($this,$node,$ctx) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
30
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
31 my @nodes = map {
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
32 {nodeName => $_->name, anyNode => $_->isa(AnyNode) , schemaNode => $_, max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur, min => $_->minOccur, seen => 0 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
33 } @{$this->childNodes};
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 $info = shift @nodes;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
36
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
37 foreach my $child ( @{$node->childNodes} ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
38 #skip schema elements
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
39 while ($info and not $info->{anyNode} and $info->{nodeName} ne $child->nodeName) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
40 # if possible of course :)
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
41 return ValidationError->new (
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
42 message => $this->_MakeLabel( $this->messageUnexpected ),
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
43 node => $child,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
44 parent => $node,
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
45 schemaNode => $info->{schemaNode}
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
46 ) if $info->{min} > $info->{seen}; # we trying to skip a schema node which has a quantifier
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
47
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
48 $info = shift @nodes;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
49 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
50
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
51 # return error if no more children allowed
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
52 return ValidationError->new (
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
53 message => $this->_MakeLabel( $this->messageUnexpected ),
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
54 node => $child,
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
55 parent => $node
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
56 ) unless $info;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
57
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
58 # it's ok, we found schema element for child
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
59
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
60 # validate
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
61 while (my @errors = $info->{schemaNode}->Validate( $child ) ) {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
62 if( $info->{anyNode} and $info->{seen} >= $info->{min} ) {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
63 # in case of any or switch node, skip it if possible
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
64 next if $info = shift @nodes;
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 return @errors;
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
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
69 $info->{seen}++;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
70
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
71 # check count limits
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
72 return ValidationError->new(
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
73 message => $this->_MakeLabel( $this->messageUnexpected ),
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
74 node => $child,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
75 parent => $node,
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
76 schemaNode => $info->{schemaNode},
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
77 ) if $info->{max} and $info->{seen} > $info->{max};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
78 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
79
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
80 # no more children left (but may be should :)
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
81 while ($info) {
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
82 return ValidationError->new(
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
83 message => $this->_MakeLabel( $this->messageNodesRequired ),
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
84 parent => $node,
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
85 schemaNode => $info->{schemaNode}
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
86 ) if $info->{seen} < $info->{min};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
87
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
88 $info = shift @nodes;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
89 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
90 return;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
91 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
92
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
93 sub _MakeLabel {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
94 my ($this,$label) = @_;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
95
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
96 if ($label =~ /^ID:(\w+)$/) {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
97 return Label->new($this->document->stringMap, $1);
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
98 } else {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
99 return $label;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
100 }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
101 }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 388
diff changeset
102
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
103 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
104
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
105 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
106
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
107 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
108
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
109 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
110
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
111 Содержимое для сложного узла. Порядок важен. Дочерними элементами могут быть
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
112 только 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
113
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
114 =cut