407
|
1 package IMPL::DOM::Schema::Node;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 use IMPL::Const qw(:prop);
|
|
6 use IMPL::declare {
|
|
7 require => {
|
|
8 Label => 'IMPL::DOM::Schema::Label'
|
|
9 },
|
|
10 base => [
|
|
11 'IMPL::DOM::Node' => sub {
|
|
12 my %args = @_;
|
|
13 delete @args{qw(
|
|
14 minOccur
|
|
15 maxOccur
|
|
16 type
|
|
17 name
|
|
18 )} ;
|
|
19 $args{nodeName} ||= 'Node';
|
|
20 %args
|
|
21 }
|
|
22 ],
|
|
23 props => [
|
|
24 minOccur => { get => 1, set => 1, direct => 1, dom => 1},
|
|
25 maxOccur => { get => 1, set => 1, direct => 1, dom => 1},
|
|
26 type => { get => 1, set => 1, direct => 1, dom => 1},
|
|
27 name => { get => 1, set => 1, direct => 1, dom => 1},
|
|
28 label => { get => '_getLabel', direct => 1 }
|
|
29 ]
|
|
30 };
|
|
31
|
|
32 sub _getLabel {
|
|
33 my ($this) = @_;
|
|
34
|
|
35 $this->{$label} ||= Label->new($this->document->stringMap, $this->name );
|
|
36 }
|
|
37
|
|
38 sub CTOR {
|
|
39 my ($this,%args) = @_;
|
|
40
|
|
41 $this->{$minOccur} = defined $args{minOccur} ? $args{minOccur} : 1;
|
|
42 $this->{$maxOccur} = defined $args{maxOccur} ? $args{maxOccur} : 1;
|
|
43 $this->{$type} = $args{type};
|
|
44 $this->{$name} = $args{name} or die new IMPL::InvalidArgumentException('Argument is required','name');
|
|
45 }
|
|
46
|
|
47 sub Validate {
|
|
48 my ($this,$node,$ctx) = @_;
|
|
49
|
|
50 $ctx->{schemaNode} = $this; # запоминаем источник ссылки
|
|
51
|
|
52 if (my $schemaType = $this->{$type} ? $this->document->ResolveType($this->{$type}) : undef ) {
|
|
53 my @errors = $schemaType->Validate($node,$ctx);
|
|
54 return @errors;
|
|
55 } else {
|
|
56 return ();
|
|
57 }
|
|
58 }
|
|
59
|
|
60 sub isOptional {
|
|
61 my ($this) = @_;
|
|
62
|
|
63 return $this->{$minOccur} ? 0 : 1;
|
|
64 }
|
|
65
|
|
66 sub isMultiple {
|
|
67 my ($this) = @_;
|
|
68
|
|
69 return ($this->{$maxOccur} eq 'unbounded' || $this->{$maxOccur} > 1 ) ? 1 : 0;
|
|
70 }
|
|
71
|
|
72 sub qname {
|
|
73 $_[0]->nodeName.'[name='.$_[0]->{$name}.']';
|
|
74 }
|
|
75
|
|
76 1;
|
|
77
|
|
78 __END__
|
|
79 =pod
|
|
80
|
|
81 =head1 SYNOPSIS
|
|
82
|
|
83 package SchemaEntity;
|
|
84 use parent qw(IMPL::DOM::Schema::Node);
|
|
85
|
|
86 sub Validate {
|
|
87 my ($this,$node) = @_;
|
|
88 }
|
|
89
|
|
90 =head1 DESCRIPTION
|
|
91
|
|
92 Базовый класс для элементов схемы. Также позволяет объявлять узлы определенного типа.
|
|
93
|
|
94 =head1 MEMBERS
|
|
95
|
|
96 =head2 PROPERTIES
|
|
97
|
|
98 =over
|
|
99
|
|
100 =item C<[get,set] minOccur>
|
|
101
|
|
102 C<default: 1>.
|
|
103
|
|
104 Минимальное количество повторений узла.
|
|
105
|
|
106 =item C<[get,set] maxOccur>
|
|
107
|
|
108 C<default: 1>.
|
|
109
|
|
110 Максимальное количество повторений узла
|
|
111
|
|
112 =item C<[get,set] type>
|
|
113
|
|
114 C<default: undef>
|
|
115
|
|
116 Имя типа из схемы.
|
|
117
|
|
118 =item C<[get,set] name>
|
|
119
|
|
120 Имя узла.
|
|
121
|
|
122 =back
|
|
123
|
|
124 =cut
|