Mercurial > pub > Impl
diff Lib/IMPL/DOM/Schema/NodeList.pm @ 19:1ca530e5c9c5
DOM схема, требует переработки в части схемы для описания схем. Автоверификация не проходит
author | Sergey |
---|---|
date | Fri, 11 Sep 2009 16:30:39 +0400 |
parents | fffb153be599 |
children | 267460284fb3 |
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Schema/NodeList.pm Thu Sep 10 17:42:47 2009 +0400 +++ b/Lib/IMPL/DOM/Schema/NodeList.pm Fri Sep 11 16:30:39 2009 +0400 @@ -1,55 +1,67 @@ package IMPL::DOM::Schema::NodeList; use strict; use warnings; -use base qw(IMPL::DOM::Schema::Item); +use base qw(IMPL::DOM::Node); + use IMPL::Class::Property; +require IMPL::DOM::Schema::ValidationError; + +our %CTOR = ( + 'IMPL::DOM::Node' => sub { nodeName => 'NodeList' } +); BEGIN { - public property MessageUnexpected => prop_all; - public property MessageNodesRequired => prop_all; + public property messageUnexpected => prop_all; + public property messageNodesRequired => prop_all; +} + +sub CTOR { + my ($this,%args) = @_; + + $this->messageUnexpected($args{messageUnexpected} || 'A %Node.nodeName% isn\'t allowed here'); + $this->messageNodesRequired($args{messageNodesRequired} || 'A content of the node %Node.nodeName% is incomplete'); } sub Validate { my ($this,$node) = @_; my @nodes = map { - {nodeName => $_->nodeName, Schema => $_, Min => $_->minOccur, Max => $_->maxOccur, Seen => 0 } + {nodeName => $_->nodeName, anyNode => $_->isa('IMPL::DOM::Schema::AnyNode') , Schema => $_, Min => $_->minOccur eq 'unbounded' ? undef : $_->maxOccur, Max => $_->maxOccur, Seen => 0 } } @{$this->childNodes}; my $info = shift @nodes; foreach my $child ( @{$node->childNodes} ) { #skip schema elements - while ($info and $info->{nodeName} ne $child->nodeName) { + while ($info and not $info->{anyNode} and $info->{nodeName} ne $child->nodeName) { # if possible of course :) - return { - Error => 1, - Message => $this->MessageUnexpected, + return new IMPL::DOM::Schema::VaidationError ( + Message => $this->messageUnexpected, Node => $child, + Schema => $info->{Schema}, Source => $this - } if $info->{Min} > $info->{Seen}; + ) if $info->{Min} > $info->{Seen}; $info = shift @nodes; } # return error if no more children allowed - return { - Error => 1, - Message => $this->MessageUnexpected, + return new IMPL::DOM::Schema::VaidationError ( + Message => $this->messageUnexpected, Node => $child, Source => $this - } unless $info; + ) unless $info; # it's ok, we found schema element for him $info->{Seen}++; # check count limits - return { + return new IMPL::DOM::Schema::VaidationError ( Error => 1, - Message => $this->MessageUnexpected, + Message => $this->messageUnexpected, Node => $child, Source => $this, - } if $info->{Seen} > $info->{Max}; + ) if $info->{Max} and $info->{Seen} > $info->{Max}; # validate if (my @errors = $info->{Schema}->Validate($child)) { @@ -59,11 +71,12 @@ # no more children left (but may be should :) while ($info) { - return { + return new IMPL::DOM::Schema::VaidationError ( Error => 1, - Message => $this->MessageNodesRequired, + Message => $this->messageNodesRequired, + Node => $node, Source => $this - } if $info->{Seen} < $info->{Min}; + ) if $info->{Seen} < $info->{Min}; $info = shift @nodes; }