comparison Lib/IMPL/DOM/Schema.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents d1676be8afcc
children 6d8092d8ce1b
comparison
equal deleted inserted replaced
193:8e8401c0aea4 194:4d0e1962161c
35 sub resolveType { 35 sub resolveType {
36 $_[0]->{$_TypesMap}->{$_[1]}; 36 $_[0]->{$_TypesMap}->{$_[1]};
37 } 37 }
38 38
39 sub CTOR { 39 sub CTOR {
40 my ($this,%args) = @_; 40 my ($this,%args) = @_;
41 41
42 $this->{$baseDir} = ($args{baseDir} || '.'); 42 $this->{$baseDir} = ($args{baseDir} || '.');
43 } 43 }
44 44
45 sub Create { 45 sub Create {
46 my ($this,$nodeName,$class,$refArgs) = @_; 46 my ($this,$nodeName,$class,$refArgs) = @_;
47 47
48 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');
49 49
50 if ($class->isa('IMPL::DOM::Schema::Validator')) { 50 if ($class->isa('IMPL::DOM::Schema::Validator')) {
51 $class = "IMPL::DOM::Schema::Validator::$nodeName"; 51 $class = "IMPL::DOM::Schema::Validator::$nodeName";
52 unless (eval {$class->can('new')}) { 52 unless (eval {$class->can('new')}) {
53 eval "require $class; 1;"; 53 eval "require $class; 1;";
54 my $e = $@; 54 my $e = $@;
55 die new IMPL::Exception("Invalid validator",$class,$e) if $e; 55 die new IMPL::Exception("Invalid validator",$class,$e) if $e;
56 } 56 }
57 } 57 }
58 58
59 return $this->SUPER::Create($nodeName,$class,$refArgs); 59 return $this->SUPER::Create($nodeName,$class,$refArgs);
60 } 60 }
61 61
68 # build types map 68 # build types map
69 $this->{$_TypesMap} = { map { $_->type, $_ } $this->selectNodes(sub { $_[0]->nodeName eq 'ComplexType' || $_[0]->nodeName eq 'SimpleType' } ) }; 69 $this->{$_TypesMap} = { map { $_->type, $_ } $this->selectNodes(sub { $_[0]->nodeName eq 'ComplexType' || $_[0]->nodeName eq 'SimpleType' } ) };
70 } 70 }
71 71
72 sub Include { 72 sub Include {
73 my ($this,$file) = @_; 73 my ($this,$file) = @_;
74 74
75 my $schema = $this->LoadSchema(File::Spec->catfile($this->baseDir, $file)); 75 my $schema = $this->LoadSchema(File::Spec->catfile($this->baseDir, $file));
76 76
77 $this->appendRange( $schema->childNodes ); 77 $this->appendRange( $schema->childNodes );
78 } 78 }
79 79
80 sub LoadSchema { 80 sub LoadSchema {
81 my ($this,$file) = @_; 81 my ($this,$file) = @_;
82 82
83 $file = File::Spec->rel2abs($file); 83 $file = File::Spec->rel2abs($file);
84 84
85 my $class = ref $this || $this; 85 my $class = ref $this || $this;
86 86
87 my $reader = new IMPL::DOM::XMLReader( 87 my $reader = new IMPL::DOM::XMLReader(
88 Navigator => new IMPL::DOM::Navigator::Builder( 88 Navigator => new IMPL::DOM::Navigator::Builder(
89 $class, 89 $class,
90 $class->MetaSchema 90 $class->MetaSchema
91 ), 91 ),
92 SkipWhitespace => 1 92 SkipWhitespace => 1
93 ); 93 );
94 94
95 $reader->ParseFile($file); 95 $reader->ParseFile($file);
96 96
97 my $schema = $reader->Navigator->Document; 97 my $schema = $reader->Navigator->Document;
98 98
99 my ($vol,$dir) = File::Spec->splitpath($file); 99 my ($vol,$dir) = File::Spec->splitpath($file);
100 100
101 $schema->baseDir($dir); 101 $schema->baseDir($dir);
102 102
103 my @errors = $class->MetaSchema->Validate($schema); 103 my @errors = $class->MetaSchema->Validate($schema);
104 104
105 die new IMPL::Exception("Schema is invalid",$file,map( $_->Message, @errors ) ) if @errors; 105 die new IMPL::Exception("Schema is invalid",$file,map( $_->Message, @errors ) ) if @errors;
106 106
107 $schema->Process; 107 $schema->Process;
108 108
109 return $schema; 109 return $schema;
110 } 110 }
111 111
112 sub Validate { 112 sub Validate {
113 my ($this,$node) = @_; 113 my ($this,$node) = @_;
114 114
189 ), 189 ),
190 new IMPL::DOM::Schema::Property(name => 'name') 190 new IMPL::DOM::Schema::Property(name => 'name')
191 ), 191 ),
192 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange( 192 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange(
193 IMPL::DOM::Schema::NodeList->new()->appendRange( 193 IMPL::DOM::Schema::NodeList->new()->appendRange(
194 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0), 194 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
195 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator') 195 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
196 ), 196 ),
197 new IMPL::DOM::Schema::Property(name => 'type'), 197 new IMPL::DOM::Schema::Property(name => 'type'),
198 new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory') 198 new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
199 ), 199 ),
200 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleNode', nativeType => 'IMPL::DOM::Schema::SimpleNode')->appendRange( 200 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleNode', nativeType => 'IMPL::DOM::Schema::SimpleNode')->appendRange(
201 IMPL::DOM::Schema::NodeList->new()->appendRange( 201 IMPL::DOM::Schema::NodeList->new()->appendRange(
202 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0), 202 IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
203 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator') 203 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
204 ), 204 ),
205 new IMPL::DOM::Schema::Property(name => 'name'), 205 new IMPL::DOM::Schema::Property(name => 'name'),
206 new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory') 206 new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
207 ), 207 ),
209 IMPL::DOM::Schema::NodeList->new()->appendRange( 209 IMPL::DOM::Schema::NodeList->new()->appendRange(
210 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0) 210 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
211 ) 211 )
212 ), 212 ),
213 IMPL::DOM::Schema::ComplexType->new(type => 'Property', nativeType => 'IMPL::DOM::Schema::Property' )->appendRange( 213 IMPL::DOM::Schema::ComplexType->new(type => 'Property', nativeType => 'IMPL::DOM::Schema::Property' )->appendRange(
214 IMPL::DOM::Schema::NodeList->new()->appendRange( 214 IMPL::DOM::Schema::NodeList->new()->appendRange(
215 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0) 215 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
216 ), 216 ),
217 IMPL::DOM::Schema::Property->new(name => 'name'), 217 IMPL::DOM::Schema::Property->new(name => 'name'),
218 new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory') 218 new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
219 ), 219 ),
220 IMPL::DOM::Schema::SimpleType->new(type => 'Node', nativeType => 'IMPL::DOM::Schema::Node')->appendRange( 220 IMPL::DOM::Schema::SimpleType->new(type => 'Node', nativeType => 'IMPL::DOM::Schema::Node')->appendRange(
221 IMPL::DOM::Schema::Property->new(name => 'name'), 221 IMPL::DOM::Schema::Property->new(name => 'name'),
222 IMPL::DOM::Schema::Property->new(name => 'type') 222 IMPL::DOM::Schema::Property->new(name => 'type')
223 ), 223 ),
224 IMPL::DOM::Schema::SimpleType->new(type => 'AnyNode', nativeType => 'IMPL::DOM::Schema::AnyNode') 224 IMPL::DOM::Schema::SimpleType->new(type => 'AnyNode', nativeType => 'IMPL::DOM::Schema::AnyNode')
225 ); 225 );
226 226
227 $schema->Process; 227 $schema->Process;