comparison Lib/IMPL/DOM/Schema.pm @ 34:a8086f85a571

Dom Builder
author Sergey
date Mon, 16 Nov 2009 18:39:25 +0300
parents 7f00786f8210
children c2e7f7c96bcd
comparison
equal deleted inserted replaced
33:0004faa276dc 34:a8086f85a571
21 'IMPL::DOM::Document' => sub { nodeName => 'schema' } 21 'IMPL::DOM::Document' => sub { nodeName => 'schema' }
22 ); 22 );
23 23
24 BEGIN { 24 BEGIN {
25 private _direct property _TypesMap => prop_all; 25 private _direct property _TypesMap => prop_all;
26 public _direct property BaseSchemas => prop_get | owner_set;
27 private _direct property _Validators => prop_all;
26 } 28 }
27 29
28 sub resolveType { 30 sub resolveType {
29 $_[0]->{$_TypesMap}->{$_[1]}; 31 $_[0]->{$_TypesMap}->{$_[1]};
30 } 32 }
33
34 #sub Create {
35 # my ($this,$nodeName,$class,$refArgs) = @_;
36
37 # goto &SUPER::Create unless $class eq 'IMPL::DOM::Schema::Validator'
38 #}
31 39
32 sub Process { 40 sub Process {
33 my ($this) = @_; 41 my ($this) = @_;
34 42
35 $this->{$_TypesMap} = { map { $_->type, $_ } $this->selectNodes(sub { $_[0]->nodeName eq 'ComplexType' || $_[0]->nodeName eq 'SimpleType' } ) }; 43 $this->{$_TypesMap} = { map { $_->type, $_ } $this->selectNodes(sub { $_[0]->nodeName eq 'ComplexType' || $_[0]->nodeName eq 'SimpleType' } ) };
39 my ($this,$node) = @_; 47 my ($this,$node) = @_;
40 48
41 if ( my ($schemaNode) = $this->selectNodes(sub { $_[0]->name eq $node->nodeName })) { 49 if ( my ($schemaNode) = $this->selectNodes(sub { $_[0]->name eq $node->nodeName })) {
42 $schemaNode->Validate($node); 50 $schemaNode->Validate($node);
43 } else { 51 } else {
44 return IMPL::DOM::Schema::ValidationError(Message=> "A specified document doesn't match the schema"); 52 return new IMPL::DOM::Schema::ValidationError(Message=> "A specified document doesn't match the schema");
45 } 53 }
46 } 54 }
47 55
48 my $schema; 56 my $schema;
49 57
97 IMPL::DOM::Schema::NodeList->new()->appendRange( 105 IMPL::DOM::Schema::NodeList->new()->appendRange(
98 IMPL::DOM::Schema::SwitchNode->new()->appendRange( 106 IMPL::DOM::Schema::SwitchNode->new()->appendRange(
99 IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'), 107 IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'),
100 IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'), 108 IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'),
101 ), 109 ),
102 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0) 110 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
103 ), 111 ),
104 new IMPL::DOM::Schema::Property(name => 'type') 112 new IMPL::DOM::Schema::Property(name => 'type')
105 ), 113 ),
106 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange( 114 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange(
107 IMPL::DOM::Schema::NodeList->new()->appendRange( 115 IMPL::DOM::Schema::NodeList->new()->appendRange(
108 IMPL::DOM::Schema::SwitchNode->new()->appendRange( 116 IMPL::DOM::Schema::SwitchNode->new()->appendRange(
109 IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'), 117 IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'),
110 IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'), 118 IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'),
111 ), 119 ),
112 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0) 120 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
113 ), 121 ),
114 new IMPL::DOM::Schema::Property(name => 'name') 122 new IMPL::DOM::Schema::Property(name => 'name')
115 ), 123 ),
116 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange( 124 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange(
117 IMPL::DOM::Schema::NodeSet->new()->appendRange( 125 IMPL::DOM::Schema::NodeSet->new()->appendRange(
118 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0) 126 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
119 ), 127 ),
120 new IMPL::DOM::Schema::Property(name => 'type') 128 new IMPL::DOM::Schema::Property(name => 'type')
121 ), 129 ),
122 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleNode', nativeType => 'IMPL::DOM::Schema::SimpleNode')->appendRange( 130 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleNode', nativeType => 'IMPL::DOM::Schema::SimpleNode')->appendRange(
123 IMPL::DOM::Schema::NodeSet->new()->appendRange( 131 IMPL::DOM::Schema::NodeSet->new()->appendRange(
132 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
133 ),
134 new IMPL::DOM::Schema::Property(name => 'name')
135 ),
136 IMPL::DOM::Schema::ComplexType->new(type => 'Validator', nativeType => 'IMPL::DOM::Schema::Validator')->appendRange(
137 IMPL::DOM::Schema::NodeList->new()->appendRange(
124 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0) 138 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
125 ), 139 ),
126 new IMPL::DOM::Schema::Property(name => 'name') 140 new IMPL::DOM::Schema::Property(name => 'name')
127 ) 141 )
128 ); 142 );
183 <Node minOcuur="0" maxOccur="unbounded" name="SimpleNode" type="SimpleNode"/> 197 <Node minOcuur="0" maxOccur="unbounded" name="SimpleNode" type="SimpleNode"/>
184 <SimpleNode minOcuur="0" maxOccur="unbounded" name="Node"/> 198 <SimpleNode minOcuur="0" maxOccur="unbounded" name="Node"/>
185 </NodeSet> 199 </NodeSet>
186 </ComplexType> 200 </ComplexType>
187 201
188
189 <ComplexType type="ComplexType"> 202 <ComplexType type="ComplexType">
190 <NodeList> 203 <NodeList>
191 <Node name="NodeSet" type="NodeContainer" minOcuur=0/> 204 <Node name="NodeSet" type="NodeContainer" minOcuur=0/>
192 <Node name="NodeList" type="NodeContainer" minOccur=0/> 205 <Node name="NodeList" type="NodeContainer" minOccur=0/>
193 <AnyNode minOccur="0" maxOccur="unbounded"/> 206 <AnyNode minOccur="0" maxOccur="unbounded" type="Validator"/>
194 </NodeList> 207 </NodeList>
195 </ComplexType> 208 </ComplexType>
196 209
197 <ComplexType type="ComplexNode"> 210 <ComplexType type="ComplexNode">
198 <NodeList> 211 <NodeList>
199 <Node name="NodeSet" type="NodeContainer" minOcuur=0/> 212 <Node name="NodeSet" type="NodeContainer" minOcuur=0/>
200 <Node name="NodeList" type="NodeContainer" minOccur=0/> 213 <Node name="NodeList" type="NodeContainer" minOccur=0/>
201 <AnyNode minOccur="0" maxOccur="unbounded"/> 214 <AnyNode minOccur="0" maxOccur="unbounded" type="Validator"/>
202 </NodeList> 215 </NodeList>
203 </ComplexType> 216 </ComplexType>
204 217
205 <ComplexType type="SimpleNode"> 218 <ComplexType type="SimpleNode">
206 <NodeSet> 219 <NodeSet>
220 <AnyNode minOccur=0 maxOccur="unbounded" type="Validator"/>
221 </NodeSet>
222 </ComplexType>
223
224 <ComplexType type="SimpleType">
225 <NodeSet>
226 <AnyNode minOccur=0 maxOccur="unbounded" type="Validator"/>
227 </NodeSet>
228 </ComplexType>
229
230 <ComplexType type="Validator">
231 <NodeSet>
207 <AnyNode minOccur=0 maxOccur="unbounded"/> 232 <AnyNode minOccur=0 maxOccur="unbounded"/>
208 </NodeSet> 233 </NodeSet>
209 </ComplexType> 234 </ComplexType>
210 235
211 <ComplexType type="SimpleType">
212 <NodeSet>
213 <AnyNode minOccur=0 maxOccur="unbounded"/>
214 </NodeSet>
215 </ComplexType>
216
217 </schema> 236 </schema>
218 237
219 =cut 238 =cut