diff Lib/IMPL/DOM/Schema.pm @ 230:6d8092d8ce1b

*reworked IMPL::Security *reworked IMPL::Web::Security *refactoring
author sergey
date Mon, 08 Oct 2012 03:37:37 +0400
parents 4d0e1962161c
children 5c82eec23bb6
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Schema.pm	Sat Sep 29 02:34:47 2012 +0400
+++ b/Lib/IMPL/DOM/Schema.pm	Mon Oct 08 03:37:37 2012 +0400
@@ -2,20 +2,23 @@
 use strict;
 use warnings;
 
-require IMPL::DOM::Schema::ComplexNode;
-require IMPL::DOM::Schema::ComplexType;
-require IMPL::DOM::Schema::SimpleNode;
-require IMPL::DOM::Schema::SimpleType;
-require IMPL::DOM::Schema::Node;
-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;
-require IMPL::DOM::Schema::Validator;
-require IMPL::DOM::Navigator::Builder;
-require IMPL::DOM::XMLReader;
-require IMPL::DOM::Schema::InflateFactory;
+use IMPL::require {
+    ComplexNode => 'IMPL::DOM::Schema::ComplexNode',
+    ComplexType => 'IMPL::DOM::Schema::ComplexType',
+    SimpleNode => 'IMPL::DOM::Schema::SimpleNode',
+    SimpleType => 'IMPL::DOM::Schema::SimpleType',
+    Node => 'IMPL::DOM::Schema::Node',
+    AnyNode => 'IMPL::DOM::Schema::AnyNode',
+    NodeList => 'IMPL::DOM::Schema::NodeList',
+    NodeSet => 'IMPL::DOM::Schema::NodeSet',
+    Property => 'IMPL::DOM::Schema::Property',
+    SwitchNode => 'IMPL::DOM::Schema::SwitchNode',
+    Validator => 'IMPL::DOM::Schema::Validator',
+    Builder => 'IMPL::DOM::Navigator::Builder',
+    XMLReader => 'IMPL::DOM::XMLReader',
+    InflateFactory => 'IMPL::DOM::Schema::InflateFactory',
+    Loader => 'Code::Loader'
+};
 
 use parent qw(IMPL::DOM::Document);
 use IMPL::Class::Property;
@@ -32,6 +35,8 @@
     public _direct property BaseSchemas => prop_get | owner_set;
 }
 
+my $validatorLoader = Loader->new(prefix => Validator, verifyNames => 1);
+
 sub resolveType {
     $_[0]->{$_TypesMap}->{$_[1]};
 }
@@ -48,10 +53,9 @@
     die new IMPL::Exception('Invalid node class') unless $class->isa('IMPL::DOM::Node');
     
     if ($class->isa('IMPL::DOM::Schema::Validator')) {
-        $class = "IMPL::DOM::Schema::Validator::$nodeName";
+        $class = $validatorLoader->GetFullName($nodeName);
         unless (eval {$class->can('new')}) {
-            eval "require $class; 1;";
-            my $e = $@;
+            $validatorLoader->Require($nodeName);
             die new IMPL::Exception("Invalid validator",$class,$e) if $e;
         }
     }
@@ -84,8 +88,8 @@
     
     my $class = ref $this || $this;
     
