comparison Lib/IMPL/DOM/Schema.pm @ 102:cf3b6ef2be22

Schema beta version
author wizard
date Fri, 07 May 2010 08:05:23 +0400
parents d8dc6cad3f55
children c289ed9662ca
comparison
equal deleted inserted replaced
101:d8dc6cad3f55 102:cf3b6ef2be22
34 34
35 sub resolveType { 35 sub resolveType {
36 $_[0]->{$_TypesMap}->{$_[1]}; 36 $_[0]->{$_TypesMap}->{$_[1]};
37 } 37 }
38 38
39 sub CTOR {
40 my ($this,%args) = @_;
41
42 $this->{$baseDir} = ($args{baseDir} || '.');
43 }
44
39 sub Create { 45 sub Create {
40 my ($this,$nodeName,$class,$refArgs) = @_; 46 my ($this,$nodeName,$class,$refArgs) = @_;
41 47
42 die new IMPL::Exception('Invalid node class') unless $class->isa('IMPL::DOM::Node'); 48 die new IMPL::Exception('Invalid node class') unless $class->isa('IMPL::DOM::Node');
43 49
44 if ($class->isa('IMPL::DOM::Schema::Validator')) { 50 if ($class->isa('IMPL::DOM::Schema::Validator')) {
45 $class = "IMPL::DOM::Schema::Validator::$nodeName"; 51 $class = "IMPL::DOM::Schema::Validator::$nodeName";
46 local $@;
47 unless (eval {$class->can('new')}) { 52 unless (eval {$class->can('new')}) {
48 eval "require $class; 1;"; 53 eval "require $class; 1;";
49 my $e = $@; 54 my $e = $@;
50 die new IMPL::Exception("Invalid validator",$class,$e) if $e; 55 die new IMPL::Exception("Invalid validator",$class,$e) if $e;
51 } 56 }
65 } 70 }
66 71
67 sub Include { 72 sub Include {
68 my ($this,$file) = @_; 73 my ($this,$file) = @_;
69 74
70 my $schema = $this->LoadSchema($file); 75 my $schema = $this->LoadSchema(File::Spec->catfile($this->baseDir, $file));
71 76
72 $this->appendRange( $schema->childNodes ); 77 $this->appendRange( $schema->childNodes );
73 } 78 }
74 79
75 sub LoadSchema { 80 sub LoadSchema {
76 my ($this,$file,$base) = @_; 81 my ($this,$file) = @_;
82
83 $file = File::Spec->rel2abs($file);
77 84
78 my $class = ref $this || $this; 85 my $class = ref $this || $this;
79 86
80 my $reader = new IMPL::DOM::XMLReader( 87 my $reader = new IMPL::DOM::XMLReader(
81 Navigator => new IMPL::DOM::Navigator::Builder( 88 Navigator => new IMPL::DOM::Navigator::Builder(
82 $class, 89 $class,
83 $class->MetaSchema 90 $class->MetaSchema
84 ) 91 )
85 ); 92 );
86 93
87 $reader->ParseFile($file) or die new IMPL::Exception("Failed to load a schema",$file); 94 $reader->ParseFile($file);
88 95
89 my $schema = $reader->Navigator->Document; 96 my $schema = $reader->Navigator->Document;
90 97
91 my ($vol,$dir) = File::Spec->splitpath($file); 98 my ($vol,$dir) = File::Spec->splitpath($file);
92 99
163 IMPL::DOM::Schema::NodeList->new()->appendRange( 170 IMPL::DOM::Schema::NodeList->new()->appendRange(
164 IMPL::DOM::Schema::SwitchNode->new()->appendRange( 171 IMPL::DOM::Schema::SwitchNode->new()->appendRange(
165 IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'), 172 IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'),
166 IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'), 173 IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'),
167 ), 174 ),
175 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
168 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator') 176 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
169 ), 177 ),
170 new IMPL::DOM::Schema::Property(name => 'type') 178 new IMPL::DOM::Schema::Property(name => 'type')
171 ), 179 ),
172 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange( 180 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange(
173 IMPL::DOM::Schema::NodeList->new()->appendRange( 181 IMPL::DOM::Schema::NodeList->new()->appendRange(
174 IMPL::DOM::Schema::SwitchNode->new()->appendRange( 182 IMPL::DOM::Schema::SwitchNode->new()->appendRange(
175 IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'), 183 IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'),
176 IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'), 184 IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'),
177 ), 185 ),
186 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
178 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator') 187 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
179 ), 188 ),
180 new IMPL::DOM::Schema::Property(name => 'name') 189 new IMPL::DOM::Schema::Property(name => 'name')
181 ), 190 ),
182 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(
183 IMPL::DOM::Schema::NodeSet->new()->appendRange( 192 IMPL::DOM::Schema::NodeList->new()->appendRange(
193 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
184 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator') 194 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
185 ), 195 ),
186 new IMPL::DOM::Schema::Property(name => 'type') 196 new IMPL::DOM::Schema::Property(name => 'type')
187 ), 197 ),
188 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleNode', nativeType => 'IMPL::DOM::Schema::SimpleNode')->appendRange( 198 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleNode', nativeType => 'IMPL::DOM::Schema::SimpleNode')->appendRange(
189 IMPL::DOM::Schema::NodeSet->new()->appendRange( 199 IMPL::DOM::Schema::NodeList->new()->appendRange(
200 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
190 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator') 201 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
191 ), 202 ),
192 new IMPL::DOM::Schema::Property(name => 'name') 203 new IMPL::DOM::Schema::Property(name => 'name')
193 ), 204 ),
194 IMPL::DOM::Schema::ComplexType->new(type => 'Validator', nativeType => 'IMPL::DOM::Schema::Validator')->appendRange( 205 IMPL::DOM::Schema::ComplexType->new(type => 'Validator', nativeType => 'IMPL::DOM::Schema::Validator')->appendRange(
195 IMPL::DOM::Schema::NodeList->new()->appendRange( 206 IMPL::DOM::Schema::NodeList->new()->appendRange(
196 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0) 207 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
197 ) 208 )
209 ),
210 IMPL::DOM::Schema::ComplexType->new(type => 'Property', nativeType => 'IMPL::DOM::Schema::Property' )->appendRange(
211 IMPL::DOM::Schema::NodeList->new()->appendRange(
212 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
213 ),
214 IMPL::DOM::Schema::Property->new(name => 'name')
198 ) 215 )
199 ); 216 );
200 217
201 $schema->Process; 218 $schema->Process;
202 219