Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/Node.pm @ 389:5aff94ba842f
DOM Schema refactoring complete
author | cin |
---|---|
date | Wed, 12 Feb 2014 13:36:24 +0400 |
parents | 648dfaf642e0 |
children |
rev | line source |
---|---|
49 | 1 package IMPL::DOM::Schema::Node; |
2 use strict; | |
3 use warnings; | |
4 | |
381
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
5 use IMPL::Const qw(:prop); |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
6 use IMPL::declare { |
383 | 7 require => { |
8 Label => 'IMPL::DOM::Schema::Label' | |
9 }, | |
381
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
10 base => [ |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
11 'IMPL::DOM::Node' => sub { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
12 my %args = @_; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
13 delete @args{qw( |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
14 minOccur |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
15 maxOccur |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
16 type |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
17 name |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
18 )} ; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
19 $args{nodeName} ||= 'Node'; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
20 %args |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
21 } |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
22 ], |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
23 props => [ |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
24 minOccur => { get => 1, set => 1, direct => 1, dom => 1}, |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
25 maxOccur => { get => 1, set => 1, direct => 1, dom => 1}, |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
26 type => { get => 1, set => 1, direct => 1, dom => 1}, |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
27 name => { get => 1, set => 1, direct => 1, dom => 1}, |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
28 label => { get => '_getLabel', direct => 1 } |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
29 ] |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
30 }; |
49 | 31 |
381
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
32 sub _getLabel { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
33 my ($this) = @_; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
34 |
383 | 35 $this->{$label} ||= Label->new($this->document->stringMap, $this->name ); |
381
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
36 } |
49 | 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 { | |
384 | 48 my ($this,$node,$ctx) = @_; |
49 | 49 |
388 | 50 $ctx->{schemaNode} = $this; # запоминаем источник ссылки |
51 | |
384 | 52 if (my $schemaType = $this->{$type} ? $this->document->ResolveType($this->{$type}) : undef ) { |
388 | 53 my @errors = $schemaType->Validate($node,$ctx); |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
54 return @errors; |
49 | 55 } else { |
56 return (); | |
57 } | |
58 } | |
59 | |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
60 sub isOptional { |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
61 my ($this) = @_; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
62 |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
63 return $this->{$minOccur} ? 0 : 1; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
64 } |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
65 |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
66 sub isMultiple { |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
67 my ($this) = @_; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
68 |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
69 return ($this->{$maxOccur} eq 'unbounded' || $this->{$maxOccur} > 1 ) ? 1 : 0; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
70 } |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
71 |
49 | 72 sub qname { |
73 $_[0]->nodeName.'[name='.$_[0]->{$name}.']'; | |
74 } | |
75 | |
76 1; | |
77 | |
78 __END__ | |
79 =pod | |
80 | |
81 =head1 SYNOPSIS | |
82 | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
83 package SchemaEntity; |
165 | 84 use parent qw(IMPL::DOM::Schema::Node); |
49 | 85 |
86 sub Validate { | |
87 my ($this,$node) = @_; | |
88 } | |
89 | |
90 =head1 DESCRIPTION | |
91 | |
180 | 92 Базовый класс для элементов схемы. Также позволяет объявлять узлы определенного типа. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
93 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
94 =head1 MEMBERS |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
95 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
96 =head2 PROPERTIES |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
97 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
98 =over |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
99 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
100 =item C<[get,set] minOccur> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
101 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
102 C<default: 1>. |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
103 |
180 | 104 Минимальное количество повторений узла. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
105 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
106 =item C<[get,set] maxOccur> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
107 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
108 C<default: 1>. |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
109 |
180 | 110 Максимальное количество повторений узла |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
111 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
112 =item C<[get,set] type> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
113 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
114 C<default: undef> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
115 |
180 | 116 Имя типа из схемы. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
117 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
118 =item C<[get,set] name> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
119 |
180 | 120 Имя узла. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
121 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
122 =back |
49 | 123 |
124 =cut |