annotate Lib/IMPL/DOM/Schema/NodeSet.pm @ 68:739f1288ca84

Auth in progress
author wizard
date Tue, 23 Mar 2010 16:55:25 +0300
parents 16ada169ca75
children df6b4f054957
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
5 use base qw(IMPL::DOM::Node);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
6 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
7
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
8 our %CTOR = (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
9 'IMPL::DOM::Node' => sub { nodeName => 'NodeSet' }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
10 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
11
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
12 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
13 public property messageUnexpected => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
14 public property messageMax => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
15 public property messageMin => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
16 }
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 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
19 my ($this,%args) = @_;
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 $this->messageMax( $args{messageMax} || 'Too many %Node.nodeName% nodes');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
22 $this->messageMin( $args{messageMin} || '%Schema.name% nodes expected');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
23 $this->messageUnexpected( $args{messageUnexpected} || 'A %Node.nodeName% isn\'t allowed in %Node.parentNode.path%');
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 {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
27 my ($this,$node) = @_;
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 @errors;
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;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
32 my $anyNode;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
33 foreach (@{$this->childNodes}) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
34 if ($_->isa('IMPL::DOM::Schema::AnyNode')) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
35 $anyNode = {Schema => $_, Min => $_->minOccur, Max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur , Seen => 0 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
36 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
37 $nodes{$_->name} = {Schema => $_, Min => $_->minOccur, Max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur , Seen => 0 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
38 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
39 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
40
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
41 foreach my $child ( @{$node->childNodes} ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
42 if (my $info = $nodes{$child->nodeName} || $anyNode) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
43 $info->{Seen}++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
44 push @errors,new IMPL::DOM::Schema::ValidationError (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
45 Source => $this,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
46 Node => $child,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
47 Schema => $info->{Schema},
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
48 Message => $this->messageMax
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
49 ) if ($info->{Max} and $info->{Seen} > $info->{Max});
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 if (my @localErrors = $info->{Schema}->Validate($child)) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
52 push @errors,@localErrors;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
53 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
54 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
55 push @errors, new IMPL::DOM::Schema::ValidationError (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
56 Source => $this,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
57 Node => $child,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
58 Schema => $info->{Schema},
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
59 Message => $this->messageUnexpected
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
60 )
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 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
63
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
64 foreach my $info (values %nodes) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
65 push @errors, new IMPL::DOM::Schema::ValidationError (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
66 Source => $this,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
67 Schema => $info->{Schema},
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
68 Node => $node,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
69 Message => $this->messageMin
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
70 ) if $info->{Min} > $info->{Seen};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
71 }
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 return @errors;
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 1;
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 __END__
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 =pod
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 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
83
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
84 Содержимое для сложного узла. Порядок не важен. Дочерними элементами могут быть
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
85 только C<IMPL::DOM::Schema::ComplexNode> и C<IMPL::DOM::Schema::SimpleNode>.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
86
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 и количества встречаемости, после чего проверяются количественные ограничения
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 24
diff changeset
91 =cut