Mercurial > pub > Impl
diff lib/IMPL/DOM/Schema/ComplexType.pm @ 407:c6e90e02dd17 ref20150831
renamed Lib->lib
author | cin |
---|---|
date | Fri, 04 Sep 2015 19:40:23 +0300 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/IMPL/DOM/Schema/ComplexType.pm Fri Sep 04 19:40:23 2015 +0300 @@ -0,0 +1,64 @@ +package IMPL::DOM::Schema::ComplexType; +use strict; +use warnings; + +use IMPL::declare { + require => { + Label => 'IMPL::DOM::Schema::Label', + ValidationError => 'IMPL::DOM::Schema::ValidationError' + }, + base => [ + 'IMPL::DOM::Schema::ComplexNode' => sub { + my %args = @_; + $args{nodeName} ||= 'ComplexType'; + $args{minOccur} = 0; + $args{maxOccur} = 'unbounded'; + $args{name} ||= 'ComplexType'; + delete @args{qw(nativeType messageWrongType)}; + %args + } + ], + props => [ + nativeType => { get => 1, set => 1, direct => 1, dom => 1 }, + messageWrongType => { get => 1, set => 1, direct => 1, dom => 1 } + ] +}; + +sub CTOR { + my ($this,%args) = @_; + + $this->{$nativeType} = $args{nativeType}; + $this->{$messageWrongType} = $args{messageWrongType} || "A complex node '%node.path%' is expected to be %schemaType.nativeType%"; +} + +sub Validate { + my ($this, $node,$ctx) = @_; + + if ($this->{$nativeType}) { + return ValidationError->new ( + node => $node, + schemaNode => $ctx->{schemaNode} || $this, + schemaType => $this, + message => $this->_MakeLabel($this->messageWrongType) + ) unless $node->isa($this->{$nativeType}); + } + + return $this->SUPER::Validate($node,$ctx); +} + +sub qname { + $_[0]->nodeName.'[type='.$_[0]->type.']'; +} + +sub _MakeLabel { + my ($this,$label) = @_; + + if ($label =~ /^ID:(\w+)$/) { + return Label->new($this->document->stringMap, $1); + } else { + return $label; + } +} + + +1;