diff Lib/IMPL/DOM/Navigator/SchemaNavigator.pm @ 104:196bf443b5e1

DOM::Schema RC0 inflators support, validation and some other things, Minor and major fixes almost for everything. A 'Source' property of the ValidationErrors generated from a NodeSet or a NodeList is subject to change in the future.
author wizard
date Tue, 11 May 2010 02:42:59 +0400
parents c289ed9662ca
children 76515373dac0
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Navigator/SchemaNavigator.pm	Fri May 07 18:17:40 2010 +0400
+++ b/Lib/IMPL/DOM/Navigator/SchemaNavigator.pm	Tue May 11 02:42:59 2010 +0400
@@ -38,7 +38,15 @@
     
     # perform a safe navigation
     #return dosafe $this sub {
-        my $steps = 1;
+        my $steps = 0;
+        # if we are currently in a ComplexNode, first go to it's content
+        if ($this->Current->isa('IMPL::DOM::Schema::ComplexNode')) {
+            # navigate to it's content
+            # ComplexNode
+            $this->internalNavigateNodeSet($this->Current->content);
+            $steps ++;
+        }
+        
         # navigate to node
         if (
             my $node = $this->Navigate( sub {
@@ -51,10 +59,13 @@
                 )
             })
         ) {
+        	$steps ++;
             if ($node->nodeName eq 'AnyNode') {
                 # if we navigate to the anynode
                 # assume it to be ComplexType by default
                 $node = $node->type ? $this->{$Schema}->resolveType($node->type) : $schemaAnyNode;
+                $this->internalNavigateNodeSet($node);
+                $steps ++;
             } elsif ($node->nodeName eq 'SwitchNode') {
                 # if we are in the switchnode
                 # navigate to the target node
@@ -70,13 +81,6 @@
                 $steps++;
             } 
             
-            # if target node is a complex node
-            if ($node->isa('IMPL::DOM::Schema::ComplexNode')) {
-                # navigate to it's content
-                $this->internalNavigateNodeSet($node->content);
-                $steps ++;
-            }
-            
             push @{$this->{$_historySteps}},$steps;
             
             # return found node schema
@@ -93,6 +97,19 @@
     $this->Back(pop @{$this->{$_historySteps}}) if $this->{$_historySteps};
 }
 
+sub SourceSchemaNode {
+	my ($this) = @_;
+	
+	if ($this->Current->isa('IMPL::DOM::Schema::SimpleType') or
+		$this->Current->isa('IMPL::DOM::Schema::ComplexType')
+	) {
+		# we a redirected
+		return $this->GetNodeFromHistory(-1);
+	} else {
+		return $this->Current;
+	}
+}
+
 1;
 __END__
 
@@ -107,16 +124,21 @@
 
 =over
 
-=item C<< $navi->NavigateName($name) >>
+=item C<NavigateName($name)>
 
 Переходит на схему узла с указанным именем. Тоесть использует свойство C<name>.
 
-=item C<< $navi->SchemaBack >>
+=item C<SchemaBack>
 
 Возвращается на позицию до последней операции C<NavigateName>. Данный метод нужен
 посокольку операция навигации по элементам описываемым схемой может приводить к
 нескольким операциям навигации по самой схеме.
 
+=item C<SourceSchemaNode>
+
+Получает схему узла из которого было выполнено перенаправление, например, C<IMPL::DOM::Schema::Node>.
+В остальных случаях совпадает со свойством C<Current>.
+
 =back
 
 =cut