Mercurial > pub > Impl
view lib/IMPL/DOM/Schema/ComplexType.pm @ 418:3f38dabaf5cc ref20150831
sync
author | cin |
---|---|
date | Mon, 28 Dec 2015 15:11:35 +0300 |
parents | c6e90e02dd17 |
children |
line wrap: on
line source
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;