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

Первая рабочая реазизация схемы и навигаторов
author Sergey
date Mon, 05 Oct 2009 00:48:49 +0400
parents fafe56cfcd69
children a8086f85a571
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Schema.pm	Wed Sep 30 17:43:52 2009 +0400
+++ b/Lib/IMPL/DOM/Schema.pm	Mon Oct 05 00:48:49 2009 +0400
@@ -10,12 +10,16 @@
 require IMPL::DOM::Schema::AnyNode;
 require IMPL::DOM::Schema::NodeList;
 require IMPL::DOM::Schema::NodeSet;
+require IMPL::DOM::Schema::Property;
+require IMPL::DOM::Schema::SwitchNode;
 
 use base qw(IMPL::DOM::Document);
 use IMPL::Class::Property;
 use IMPL::Class::Property::Direct;
 
-__PACKAGE__->PassThroughArgs;
+our %CTOR = (
+    'IMPL::DOM::Document' => sub { nodeName => 'schema' }
+);
 
 BEGIN {
     private _direct property _TypesMap => prop_all;
@@ -28,7 +32,7 @@
 sub Process {
     my ($this) = @_;
     
-    $this->{$_TypesMap} = { map { $_->type, $_ } grep {$_->isa('IMPL::DOM::Schema::Type')} @{$this->childNodes} };
+    $this->{$_TypesMap} = { map { $_->type, $_ } $this->selectNodes(sub { $_[0]->nodeName eq 'ComplexType' || $_[0]->nodeName eq 'SimpleType' } ) };
 }
 
 sub Validate {
@@ -37,7 +41,7 @@
     if ( my ($schemaNode) = $this->selectNodes(sub { $_[0]->name eq $node->nodeName })) {
         $schemaNode->Validate($node);
     } else {
-        return IMPL::DOM::Schema::VaidationError(Message=> "A specified document doesn't match the schema");
+        return IMPL::DOM::Schema::ValidationError(Message=> "A specified document doesn't match the schema");
     }
 }
 
@@ -47,7 +51,7 @@
     
     return $schema if $schema;
     
-    $schema = new IMPL::DOM::Schema(nodeName => 'schema');
+    $schema = new IMPL::DOM::Schema;
     
     $schema->appendRange(
         IMPL::DOM::Schema::ComplexNode->new(name => 'schema')->appendRange(
@@ -57,7 +61,9 @@
                 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
                 IMPL::DOM::Schema::Node->new(name => 'SimpleType', type => 'SimpleType', minOccur => 0, maxOccur=>'unbounded'),
                 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::SimpleNode->new(name => 'Include', minOccur => 0, maxOccur=>'unbounded')
+                IMPL::DOM::Schema::SimpleNode->new(name => 'Include', minOccur => 0, maxOccur=>'unbounded')->appendRange(
+                    IMPL::DOM::Schema::Property->new(name => 'source')
+                )
             ),
         ),
         IMPL::DOM::Schema::ComplexType->new(type => 'NodeSet', nativeType => 'IMPL::DOM::Schema::NodeSet')->appendRange(
@@ -65,28 +71,45 @@
                 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
                 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
                 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::SwitchNode->new(minOccur => 0, maxOccur => 1)->appendRange(
+                    IMPL::DOM::Schema::SimpleNode->new(name => 'AnyNode'),
+                    IMPL::DOM::Schema::Node->new(name => 'SwitchNode',type => 'SwitchNode')
+                )
+            )
+        ),
+        IMPL::DOM::Schema::ComplexType->new(type => 'SwitchNode', nativeType => 'IMPL::DOM::Schema::SwitchNode')->appendRange(
+            IMPL::DOM::Schema::NodeSet->new()->appendRange(
+                IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type=>'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type=>'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
             )
         ),
         IMPL::DOM::Schema::ComplexType->new(type => 'NodeList', nativeType => 'IMPL::DOM::Schema::NodeList')->appendRange(
             IMPL::DOM::Schema::NodeSet->new()->appendRange(
                 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
                 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::Node->new(name => 'SwitchNode',type => 'SwitchNode', minOccur => 0, maxOccur=>'unbounded'),
                 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::SimpleNode->new(name => 'AnyNode', minOccur => 0, maxOccur=>'unbounded'),
             )
         ),
         IMPL::DOM::Schema::ComplexType->new(type => 'ComplexType', nativeType => 'IMPL::DOM::Schema::ComplexType')->appendRange(
             IMPL::DOM::Schema::NodeList->new()->appendRange(
-                IMPL::DOM::Schema::Node->new(name => 'NodeSet', minOccur => 0, type => 'NodeSet'),
-                IMPL::DOM::Schema::Node->new(name => 'NodeList', minOccur => 0, type => 'NodeSet'),
-                IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur => 'unbounded')
+                IMPL::DOM::Schema::SwitchNode->new()->appendRange(
+                    IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'),
+                    IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'),
+                ),
+                IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
             ),
             new IMPL::DOM::Schema::Property(name => 'type')
         ),
         IMPL::DOM::Schema::ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange(
             IMPL::DOM::Schema::NodeList->new()->appendRange(
-                IMPL::DOM::Schema::Node->new(name => 'NodeSet', minOccur => 0, type => 'NodeSet'),
-                IMPL::DOM::Schema::Node->new(name => 'NodeList', minOccur => 0, type => 'NodeSet'),
-                IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur => 'unbounded')
+                IMPL::DOM::Schema::SwitchNode->new()->appendRange(
+                    IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'),
+                    IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'),
+                ),
+                IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
             ),
             new IMPL::DOM::Schema::Property(name => 'name')
         ),