Mercurial > pub > Impl
comparison Lib/IMPL/DOM/Schema/NodeSet.pm @ 125:a4b0a819bbda
Small fixes in IMPL::DOM::Schema
author | wizard |
---|---|
date | Thu, 10 Jun 2010 17:43:51 +0400 |
parents | cf3b6ef2be22 |
children | 1e7f03414b65 |
comparison
equal
deleted
inserted
replaced
124:e30bdd040fe3 | 125:a4b0a819bbda |
---|---|
22 $this->messageMin( $args{messageMin} || '%Schema.name% nodes expected'); | 22 $this->messageMin( $args{messageMin} || '%Schema.name% nodes expected'); |
23 $this->messageUnexpected( $args{messageUnexpected} || 'A %Node.nodeName% isn\'t allowed in %Node.parentNode.path%'); | 23 $this->messageUnexpected( $args{messageUnexpected} || 'A %Node.nodeName% isn\'t allowed in %Node.parentNode.path%'); |
24 } | 24 } |
25 | 25 |
26 sub Validate { | 26 sub Validate { |
27 my ($this,$node) = @_; | 27 my ($this,$node,$ctx) = @_; |
28 | 28 |
29 my @errors; | 29 my @errors; |
30 | 30 |
31 my %nodes; | 31 my %nodes; |
32 my $anyNode; | 32 my $anyNode; |
33 my $sourceSchema = $ctx->{Source} || $this->parentNode; | |
34 | |
33 foreach (@{$this->childNodes}) { | 35 foreach (@{$this->childNodes}) { |
34 if ($_->isa('IMPL::DOM::Schema::AnyNode')) { | 36 if ($_->isa('IMPL::DOM::Schema::AnyNode')) { |
35 $anyNode = {Schema => $_, Min => $_->minOccur, Max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur , Seen => 0 }; | 37 $anyNode = {Schema => $_, Min => $_->minOccur, Max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur , Seen => 0 }; |
36 } else { | 38 } else { |
37 $nodes{$_->name} = {Schema => $_, Min => $_->minOccur, Max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur , Seen => 0 }; | 39 $nodes{$_->name} = {Schema => $_, Min => $_->minOccur, Max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur , Seen => 0 }; |
40 | 42 |
41 foreach my $child ( @{$node->childNodes} ) { | 43 foreach my $child ( @{$node->childNodes} ) { |
42 if (my $info = $nodes{$child->nodeName} || $anyNode) { | 44 if (my $info = $nodes{$child->nodeName} || $anyNode) { |
43 $info->{Seen}++; | 45 $info->{Seen}++; |
44 push @errors,new IMPL::DOM::Schema::ValidationError ( | 46 push @errors,new IMPL::DOM::Schema::ValidationError ( |
45 Source => $this, | 47 Source => $sourceSchema, |
46 Node => $child, | 48 Node => $child, |
47 Parent => $node, | 49 Parent => $node, |
48 Schema => $info->{Schema}, | 50 Schema => $info->{Schema}, |
49 Message => $this->messageMax | 51 Message => $this->messageMax |
50 ) if ($info->{Max} and $info->{Seen} > $info->{Max}); | 52 ) if ($info->{Max} and $info->{Seen} > $info->{Max}); |
52 if (my @localErrors = $info->{Schema}->Validate($child)) { | 54 if (my @localErrors = $info->{Schema}->Validate($child)) { |
53 push @errors,@localErrors; | 55 push @errors,@localErrors; |
54 } | 56 } |
55 } else { | 57 } else { |
56 push @errors, new IMPL::DOM::Schema::ValidationError ( | 58 push @errors, new IMPL::DOM::Schema::ValidationError ( |
57 Source => $this, | 59 Source => $sourceSchema, |
58 Node => $child, | 60 Node => $child, |
59 Parent => $node, | 61 Parent => $node, |
60 Message => $this->messageUnexpected | 62 Message => $this->messageUnexpected |
61 ) | 63 ) |
62 } | 64 } |
63 } | 65 } |
64 | 66 |
65 foreach my $info (values %nodes) { | 67 foreach my $info (values %nodes) { |
66 push @errors, new IMPL::DOM::Schema::ValidationError ( | 68 push @errors, new IMPL::DOM::Schema::ValidationError ( |
67 Source => $this, | 69 Source => $sourceSchema, |
68 Schema => $info->{Schema}, | 70 Schema => $info->{Schema}, |
69 Parent => $node, | 71 Parent => $node, |
70 Message => $this->messageMin | 72 Message => $this->messageMin |
71 ) if $info->{Min} > $info->{Seen}; | 73 ) if $info->{Min} > $info->{Seen}; |
72 } | 74 } |