annotate Lib/IMPL/DOM/Schema/NodeList.pm @ 388:648dfaf642e0

DOM refactoring, removed inflators from DOM Schema, DOM validation - in progress
author cin
date Tue, 11 Feb 2014 20:22:01 +0400
parents b8c724f6de36
children 5aff94ba842f
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',
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
9 AnyNode => '-IMPL::DOM::Schema::AnyNode'
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
10 },
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
11 base => [
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
12 'IMPL::DOM::Node' => sub { nodeName => 'NodeList' }
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
13 ],
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
14 props => [
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
15 messageUnexpected => { get => 1, set => 1, dom => 1 },
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
16 messageNodesRequired => { get => 1, set => 1, dom => 1}
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
17 ]
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
18 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
19
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
20 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
21 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
22
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
23 $this->messageUnexpected($args{messageUnexpected} || 'A %node.nodeName% isn\'t allowed in %node.parentNode.path%');
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
24 $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
25 }
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 sub Validate {
125
a4b0a819bbda Small fixes in IMPL::DOM::Schema
wizard
parents: 102
diff changeset
28 my ($this,$node,$ctx) = @_;
49
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 my @nodes = map {
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
31 {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
32 } @{$this->childNodes};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
33
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
34 my $info = shift @nodes;
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 :)
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
40 return ValidationError->new (
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
41 message => $this->messageUnexpected,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
42 node => $child,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
43 parent => $node,
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
44 schemaNode => $info->{schemaNode}
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
45 ) if $info->{Min} > $info->{Seen};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
46
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
47 $info = shift @nodes;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
48 }
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 # return error if no more children allowed
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
51 return ValidationError->new (
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
52 message => $this->messageUnexpected,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
53 node => $child,
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
54 parent => $node
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
55 ) unless $info;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
56
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
57 # it's ok, we found schema element for child
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
58 # 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
59
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
60 # validate
388
648dfaf642e0 DOM refactoring,
cin
parents: 238
diff changeset
61 while (my @errors = $info->{schemaNode}->Validate($child)) {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
62 if( $info->{anyNode} and $info->{Seen} >= $info->{Min} ) {
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
69 $info->{Seen}++;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
72 return new IMPL::DOM::Schema::ValidationError (
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
73 message => $this->messageUnexpected,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
74 node => $child,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
75 parent => $node,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
76 source => $sourceSchema,
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
77 ) if $info->{Max} and $info->{Seen} > $info->{Max};
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) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
82 return new IMPL::DOM::Schema::ValidationError (
236
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
83 error => 1,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
84 message => $this->messageNodesRequired,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
85 source => $sourceSchema,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
86 parent => $node,
2904da230022 DOM refactoring
sergey
parents: 180
diff changeset
87 schema => $info->{Schema}
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
88 ) if $info->{Seen} < $info->{Min};
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 $info = shift @nodes;
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 return;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
93 }
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 1;
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 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
98
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
99 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
100
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
101 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
102
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
103 Содержимое для сложного узла. Порядок важен. Дочерними элементами могут быть
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
104 только 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
105
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
106 =cut