comparison Lib/IMPL/DOM/Schema.pm @ 24:7f00786f8210

Первая рабочая реазизация схемы и навигаторов
author Sergey
date Mon, 05 Oct 2009 00:48:49 +0400
parents fafe56cfcd69
children a8086f85a571
comparison
equal deleted inserted replaced
23:716b287d4795 24:7f00786f8210
8 require IMPL::DOM::Schema::SimpleType; 8 require IMPL::DOM::Schema::SimpleType;
9 require IMPL::DOM::Schema::Node; 9 require IMPL::DOM::Schema::Node;
10 require IMPL::DOM::Schema::AnyNode; 10 require IMPL::DOM::Schema::AnyNode;
11 require IMPL::DOM::Schema::NodeList; 11 require IMPL::DOM::Schema::NodeList;
12 require IMPL::DOM::Schema::NodeSet; 12 require IMPL::DOM::Schema::NodeSet;
13 require IMPL::DOM::Schema::Property;
14 require IMPL::DOM::Schema::SwitchNode;
13 15
14 use base qw(IMPL::DOM::Document); 16 use base qw(IMPL::DOM::Document);
15 use IMPL::Class::Property; 17 use IMPL::Class::Property;
16 use IMPL::Class::Property::Direct; 18 use IMPL::Class::Property::Direct;
17 19
18 __PACKAGE__->PassThroughArgs; 20 our %CTOR = (
21 'IMPL::DOM::Document' => sub { nodeName => 'schema' }
22 );
19 23
20 BEGIN { 24 BEGIN {
21 private _direct property _TypesMap => prop_all; 25 private _direct property _TypesMap => prop_all;
22 } 26 }
23 27
26 } 30 }
27 31
28 sub Process { 32 sub Process {
29 my ($this) = @_; 33 my ($this) = @_;
30 34
31 $this->{$_TypesMap} = { map { $_->type, $_ } grep {$_->isa('IMPL::DOM::Schema::Type')} @{$this->childNodes} }; 35 $this->{$_TypesMap} = { map { $_->type, $_ } $this->selectNodes(sub { $_[0]->nodeName eq 'ComplexType' || $_[0]->nodeName eq 'SimpleType' } ) };
32 } 36 }
33 37
34 sub Validate { 38 sub Validate {
35 my ($this,$node) = @_; 39 my ($this,$node) = @_;
36 40
37 if ( my ($schemaNode) = $this->selectNodes(sub { $_[0]->name eq $node->nodeName })) { 41 if ( my ($schemaNode) = $this->selectNodes(sub { $_[0]->name eq $node->nodeName })) {
38 $schemaNode->Validate($node); 42 $schemaNode->Validate($node);
39 } else { 43 } else {
40 return IMPL::DOM::Schema::VaidationError(Message=> "A specified document doesn't match the schema"); 44 return IMPL::DOM::Schema::ValidationError(Message=> "A specified document doesn't match the schema");
41 } 45 }
42 } 46 }
43 47
44 my $schema; 48 my $schema;
45 49
46 sub MetaSchema { 50 sub MetaSchema {
47 51
48 return $schema if $schema; 52 return $schema if $schema;
49 53
50 $schema = new IMPL::DOM::Schema(nodeName => 'schema'); 54 $schema = new IMPL::DOM::Schema;
51 55
52 $schema->appendRange( 56 $schema->appendRange(
53 IMPL::DOM::Schema::ComplexNode->new(name => 'schema')->appendRange( 57 IMPL::DOM::Schema::ComplexNode->new(name => 'schema')->appendRange(
54 IMPL::DOM::Schema::NodeSet->new()->appendRange( 58 IMPL::DOM::Schema::NodeSet->new()->appendRange(
55 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'), 59 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
56 IMPL::DOM::Schema::Node->new(name => 'ComplexType', type => 'ComplexType', minOccur => 0, maxOccur=>'unbounded'), 60 IMPL::DOM::Schema::Node->new(name => 'ComplexType', type => 'ComplexType', minOccur => 0, maxOccur=>'unbounded'),
57 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'), 61 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
58 IMPL::DOM::Schema::Node->new(name => 'SimpleType', type => 'SimpleType', minOccur => 0, maxOccur=>'unbounded'), 62 IMPL::DOM::Schema::Node->new(name => 'SimpleType', type => 'SimpleType', minOccur => 0, maxOccur=>'unbounded'),
59 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'), 63 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
60 IMPL::DOM::Schema::SimpleNode->new(name => 'Include', minOccur => 0, maxOccur=>'unbounded') 64 IMPL::DOM::Schema::SimpleNode->new(name => 'Include', minOccur => 0, maxOccur=>'unbounded')->appendRange(
65 IMPL::DOM::Schema::Property->new(name => 'source')
66 )
61 ), 67 ),
62 ), 68 ),
63 IMPL::DOM::Schema::ComplexType->new(type => 'NodeSet', nativeType => 'IMPL::DOM::Schema::NodeSet')->appendRange( 69 IMPL::DOM::Schema::ComplexType->new(type => 'NodeSet', nativeType => 'IMPL::DOM::Schema::NodeSet')->appendRange(
64 IMPL::DOM::Schema::NodeSet->new()->appendRange( 70 IMPL::DOM::Schema::NodeSet->new()->appendRange(
65 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'), 71 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
66 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'), 72 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
67 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'), 73 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
74 IMPL::DOM::Schema::SwitchNode->new(minOccur => 0, maxOccur => 1)->appendRange(
75 IMPL::DOM::Schema::SimpleNode->new(name => 'AnyNode'),
76 IMPL::DOM::Schema::Node->new(name => 'SwitchNode',type => 'SwitchNode')
77 )
78 )
79 ),
80 IMPL::DOM::Schema::ComplexType->new(type => 'SwitchNode', nativeType => 'IMPL::DOM::Schema::SwitchNode')->appendRange(
81 IMPL::DOM::Schema::NodeSet->new()->appendRange(
82 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type=>'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
83 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type=>'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
84 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
68 ) 85 )
69 ), 86 ),
70 IMPL::DOM::Schema::ComplexType->new(type => 'NodeList', nativeType => 'IMPL::DOM::Schema::NodeList')->appendRange( 87 IMPL::DOM::Schema::ComplexType->new(type => 'NodeList', nativeType => 'IMPL::DOM::Schema::NodeList')->appendRange(
71 IMPL::DOM::Schema::NodeSet->new()->appendRange( 88 IMPL::DOM::Schema::NodeSet->new()->appendRange(
72 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'), 89 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
73 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'), 90 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
74 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'), 91 IMPL::DOM::Schema::Node->new(name => 'SwitchNode',type => 'SwitchNode', minOccur => 0, maxOccur=>'unbounded'),
92 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
93 IMPL::DOM::Schema::SimpleNode->new(name => 'AnyNode', minOccur => 0, maxOccur=>'unbounded'),
75 ) 94 )
76 ), 95 ),
77 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexType', nativeType => 'IMPL::DOM::Schema::ComplexType')->appendRange( 96 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexType', nativeType => 'IMPL::DOM::Schema::ComplexType')->appendRange(
78 IMPL::DOM::Schema::NodeList->new()->appendRange( 97 IMPL::DOM::Schema::NodeList->new()->appendRange(
79 IMPL::DOM::Schema::Node->new(name => 'NodeSet', minOccur => 0, type => 'NodeSet'), 98 IMPL::DOM::Schema::SwitchNode->new()->appendRange(
80 IMPL::DOM::Schema::Node->new(name => 'NodeList', minOccur => 0, type => 'NodeSet'), 99 IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'),
81 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur => 'unbounded') 100 IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'),
101 ),
102 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
82 ), 103 ),
83 new IMPL::DOM::Schema::Property(name => 'type') 104 new IMPL::DOM::Schema::Property(name => 'type')
84 ), 105 ),
85 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange( 106 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange(
86 IMPL::DOM::Schema::NodeList->new()->appendRange( 107 IMPL::DOM::Schema::NodeList->new()->appendRange(
87 IMPL::DOM::Schema::Node->new(name => 'NodeSet', minOccur => 0, type => 'NodeSet'), 108 IMPL::DOM::Schema::SwitchNode->new()->appendRange(
88 IMPL::DOM::Schema::Node->new(name => 'NodeList', minOccur => 0, type => 'NodeSet'), 109 IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'),
89 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur => 'unbounded') 110 IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'),
111 ),
112 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
90 ), 113 ),
91 new IMPL::DOM::Schema::Property(name => 'name') 114 new IMPL::DOM::Schema::Property(name => 'name')
92 ), 115 ),
93 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange( 116 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange(
94 IMPL::DOM::Schema::NodeSet->new()->appendRange( 117 IMPL::DOM::Schema::NodeSet->new()->appendRange(