comparison Lib/IMPL/DOM/Schema/SwitchNode.pm @ 389:5aff94ba842f

DOM Schema refactoring complete
author cin
date Wed, 12 Feb 2014 13:36:24 +0400
parents b8c724f6de36
children
comparison
equal deleted inserted replaced
388:648dfaf642e0 389:5aff94ba842f
1 package IMPL::DOM::Schema::SwitchNode; 1 package IMPL::DOM::Schema::SwitchNode;
2 use strict; 2 use strict;
3 use warnings; 3 use warnings;
4 4
5 use parent qw(IMPL::DOM::Schema::AnyNode); 5 use IMPL::declare {
6 use IMPL::Class::Property; 6 require => {
7 require IMPL::DOM::Schema::ValidationError; 7 Label => 'IMPL::DOM::Schema::Label',
8 use IMPL::DOM::Property qw(_dom); 8 ValidationError => 'IMPL::DOM::Schema::ValidationError'
9 9 },
10 our %CTOR = ( 10 base => [
11 'IMPL::DOM::Schema::AnyNode' => sub { 11 'IMPL::DOM::Schema::AnyNode' => sub {
12 my %args = @_; 12 my %args = @_;
13 13
14 $args{nodeName} ||= 'SwitchNode'; 14 $args{nodeName} ||= 'SwitchNode';
15 15
16 %args; 16 %args;
17 } 17 }
18 ); 18 ],
19 19 props => [
20 BEGIN { 20 messageNoMatch => { get => 1, set => 1, dom => 1 }
21 public _dom property messageNoMatch => prop_all; 21 ]
22 } 22 };
23 23
24 sub CTOR { 24 sub CTOR {
25 my ($this,%args) = @_; 25 my ($this,%args) = @_;
26 26
27 $this->messageNoMatch($args{messageNoMatch} || 'A node %node.nodeName% isn\'t expected in the %parent.path%'); 27 $this->messageNoMatch($args{messageNoMatch} || 'A node %node.nodeName% isn\'t expected in the %parent.path%');
29 29
30 sub Validate { 30 sub Validate {
31 my ($this,$node,$ctx) = @_; 31 my ($this,$node,$ctx) = @_;
32 32
33 if ( my ($schema) = $this->selectNodes(sub {$_[0]->name eq $node->nodeName} ) ) { 33 if ( my ($schema) = $this->selectNodes(sub {$_[0]->name eq $node->nodeName} ) ) {
34 return $schema->Validate($node); 34 return $schema->Validate($node,$ctx);
35 } else { 35 } else {
36 return new IMPL::DOM::Schema::ValidationError( 36 return ValidationError->new(
37 node => $node, 37 node => $node,
38 source => $this, 38 message => $this->_MakeLabel($this->messageNoMatch)
39 message => $this->messageNoMatch
40 ); 39 );
41 } 40 }
41 }
42
43 sub _MakeLabel {
44 my ($this,$label) = @_;
45
46 if ($label =~ /^ID:(\w+)$/) {
47 return Label->new($this->document->stringMap, $1);
48 } else {
49 return $label;
50 }
42 } 51 }
43 52
44 1; 53 1;
45 54
46 __END__ 55 __END__