-    my $reader = new IMPL::DOM::XMLReader(
-        Navigator => new IMPL::DOM::Navigator::Builder(
+    my $reader = Reader->(
+        Navigator => Builder->new(
             $class,
             $class->MetaSchema
         ),
@@ -112,7 +116,7 @@
 sub Validate {
     my ($this,$node) = @_;
     
-    if ( my ($schemaNode) = $this->selectNodes(sub { $_->isa('IMPL::DOM::Schema::Node') and $_[0]->name eq $node->nodeName })) {
+    if ( my ($schemaNode) = $this->selectNodes(sub { $_->isa(Node) and $_[0]->name eq $node->nodeName })) {
         $schemaNode->Validate($node);
     } else {
         return new IMPL::DOM::Schema::ValidationError(Node => $node, Message=> "A specified document (%Node.nodeName%) doesn't match the schema");
@@ -125,103 +129,103 @@
     
     return $schema if $schema;
     
-    $schema = new IMPL::DOM::Schema;
+    $schema = Schema->new();
     
     $schema->appendRange(
-        IMPL::DOM::Schema::ComplexNode->new(name => 'schema')->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 => 'ComplexType', type => 'ComplexType', minOccur => 0, maxOccur=>'unbounded'),
-                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::Node->new(name => 'Node', type => 'Node', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::SimpleNode->new(name => 'Include', minOccur => 0, maxOccur=>'unbounded')->appendRange(
-                    IMPL::DOM::Schema::Property->new(name => 'source')
+        ComplexNode->new(name => 'schema')->appendRange(
+            NodeSet->new()->appendRange(
+                Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'ComplexType', type => 'ComplexType', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'SimpleType', type => 'SimpleType', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'Node', type => 'Node', minOccur => 0, maxOccur=>'unbounded'),
+                SimpleNode->new(name => 'Include', minOccur => 0, maxOccur=>'unbounded')->appendRange(
+                    Property->new(name => 'source')
                 )
             ),
         ),
-        IMPL::DOM::Schema::ComplexType->new(type => 'NodeSet', nativeType => 'IMPL::DOM::Schema::NodeSet')->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 => 'Node', type=>'Node', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::SwitchNode->new(minOccur => 0, maxOccur => 1)->appendRange(
-                    IMPL::DOM::Schema::Node->new(name => 'AnyNode', type => 'AnyNode'),
-                    IMPL::DOM::Schema::Node->new(name => 'SwitchNode',type => 'SwitchNode')
+        ComplexType->new(type => 'NodeSet', nativeType => 'IMPL::DOM::Schema::NodeSet')->appendRange(
+            NodeSet->new()->appendRange(
+                Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'Node', type=>'Node', minOccur => 0, maxOccur=>'unbounded'),
+                SwitchNode->new(minOccur => 0, maxOccur => 1)->appendRange(
+                    Node->new(name => 'AnyNode', type => 'AnyNode'),
+                    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::Node->new(name => 'Node', type=>'Node', minOccur => 0, maxOccur=>'unbounded'),
+        ComplexType->new(type => 'SwitchNode', nativeType => 'IMPL::DOM::Schema::SwitchNode')->appendRange(
+            NodeSet->new()->appendRange(
+                Node->new(name => 'ComplexNode', type=>'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'SimpleNode', type=>'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'Node', type=>'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::Node->new(name => 'Node', type => 'Node', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::Node->new(name => 'AnyNode', type => 'AnyNode', minOccur => 0, maxOccur=>'unbounded'),
+        ComplexType->new(type => 'NodeList', nativeType => 'IMPL::DOM::Schema::NodeList')->appendRange(
+            NodeSet->new()->appendRange(
+                Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'SwitchNode',type => 'SwitchNode', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'Node', type => 'Node', minOccur => 0, maxOccur=>'unbounded'),
+                Node->new(name => 'AnyNode', type => '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::SwitchNode->new()->appendRange(
-                    IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'),
-                    IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'),
+        ComplexType->new(type => 'ComplexType', nativeType => 'IMPL::DOM::Schema::ComplexType')->appendRange(
+            NodeList->new()->appendRange(
+                SwitchNode->new()->appendRange(
+                    Node->new(name => 'NodeSet', type => 'NodeSet'),
+                    Node->new(name => 'NodeList',type => 'NodeList'),
                 ),
-                IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
-                IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
+                Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
+                AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
             ),
-            new IMPL::DOM::Schema::Property(name => 'type')
+            Property->new(name => 'type')
         ),
-        IMPL::DOM::Schema::ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange(
-            IMPL::DOM::Schema::NodeList->new()->appendRange(
-                IMPL::DOM::Schema::SwitchNode->new()->appendRange(
-                    IMPL::DOM::Schema::Node->new(name => 'NodeSet', type => 'NodeSet'),
-                    IMPL::DOM::Schema::Node->new(name => 'NodeList',type => 'NodeList'),
+        ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange(
+           NodeList->new()->appendRange(
+                SwitchNode->new()->appendRange(
+                    Node->new(name => 'NodeSet', type => 'NodeSet'),
+                    Node->new(name => 'NodeList',type => 'NodeList'),
                 ),
-                IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
-                IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
+                Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
+                AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
             ),
-            new IMPL::DOM::Schema::Property(name => 'name')
+            Property->new(name => 'name')
         ),
-        IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange(
-            IMPL::DOM::Schema::NodeList->new()->appendRange(
-                IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
-                IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
+        ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange(
+            NodeList->new()->appendRange(
+                Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
+                AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
             ),
-            new IMPL::DOM::Schema::Property(name => 'type'),
-            new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
+            Property->new(name => 'type'),
+            Property->(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
         ),
-        IMPL::DOM::Schema::ComplexType->new(type => 'SimpleNode', nativeType => 'IMPL::DOM::Schema::SimpleNode')->appendRange(
-            IMPL::DOM::Schema::NodeList->new()->appendRange(
-                IMPL::DOM::Schema::Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
-                IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
+        ComplexType->new(type => 'SimpleNode', nativeType => 'IMPL::DOM::Schema::SimpleNode')->appendRange(
+            NodeList->new()->appendRange(
+                Node->new(name => 'Property', type=>'Property', maxOccur=>'unbounded', minOccur=>0),
+                AnyNode->new(maxOccur => 'unbounded', minOccur => 0, type=>'Validator')
             ),
-            new IMPL::DOM::Schema::Property(name => 'name'),
-            new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
+            Property->new(name => 'name'),
+            Property->new(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
         ),
-        IMPL::DOM::Schema::ComplexType->new(type => 'Validator', nativeType => 'IMPL::DOM::Schema::Validator')->appendRange(
-            IMPL::DOM::Schema::NodeList->new()->appendRange(
-                IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
+        ComplexType->new(type => 'Validator', nativeType => 'IMPL::DOM::Schema::Validator')->appendRange(
+            NodeList->new()->appendRange(
+                AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
             )
         ),
-        IMPL::DOM::Schema::ComplexType->new(type => 'Property', nativeType => 'IMPL::DOM::Schema::Property' )->appendRange(
-            IMPL::DOM::Schema::NodeList->new()->appendRange(
-                IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
+        ComplexType->new(type => 'Property', nativeType => 'IMPL::DOM::Schema::Property' )->appendRange(
+            NodeList->new()->appendRange(
+                AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
             ),
-            IMPL::DOM::Schema::Property->new(name => 'name'),
-            new IMPL::DOM::Schema::Property(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
+            Property->new(name => 'name'),
+            Property->new(name => 'inflator', optional => 1, inflator => 'IMPL::DOM::Schema::InflateFactory')
         ),
-        IMPL::DOM::Schema::SimpleType->new(type => 'Node', nativeType => 'IMPL::DOM::Schema::Node')->appendRange(
-            IMPL::DOM::Schema::Property->new(name => 'name'),
-            IMPL::DOM::Schema::Property->new(name => 'type')
+        SimpleType->new(type => 'Node', nativeType => 'IMPL::DOM::Schema::Node')->appendRange(
+            Property->new(name => 'name'),
+            Property->new(name => 'type')
         ),
-        IMPL::DOM::Schema::SimpleType->new(type => 'AnyNode', nativeType => 'IMPL::DOM::Schema::AnyNode')
+        SimpleType->new(type => 'AnyNode', nativeType => 'IMPL::DOM::Schema::AnyNode')
     );
     
     $schema->Process;