changeset 35:f25d021780b3

DOM::Navigator::Builder working version
author Sergey
date Tue, 17 Nov 2009 17:46:24 +0300
parents a8086f85a571
children 1828103371d0
files Lib/IMPL/DOM/Navigator/Builder.pm Lib/IMPL/DOM/Navigator/SchemaNavigator.pm _test/Test/DOM/Builder.pm impl.kpf
diffstat 4 files changed, 51 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Navigator/Builder.pm	Mon Nov 16 18:39:25 2009 +0300
+++ b/Lib/IMPL/DOM/Navigator/Builder.pm	Tue Nov 17 17:46:24 2009 +0300
@@ -19,7 +19,7 @@
     my ($this,$docClass,$schema) = @_;
     
     $this->{$_docClass} = $docClass;
-    $this->{$_schemaNavi} = IMPL::DOM::Navigator::SchemaNavigator->new($schema);
+    $this->{$_schemaNavi} = $schema ? IMPL::DOM::Navigator::SchemaNavigator->new($schema) : undef;
 }
 
 sub NavigateCreate {
@@ -32,7 +32,7 @@
         if (! $this->{$Document}) {
             $node = $this->{$Document} = $this->{$_docClass}->new(nodeName => $nodeName,%props);
         } else {
-            die new IMPL::InvalidOperationException('Can\t create a second top level element');
+            die new IMPL::InvalidOperationException('Can\t create a second top level element') unless $this->{$_nodeCurrent};
             $node = $this->{$Document}->Create($nodeName,$class,\%props);
             push @{$this->{$_nodesPath}}, $this->{$_nodeCurrent};
             $this->{$_nodeCurrent}->appendChild($node);
--- a/Lib/IMPL/DOM/Navigator/SchemaNavigator.pm	Mon Nov 16 18:39:25 2009 +0300
+++ b/Lib/IMPL/DOM/Navigator/SchemaNavigator.pm	Tue Nov 17 17:46:24 2009 +0300
@@ -37,7 +37,7 @@
     die new IMPL::InvalidArgumentException('name is required') unless defined $name;
     
     # perform a safe navigation
-    return dosafe $this sub {
+    #return dosafe $this sub {
         my $steps = 1;
         # navigate to node
         if (
@@ -84,7 +84,7 @@
         } else {
             die; # abort navigation
         }
-    }
+    #}
 }
 
 sub SchemaBack {
--- a/_test/Test/DOM/Builder.pm	Mon Nov 16 18:39:25 2009 +0300
+++ b/_test/Test/DOM/Builder.pm	Tue Nov 17 17:46:24 2009 +0300
@@ -25,7 +25,7 @@
             IMPL::DOM::Schema::NodeSet->new()->appendRange(
                 new IMPL::DOM::Schema::SimpleNode( name => 'firstName' ),
                 new IMPL::DOM::Schema::SimpleNode( name => 'lastName' ),
-                new IMPL::DOM::Schema::ComplexNode( name => 'address' )->appendRange(
+                new IMPL::DOM::Schema::ComplexNode( name => 'address', maxOccur => 'unbounded' )->appendRange(
                     IMPL::DOM::Schema::NodeSet->new()->appendRange(
                         new IMPL::DOM::Schema::SimpleNode( name => 'street' ),
                         new IMPL::DOM::Schema::SimpleNode( name => 'line', minOccur => 0 )
@@ -55,15 +55,32 @@
         $this->schemaDoc
     );
     
+    use Time::HiRes qw(gettimeofday tv_interval);
+    
+    my $t = [gettimeofday];
+    
     $builder->NavigateCreate('personInfo', version => '1');
         $builder->NavigateCreate('firstName')->nodeValue('Nemo');
         $builder->Back();
-        $builder->NavigateCreate('address', local => 1);
-            $builder->NavigateCreate('street')->nodeValue('Hellroad');
+        $builder->NavigateCreate('lastName')->nodeValue('Nobel');
+        $builder->Back();
+        $builder->NavigateCreate('lastName')->nodeValue('Gardum');
+        $builder->Back();
+        for(1..100) {
+            $builder->NavigateCreate('address', local => 1);
+                $builder->NavigateCreate('street')->nodeValue('Hellroad');
+                $builder->Back();
+                $builder->NavigateCreate('line')->nodeValue($_);
+                $builder->Back();
             $builder->Back();
-        $builder->Back();
+        }
     $builder->Back();
     
+    print "Build: ",tv_interval($t,[gettimeofday]),"\n";
+    $t = [gettimeofday];
+    print $_->Message,"\n" foreach $this->schemaDoc->Validate($builder->Document);
+    print "Validate: ",tv_interval($t,[gettimeofday]),"\n";
+    
     return 1;
 };
 
--- a/impl.kpf	Mon Nov 16 18:39:25 2009 +0300
+++ b/impl.kpf	Tue Nov 17 17:46:24 2009 +0300
@@ -456,6 +456,32 @@
 </preference-set>
   <string id="lastInvocation">default</string>
 </preference-set>
+<preference-set idref="66c7d414-175f-45b6-92fe-dbda51c64843/_test/Test/DOM/Builder.pm">
+<preference-set id="Invocations">
+<preference-set id="default">
+  <string id="cookieparams"></string>
+  <string id="cwd"></string>
+  <long id="debugger.io-port">9011</long>
+  <string id="documentRoot"></string>
+  <string id="executable-params"></string>
+  <string relative="path" id="filename">_test/Test/DOM/Builder.pm</string>
+  <string id="getparams"></string>
+  <string id="language">Perl</string>
+  <string id="mpostparams"></string>
+  <string id="params"></string>
+  <string id="postparams"></string>
+  <string id="posttype">application/x-www-form-urlencoded</string>
+  <string id="request-method">GET</string>
+  <boolean id="show-dialog">1</boolean>
+  <boolean id="sim-cgi">0</boolean>
+  <boolean id="use-console">0</boolean>
+  <string id="userCGIEnvironment"></string>
+  <string id="userEnvironment"></string>
+  <string id="warnings">enabled</string>
+</preference-set>
+</preference-set>
+  <string id="lastInvocation">default</string>
+</preference-set>
 <preference-set idref="66c7d414-175f-45b6-92fe-dbda51c64843/_test/Test/DOM/Node.pm">
 <preference-set id="Invocations">
 <preference-set id="default">