49
|
1 package IMPL::DOM::Schema::SwitchNode;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
389
|
5 use IMPL::declare {
|
|
6 require => {
|
|
7 Label => 'IMPL::DOM::Schema::Label',
|
|
8 ValidationError => 'IMPL::DOM::Schema::ValidationError'
|
|
9 },
|
|
10 base => [
|
|
11 'IMPL::DOM::Schema::AnyNode' => sub {
|
|
12 my %args = @_;
|
|
13
|
|
14 $args{nodeName} ||= 'SwitchNode';
|
|
15
|
|
16 %args;
|
|
17 }
|
|
18 ],
|
|
19 props => [
|
|
20 messageNoMatch => { get => 1, set => 1, dom => 1 }
|
|
21 ]
|
|
22 };
|
49
|
23
|
|
24 sub CTOR {
|
|
25 my ($this,%args) = @_;
|
|
26
|
238
|
27 $this->messageNoMatch($args{messageNoMatch} || 'A node %node.nodeName% isn\'t expected in the %parent.path%');
|
49
|
28 }
|
|
29
|
|
30 sub Validate {
|
125
|
31 my ($this,$node,$ctx) = @_;
|
|
32
|
49
|
33 if ( my ($schema) = $this->selectNodes(sub {$_[0]->name eq $node->nodeName} ) ) {
|
389
|
34 return $schema->Validate($node,$ctx);
|
49
|
35 } else {
|
389
|
36 return ValidationError->new(
|
236
|
37 node => $node,
|
389
|
38 message => $this->_MakeLabel($this->messageNoMatch)
|
49
|
39 );
|
|
40 }
|
|
41 }
|
|
42
|
389
|
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 }
|
|
51 }
|
|
52
|
49
|
53 1;
|
|
54
|
|
55 __END__
|
|
56
|
|
57 =pod
|
|
58
|
|
59 =head1 DESCRIPTION
|
|
60
|
180
|
61 Представляет узел, который может быть одним из узлов, которые лежат внутри него.
|
|
62 Это более строгий вариант C<IMPL::DOM::Schema::AnyNode>.
|
49
|
63
|
|
64 =cut
|