annotate Lib/IMPL/DOM/Schema/NodeList.pm @ 228:431db7034a88

Для синхронизации
author andrei <andrei@nap21.upri>
date Thu, 13 Sep 2012 17:55:01 +0400
parents d1676be8afcc
children 2904da230022
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;
165
76515373dac0 Added Class::Template,
wizard
parents: 152
diff changeset
4 use parent qw(IMPL::DOM::Node);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
5
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
6 use IMPL::Class::Property;
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 125
diff changeset
7 use IMPL::DOM::Property qw(_dom);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
8 require IMPL::DOM::Schema::ValidationError;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
9
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
10 our %CTOR = (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
11 'IMPL::DOM::Node' => sub { nodeName => 'NodeList' }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
12 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
13
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
14 BEGIN {
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 125
diff changeset
15 public _dom property messageUnexpected => prop_all;
1e7f03414b65 DOM: schema improvements
wizard
parents: 125
diff changeset
16 public _dom property messageNodesRequired => prop_all;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
17 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
18
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
19 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
20 my ($this,%args) = @_;
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 $this->messageUnexpected($args{messageUnexpected} || 'A %Node.nodeName% isn\'t allowed in %Node.parentNode.path%');
102
cf3b6ef2be22 Schema beta version
wizard
parents: 100
diff changeset
23 $this->messageNodesRequired($args{messageNodesRequired} || 'A %Schema.name% is required in the node %Parent.path%');
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
24 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
25
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
26 sub Validate {
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
27 my ($this,$node,$ctx) = @_;
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 my @nodes = map {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
30 {nodeName => $_->name, anyNode => $_->isa('IMPL::DOM::Schema::AnyNode') , Schema => $_, Max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur, Min => $_->minOccur, Seen => 0 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
31 } @{$this->childNodes};
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 $info = shift @nodes;
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
34 my $sourceSchema = $ctx->{Source} || $this->parentNode;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
35
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
36 foreach my $child ( @{$node->childNodes} ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
37 #skip schema elements
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
38 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
39 # if possible of course :)
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
40 return new IMPL::DOM::Schema::ValidationError (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
41 Message => $this->messageUnexpected,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
42 Node => $child,
102
cf3b6ef2be22 Schema beta version
wizard
parents: 100
diff changeset
43 Parent => $node,
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
44 Schema => $info->{Schema},
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
45 Source => $sourceSchema
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
46 ) if $info->{Min} > $info->{Seen};
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
52 return new IMPL::DOM::Schema::ValidationError (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
53 Message => $this->messageUnexpected,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
54 Node => $child,
102
cf3b6ef2be22 Schema beta version
wizard
parents: 100
diff changeset
55 Parent => $node,
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
56 Source => $sourceSchema
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
57 ) unless $info;
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 # it's ok, we found schema element for child
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
60 # but it may be any node or switching node wich would not satisfy current child
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
61
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
62 # validate
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
63 while (my @errors = $info->{Schema}->Validate($child)) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
64 if( $info->{anyNode} and $info->{Seen} >= $info->{Min} ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
65 # 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
66 next if $info = shift @nodes;
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 return @errors;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
69 }
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 $info->{Seen}++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
72
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
73 # check count limits
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
74 return new IMPL::DOM::Schema::ValidationError (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
75 Error => 1,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
76 Message => $this->messageUnexpected,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
77 Node => $child,
102
cf3b6ef2be22 Schema beta version
wizard
parents: 100
diff changeset
78 Parent => $node,
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
79 Source => $sourceSchema,
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
80 ) if $info->{Max} and $info->{Seen} > $info->{Max};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
81 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
82
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
83 # no more children left (but may be should :)
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
84 while ($info) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
85 return new IMPL::DOM::Schema::ValidationError (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
86 Error => 1,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
87 Message => $this->messageNodesRequired,
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
88 Source => $sourceSchema,
102
cf3b6ef2be22 Schema beta version
wizard
parents: 100
diff changeset
89 Parent => $node,
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
90 Schema => $info->{Schema}
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
91 ) if $info->{Seen} < $info->{Min};
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 $info = shift @nodes;
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 return;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
96 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
97
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
98 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
99
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
100 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
101
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
102 =pod
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 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
105
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
106 Содержимое для сложного узла. Порядок важен. Дочерними элементами могут быть
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
107 только 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
108
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
109 =cut