comparison Lib/IMPL/DOM/Schema.pm @ 104:196bf443b5e1

DOM::Schema RC0 inflators support, validation and some other things, Minor and major fixes almost for everything. A 'Source' property of the ValidationErrors generated from a NodeSet or a NodeList is subject to change in the future.
author wizard
date Tue, 11 May 2010 02:42:59 +0400
parents c289ed9662ca
children c8dfbbdd8005
comparison
equal deleted inserted replaced
103:c289ed9662ca 104:196bf443b5e1
13 require IMPL::DOM::Schema::Property; 13 require IMPL::DOM::Schema::Property;
14 require IMPL::DOM::Schema::SwitchNode; 14 require IMPL::DOM::Schema::SwitchNode;
15 require IMPL::DOM::Schema::Validator; 15 require IMPL::DOM::Schema::Validator;
16 require IMPL::DOM::Navigator::Builder; 16 require IMPL::DOM::Navigator::Builder;
17 require IMPL::DOM::XMLReader; 17 require IMPL::DOM::XMLReader;
18 require IMPL::DOM::Schema::InflateFactory;
18 19
19 use base qw(IMPL::DOM::Document); 20 use base qw(IMPL::DOM::Document);
20 use IMPL::Class::Property; 21 use IMPL::Class::Property;
21 use IMPL::Class::Property::Direct; 22 use IMPL::Class::Property::Direct;
22 use File::Spec; 23 use File::Spec;
108 } 109 }
109 110
110 sub Validate { 111 sub Validate {
111 my ($this,$node) = @_; 112 my ($this,$node) = @_;
112 113
113 if ( my ($schemaNode) = $this->selectNodes(sub { $_[0]->name eq $node->nodeName })) { 114 if ( my ($schemaNode) = $this->selectNodes(sub { $_->isa('IMPL::DOM::Schema::Node') and $_[0]->name eq $node->nodeName })) {
114 $schemaNode->Validate($node); 115 $schemaNode->Validate($node);
115 } else { 116 } else {
116 return new IMPL::DOM::Schema::ValidationError(Message=> "A specified document doesn't match the schema"); 117 return new IMPL::DOM::Schema::ValidationError(Message=> "A specified document doesn't match the schema");
117 } 118 }
118 } 119 }
130 IMPL::DOM::Schema::NodeSet->new()->appendRange( 131 IMPL::DOM::Schema::NodeSet->new()->appendRange(
131 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'), 132 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
132 IMPL::DOM::Schema::Node->new(name => 'ComplexType', type => 'ComplexType', minOccur => 0, maxOccur=>'unbounded'), 133 IMPL::DOM::Schema::Node->new(name => 'ComplexType', type => 'ComplexType', minOccur => 0, maxOccur=>'unbounded'),
133 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'), 134 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
134 IMPL::DOM::Schema::Node->new(name => 'SimpleType', type => 'SimpleType', minOccur => 0, maxOccur=>'unbounded'), 135 IMPL::DOM::Schema::Node->new(name => 'SimpleType', type => 'SimpleType', minOccur => 0, maxOccur=>'unbounded'),
135 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'), 136 IMPL::DOM::Schema::Node->new(name => 'Node', type => 'Node', minOccur => 0, maxOccur=>'unbounded'),
136 IMPL::DOM::Schema::SimpleNode->new(name => 'Include', minOccur => 0, maxOccur=>'unbounded')->appendRange( 137 IMPL::DOM::Schema::SimpleNode->new(name => 'Include', minOccur => 0, maxOccur=>'unbounded')->appendRange(
137 IMPL::DOM::Schema::Property->new(name => 'source') 138 IMPL::DOM::Schema::Property->new(name => 'source')
138 ) 139 )
139 ), 140 ),
140 ), 141 ),
141 IMPL::DOM::Schema::ComplexType->new(type => 'NodeSet', nativeType => 'IMPL::DOM::Schema::NodeSet')->appendRange( 142 IMPL::DOM::Schema::ComplexType->new(type => 'NodeSet', nativeType => 'IMPL::DOM::Schema::NodeSet')->appendRange(
142 IMPL::DOM::Schema::NodeSet->new()->appendRange( 143 IMPL::DOM::Schema::NodeSet->new()->appendRange(
143 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'), 144 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
144 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'), 145 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
145 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'), 146 IMPL::DOM::Schema::Node->new(name => 'Node', type=>'Node', minOccur => 0, maxOccur=>'unbounded'),
146 IMPL::DOM::Schema::SwitchNode->new(minOccur => 0, maxOccur => 1)->appendRange( 147 IMPL::DOM::Schema::SwitchNode->new(minOccur => 0, maxOccur => 1)->appendRange(
147 IMPL::DOM::Schema::SimpleNode->new(name => 'AnyNode'), 148 IMPL::DOM::Schema::Node->new(name => 'AnyNode', type => 'AnyNode'),
148 IMPL::DOM::Schema::Node->new(name => 'SwitchNode',type => 'SwitchNode') 149 IMPL::DOM::Schema::Node->new(name => 'SwitchNode',type => 'SwitchNode')
149 ) 150 )
150 ) 151 )
151 ), 152 ),
152 IMPL::DOM::Schema::ComplexType->new(type => 'SwitchNode', nativeType => 'IMPL::DOM::Schema::SwitchNode')->appendRange( 153 IMPL::DOM::Schema::ComplexType->new(type => 'SwitchNode', nativeType => 'IMPL::DOM::Schema::SwitchNode')->appendRange(
153 IMPL::DOM::Schema::NodeSet->new()->appendRange( 154 IMPL::DOM::Schema::NodeSet->new()->appendRange(
154 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type=>'ComplexNode', minOccur => 0, maxOccur=>'unbounded'), 155 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type=>'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
155 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type=>'SimpleNode', minOccur => 0, maxOccur=>'unbounded'), 156 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type=>'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
156 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'), 157 IMPL::DOM::Schema::Node->new(name => 'Node', type=>'Node', minOccur => 0, maxOccur=>'unbounded'),
157 ) 158 )
158 ), 159 ),
159 IMPL::DOM::Schema::ComplexType->new(type => 'NodeList', nativeType => 'IMPL::DOM::Schema::NodeList')->appendRange( 160 IMPL::DOM::Schema::ComplexType->new(type => 'NodeList', nativeType => 'IMPL::DOM::Schema::NodeList')->appendRange(
160 IMPL::DOM::Schema::NodeSet->new()->appendRange( 161 IMPL::DOM::Schema::NodeSet->new()->appendRange(
161 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'), 162 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
162 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'), 163 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
163 IMPL::DOM::Schema::Node->new(name => 'SwitchNode',type => 'SwitchNode', minOccur => 0, maxOccur=>'unbounded'), 164 IMPL::DOM::Schema::Node->new(name => 'SwitchNode',type => 'SwitchNode', minOccur => 0, maxOccur=>'unbounded'),
164 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'), 165 IMPL::DOM::Schema::Node->new(name => 'Node', type => 'Node', minOccur => 0, maxOccur=>'unbounded'),
165 IMPL::DOM::Schema::SimpleNode->new(name => 'AnyNode', minOccur => 0, maxOccur=>'unbounded'), 166 IMPL::DOM::Schema::Node->new(name => 'AnyNode', type => 'AnyNode', minOccur => 0, maxOccur=>'unbounded'),
166 ) 167 )
167 ), 168 ),
168 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexType', nativeType => 'IMPL::DOM::Schema::ComplexType')->appendRange( 169 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexType', nativeType => 'IMPL::DOM::Schema::ComplexType')->appendRange(
169 IMPL::DOM::Schema::NodeList->new()->appendRange( 170 IMPL::DOM::Schema::NodeList->new()->appendRange(
170 IMPL::DOM::Schema::SwitchNode->new()->appendRange( 171 IMPL::DOM::Schema::SwitchNode->new()->appendRange(
190 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange( 191 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange(
191 IMPL::DOM::Schema::NodeList->new()->appendRange( 192 IMPL::DOM::Schema::NodeList->new()->appendRange(
192 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0), 193 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
193 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator') 194 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
194 ), 195 ),
195 new IMPL::DOM::Schema::Property(name => 'type') 196 new IMPL::DOM::Schema::Property(name => 'type'),
197 new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
196 ), 198 ),
197 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleNode', nativeType => 'IMPL::DOM::Schema::SimpleNode')->appendRange( 199 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleNode', nativeType => 'IMPL::DOM::Schema::SimpleNode')->appendRange(
198 IMPL::DOM::Schema::NodeList->new()->appendRange( 200 IMPL::DOM::Schema::NodeList->new()->appendRange(
199 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0), 201 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
200 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator') 202 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
201 ), 203 ),
202 new IMPL::DOM::Schema::Property(name => 'name') 204 new IMPL::DOM::Schema::Property(name => 'name'),
205 new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
203 ), 206 ),
204 IMPL::DOM::Schema::ComplexType->new(type => 'Validator', nativeType => 'IMPL::DOM::Schema::Validator')->appendRange( 207 IMPL::DOM::Schema::ComplexType->new(type => 'Validator', nativeType => 'IMPL::DOM::Schema::Validator')->appendRange(
205 IMPL::DOM::Schema::NodeList->new()->appendRange( 208 IMPL::DOM::Schema::NodeList->new()->appendRange(
206 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0) 209 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
207 ) 210 )
208 ), 211 ),
209 IMPL::DOM::Schema::ComplexType->new(type => 'Property', nativeType => 'IMPL::DOM::Schema::Property' )->appendRange( 212 IMPL::DOM::Schema::ComplexType->new(type => 'Property', nativeType => 'IMPL::DOM::Schema::Property' )->appendRange(
210 IMPL::DOM::Schema::NodeList->new()->appendRange( 213 IMPL::DOM::Schema::NodeList->new()->appendRange(
211 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0) 214 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
212 ), 215 ),
213 IMPL::DOM::Schema::Property->new(name => 'name') 216 IMPL::DOM::Schema::Property->new(name => 'name'),
214 ) 217 new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
218 ),
219 IMPL::DOM::Schema::SimpleType->new(type => 'Node', nativeType => 'IMPL::DOM::Schema::Node')->appendRange(
220 IMPL::DOM::Schema::Property->new(name => 'name'),
221 IMPL::DOM::Schema::Property->new(name => 'type')
222 ),
223 IMPL::DOM::Schema::SimpleType->new(type => 'AnyNode', nativeType => 'IMPL::DOM::Schema::AnyNode')
215 ); 224 );
216 225
217 $schema->Process; 226 $schema->Process;
218 227
219 return $schema; 228 return $schema;