annotate lib/IMPL/DOM/Schema.pm @ 416:cc2cf8c0edc2 ref20150831

sync
author cin
date Thu, 29 Oct 2015 03:50:25 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::DOM::Schema;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3 use warnings;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use File::Spec;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 use IMPL::Const qw(:prop);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 use IMPL::declare {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 require => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 ComplexNode => 'IMPL::DOM::Schema::ComplexNode',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 ComplexType => 'IMPL::DOM::Schema::ComplexType',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 SimpleNode => 'IMPL::DOM::Schema::SimpleNode',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 SimpleType => 'IMPL::DOM::Schema::SimpleType',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 Node => 'IMPL::DOM::Schema::Node',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 AnyNode => 'IMPL::DOM::Schema::AnyNode',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 NodeList => 'IMPL::DOM::Schema::NodeList',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 NodeSet => 'IMPL::DOM::Schema::NodeSet',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 Property => 'IMPL::DOM::Schema::Property',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 SwitchNode => 'IMPL::DOM::Schema::SwitchNode',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 Validator => 'IMPL::DOM::Schema::Validator',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 Builder => 'IMPL::DOM::Navigator::Builder',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 XMLReader => 'IMPL::DOM::XMLReader', # XMLReader references Schema
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 Loader => 'IMPL::Code::Loader',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23 StringMap => 'IMPL::Resources::StringLocaleMap'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 base => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26 'IMPL::DOM::Document' => sub {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 nodeName => 'schema'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29 ],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 props => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31 _typesMap => PROP_RW | PROP_DIRECT,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 baseDir => PROP_RW | PROP_DIRECT,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 schemaName => PROP_RW | PROP_DIRECT,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34 baseSchemas => PROP_RO | PROP_LIST | PROP_DIRECT,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35 stringMap => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 get => '_getStringMap',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37 direct => 1
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 ]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 my $validatorLoader = Loader->new(prefix => Validator, verifyNames => 1);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 #TODO rename and remove
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45 sub resolveType {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46 goto &ResolveType;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 my ($this,%args) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52 $this->{$baseDir} = ($args{baseDir} || '.');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55 # compat
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 sub ResolveType {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 my ($this,$typeName) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59 my $type = $this->{$_typesMap}{$typeName};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 return $type if $type;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62 foreach my $base ($this->baseSchemas) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63 last if $type = $base->ResolveType($typeName);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 die IMPL::KeyNotFoundException->new($typeName)
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67 unless $type;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68 return $this->{$_typesMap}{$typeName} = $type;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71 sub Create {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72 my ($this,$nodeName,$class,$refArgs) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74 die new IMPL::Exception('Invalid node class') unless $class->isa('IMPL::DOM::Node');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
76 if ($class->isa('IMPL::DOM::Schema::Validator')) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
77 $class = $validatorLoader->GetFullName($nodeName);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
78 unless (eval {$class->can('new')}) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
79 eval {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
80 $validatorLoader->Require($nodeName);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
81 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
82 my $e = $@;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
83 die new IMPL::Exception("Invalid validator",$class,$e) if $e;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
84 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
85 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
86
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
87 return $this->SUPER::Create($nodeName,$class,$refArgs);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
88 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
89
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
90 sub _getStringMap {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
91 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
92
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
93 return $this->{$stringMap}
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
94 if $this->{$stringMap};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
95
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
96 my $map = StringMap->new();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
97 if ($this->baseDir and $this->schemaName) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
98
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
99 $map->paths( File::Spec->catdir($this->baseDir,'locale') );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
100 $map->name( $this->schemaName );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
101 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
102
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
103 return $this->{$stringMap} = $map;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
104 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
105
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
106 sub Process {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
107 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
108
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
109 # process instructions
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
110 $this->Include($_) foreach map $_->nodeProperty('source'), $this->selectNodes('Include');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
111
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
112 # build types map
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
113 $this->{$_typesMap} = { map { $_->type, $_ } $this->selectNodes(sub { $_[0]->nodeName eq 'ComplexType' || $_[0]->nodeName eq 'SimpleType' } ) };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
114 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
115
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
116 sub Include {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
117 my ($this,$file) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
118
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
119 my $schema = $this->LoadSchema(File::Spec->catfile($this->baseDir, $file));
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
120
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
121 $this->baseSchemas->Push( $schema );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
122 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
123
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
124 sub LoadSchema {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
125 my ($this,$file) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
126
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
127 $file = File::Spec->rel2abs($file);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
128
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
129 my $class = ref $this || $this;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
130
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
131 my $reader = XMLReader->new(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
132 Navigator => Builder->new(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
133 $class,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
134 $class->MetaSchema
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
135 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
136 SkipWhitespace => 1
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
137 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
138
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
139 $reader->ParseFile($file);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
140
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
141 my $schema = $reader->Navigator->Document;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
142
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
143 my ($vol,$dir,$name) = File::Spec->splitpath($file);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
144
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
145 $name =~ s/\.xml$//;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
146
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
147 $schema->baseDir($dir);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
148 $schema->schemaName($name);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
149
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
150 my @errors = $class->MetaSchema->Validate($schema);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
151
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
152 die new IMPL::Exception("Schema is invalid",$file,map( $_->message, @errors ) ) if @errors;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
153
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
154 $schema->Process;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
155
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
156 return $schema;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
157 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
158
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
159 sub Validate {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
160 my ($this,$node) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
161
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
162 if ( my ($schemaNode) = $this->selectNodes(sub { $_->isa(Node) and $_[0]->name eq $node->nodeName })) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
163 $schemaNode->Validate($node);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
164 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
165 return new IMPL::DOM::Schema::ValidationError(node => $node, message=> "A specified document (%Node.nodeName%) doesn't match the schema");
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
166 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
167 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
168
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
169 my $schema;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
170
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
171 sub MetaSchema {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
172
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
173 return $schema if $schema;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
174
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
175 $schema = __PACKAGE__->new();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
176
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
177 $schema->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
178 ComplexNode->new(name => 'schema')->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
179 NodeSet->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
180 Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
181 Node->new(name => 'ComplexType', type => 'ComplexType', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
182 Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
183 Node->new(name => 'SimpleType', type => 'SimpleType', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
184 Node->new(name => 'Node', type => 'Node', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
185 SimpleNode->new(name => 'Include', minOccur => 0, maxOccur=>'unbounded')->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
186 Property->new(name => 'source')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
187 )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
188 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
189 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
190 ComplexType->new(type => 'NodeSet', nativeType => 'IMPL::DOM::Schema::NodeSet')->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
191 NodeSet->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
192 Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
193 Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
194 Node->new(name => 'Node', type=>'Node', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
195 SwitchNode->new(minOccur => 0, maxOccur => 1)->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
196 Node->new(name => 'AnyNode', type => 'AnyNode'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
197 Node->new(name => 'SwitchNode',type => 'SwitchNode')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
198 )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
199 )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
200 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
201 ComplexType->new(type => 'SwitchNode', nativeType => 'IMPL::DOM::Schema::SwitchNode')->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
202 NodeSet->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
203 Node->new(name => 'ComplexNode', type=>'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
204 Node->new(name => 'SimpleNode', type=>'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
205 Node->new(name => 'Node', type=>'Node', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
206 )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
207 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
208 ComplexType->new(type => 'NodeList', nativeType => 'IMPL::DOM::Schema::NodeList')->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
209 NodeSet->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
210 Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
211 Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
212 Node->new(name => 'SwitchNode',type => 'SwitchNode', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
213 Node->new(name => 'Node', type => 'Node', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
214 Node->new(name => 'AnyNode', type => 'AnyNode', minOccur => 0, maxOccur=>'unbounded'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
215 )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
216 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
217 ComplexType->new(type => 'ComplexType', nativeType => 'IMPL::DOM::Schema::ComplexType')->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
218 NodeList->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
219 SwitchNode->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
220 Node->new(name => 'NodeSet', type => 'NodeSet'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
221 Node->new(name => 'NodeList',type => 'NodeList'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
222 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
223 Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
224 AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
225 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
226 Property->new(name => 'type')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
227 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
228 ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
229 NodeList->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
230 SwitchNode->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
231 Node->new(name => 'NodeSet', type => 'NodeSet'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
232 Node->new(name => 'NodeList',type => 'NodeList'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
233 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
234 Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
235 AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
236 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
237 Property->new(name => 'name')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
238 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
239 ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
240 NodeList->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
241 Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
242 AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
243 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
244 Property->new(name => 'type')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
245 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
246 ComplexType->new(type => 'SimpleNode', nativeType => 'IMPL::DOM::Schema::SimpleNode')->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
247 NodeList->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
248 Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
249 AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
250 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
251 Property->new(name => 'name')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
252 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
253 ComplexType->new(type => 'Validator', nativeType => 'IMPL::DOM::Schema::Validator')->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
254 NodeList->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
255 AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
256 )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
257 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
258 ComplexType->new(type => 'Property', nativeType => 'IMPL::DOM::Schema::Property' )->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
259 NodeList->new()->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
260 AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
261 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
262 Property->new(name => 'name')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
263 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
264 SimpleType->new(type => 'Node', nativeType => 'IMPL::DOM::Schema::Node')->appendRange(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
265 Property->new(name => 'name'),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
266 Property->new(name => 'type')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
267 ),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
268 SimpleType->new(type => 'AnyNode', nativeType => 'IMPL::DOM::Schema::AnyNode')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
269 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
270
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
271 $schema->Process;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
272
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
273 return $schema;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
274 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
275
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
276 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
277
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
278 __END__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
279
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
280 =pod
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
281
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
282 =head1 NAME
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
283
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
284 C<IMPL::DOM::Schema> - Схема документа.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
285
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
286 =head1 DESCRIPTION
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
287
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
288 C<use parent qw(IMPL::DOM::Document)>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
289
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
290 DOM схема - это документ, состоящий из определенных узлов, описывающая структуру
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
291 других документов.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
292
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
293 =head1 METHODS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
294
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
295 =over
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
296
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
297 =item C<< $obj->Process() >>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
298
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
299 Обновляет таблицу типов из содержимого.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
300
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
301 =item C<< $obj->ResolveType($typeName) >>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
302
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
303 Возвращает схему типа c именем C<$typeName>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
304
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
305 =back
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
306
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
307 =head1 META SCHEMA
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
308
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
309 Схема для описания схемы, эта схема используется для постороения других схем, выглядит приблизительно так
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
310
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
311 =begin code xml
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
312
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
313 <schema>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
314 <ComplexNode name="schema">
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
315 <NodeSet>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
316 <Node minOcuur="0" maxOccur="unbounded" name="ComplexNode" type="ComplexNode"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
317 <Node minOcuur="0" maxOccur="unbounded" name="SimpleNode" type="SimpleNode"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
318 <Node minOcuur="0" maxOccur="unbounded" name="ComplexType" type="ComplexType"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
319 <Node minOcuur="0" maxOccur="unbounded" name="SimpleType" type="SimpleType"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
320 <SimpleNode minOcuur="0" maxOccur="unbounded" name="Node"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
321 <SimpleNode minOcuur="0" maxOccur="unbounded" name="Include"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
322 </NodeSet>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
323 </ComplexNode>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
324
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
325 <ComplexType type="NodeContainer">
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
326 <NodeSet>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
327 <Node minOcuur="0" maxOccur="unbounded" name="ComplexNode" type="ComplexNode"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
328 <Node minOcuur="0" maxOccur="unbounded" name="SimpleNode" type="SimpleNode"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
329 <SimpleNode minOcuur="0" maxOccur="unbounded" name="Node"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
330 </NodeSet>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
331 </ComplexType>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
332
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
333 <ComplexType type="ComplexType">
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
334 <NodeList>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
335 <Node name="NodeSet" type="NodeContainer" minOcuur=0/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
336 <Node name="NodeList" type="NodeContainer" minOccur=0/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
337 <AnyNode minOccur="0" maxOccur="unbounded" type="Validator"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
338 </NodeList>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
339 </ComplexType>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
340
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
341 <ComplexType type="ComplexNode">
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
342 <NodeList>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
343 <Node name="NodeSet" type="NodeContainer" minOcuur=0/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
344 <Node name="NodeList" type="NodeContainer" minOccur=0/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
345 <AnyNode minOccur="0" maxOccur="unbounded" type="Validator"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
346 </NodeList>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
347 </ComplexType>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
348
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
349 <ComplexType type="SimpleNode">
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
350 <NodeSet>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
351 <AnyNode minOccur=0 maxOccur="unbounded" type="Validator"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
352 </NodeSet>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
353 </ComplexType>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
354
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
355 <ComplexType type="SimpleType">
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
356 <NodeSet>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
357 <AnyNode minOccur=0 maxOccur="unbounded" type="Validator"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
358 </NodeSet>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
359 </ComplexType>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
360
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
361 <ComplexType type="Validator">
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
362 <NodeSet>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
363 <AnyNode minOccur=0 maxOccur="unbounded"/>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
364 </NodeSet>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
365 </ComplexType>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
366
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
367 </schema>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
368
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
369 =end code xml
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
370
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
371 =cut