changeset 384:4edd36025051

DOM schema refactoring
author cin
date Mon, 10 Feb 2014 17:41:34 +0400
parents 2f16f13b000c
children 4bdf155e5bfe
files Lib/IMPL/DOM/Navigator/Builder.pm Lib/IMPL/DOM/Node.pm Lib/IMPL/DOM/Schema/Node.pm Lib/IMPL/DOM/XMLReader.pm
diffstat 4 files changed, 14 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Navigator/Builder.pm	Thu Jan 23 17:26:34 2014 +0400
+++ b/Lib/IMPL/DOM/Navigator/Builder.pm	Mon Feb 10 17:41:34 2014 +0400
@@ -13,7 +13,6 @@
 BEGIN {
     private _direct property _schemaNavi => PROP_RW;
     private _direct property _docClass => PROP_RW;
-    public _direct property BuildErrors => PROP_RO | PROP_LIST;
     public _direct property Document => PROP_RO;
     public _direct property ignoreUndefined => PROP_RO;
 }
@@ -34,15 +33,13 @@
 sub NavigateCreate {
     my ($this,$nodeName,%props) = @_;
     
-    if (my $schemaNode = $this->{$_schemaNavi}->NavigateName($nodeName)) {
-        my $class = $schemaNode->can('nativeType') ? $schemaNode->nativeType || 'IMPL::DOM::Node' : 'IMPL::DOM::Node';
-        
-        my $schemaSource = $this->{$_schemaNavi}->SourceSchemaNode;
+    if (my $schemaType = $this->{$_schemaNavi}->NavigateName($nodeName)) {
+        my $class = $schemaType->can('nativeType') ? $schemaType->nativeType || 'IMPL::DOM::Node' : 'IMPL::DOM::Node';
         
-        my @errors = $this->inflateProperties($schemaNode,\%props);
-
-        $props{schema} = $schemaNode;
-        $props{schemaSource} = $schemaSource;
+        my $schemaNode = $this->{$_schemaNavi}->SourceSchemaNode;
+        
+        $props{schemaType} = $schemaType;
+        $props{schemaNode} = $schemaNode;
         
         my $node;
         if (! $this->{$Document}) {
@@ -57,20 +54,6 @@
             $this->internalNavigateNodeSet($node);
         }
         
-        if (@errors) {
-            $this->BuildErrors->Append(
-                map {
-                    IMPL::DOM::Schema::ValidationError->new(
-                        node => $node,
-                        source => $schemaSource,
-                        schema => $schemaNode,
-                        message => $schemaNode->messageInflateError,
-                        error => $_
-                    )                    
-                } @errors
-            );
-        }
-        
         return $node;
     } else {
         die new IMPL::InvalidOperationException("The specified node is undefined", $nodeName)
@@ -79,44 +62,6 @@
     }
 }
 
-sub inflateProperties {
-    my ($this,$schemaNode,$refProps) = @_;
-    my @errors;
-    foreach my $schemaProp ( $schemaNode->selectNodes('Property') ) {
-        next if not exists $refProps->{$schemaProp->name};
-        my $result = eval {$schemaProp->inflateValue($refProps->{$schemaProp->name}) };
-        if (my $e = $@) {
-            push @errors, $e;
-        } else {
-            $refProps->{$schemaProp->name} = $result;
-        }        
-    }
-    return @errors;
-}
-
-sub inflateValue {
-    my ($this,$value,$node,$strict) = @_;
-    
-    $strict ||= 0;
-    $node ||= $this->Current;
-    
-    my $nodeSchema = $this->{$_schemaNavi}->Current;
-    
-    my $result = eval { $nodeSchema->inflateValue($value) };
-    if (my $e=$@) {
-        $this->BuildErrors->Append(new IMPL::DOM::Schema::ValidationError(
-            schema =>  $nodeSchema,
-            node => $node,
-            error => $e,
-            message => $nodeSchema->messageInflateError,
-            source => $this->{$_schemaNavi}->SourceSchemaNode
-        ));
-        return $strict ? undef : $value ;
-    } else {
-        return $result;
-    }
-}
-
 sub Back {
     my ($this) = @_;
     
@@ -138,11 +83,6 @@
     $this->SUPER::restoreState;
 }
 
-#compatibility
-sub buildErrors {
-    goto &BuildErrors;
-}
-
 sub document {
     goto &Document;
 }
--- a/Lib/IMPL/DOM/Node.pm	Thu Jan 23 17:26:34 2014 +0400
+++ b/Lib/IMPL/DOM/Node.pm	Mon Feb 10 17:41:34 2014 +0400
@@ -23,8 +23,8 @@
         nodeValue => PROP_RW | PROP_DIRECT,
         childNodes => { get => \&_getChildNodes, isList => 1, direct => 1 },
         parentNode => PROP_RO | PROP_DIRECT,
-        schema => PROP_RO | PROP_DIRECT,
-        schemaSource => PROP_RO | PROP_DIRECT,
+        schemaNode => PROP_RO | PROP_DIRECT,
+        schemaType => PROP_RO | PROP_DIRECT,
         _propertyMap => PROP_RW | PROP_DIRECT
     ]
 };
@@ -486,15 +486,15 @@
 
 Ссылка на родительский элемент, если таковой имеется.
 
-=item C<[get] schema>
+=item C<[get] schemaType>
 
 Ссылка на узел из C<IMPL::DOM::Schema>, представляющий схему данных текущего узла. Может быть C<undef>.
 
-=item C<[get] schema>
+=item C<[get] schemaNode>
 
 Ссылка на узел из C<IMPL::DOM::Schema>, представляющий элемент схемы, объявляющий данный узел. Может быть C<undef>.
 
-Отличается от свойства C<schema> тем, что узел в случае ссылки на тип узла, данной свойство будет содержать
+Отличается от свойства C<schemaType> тем, что узел в случае ссылки на тип узла, данной свойство будет содержать
 описание ссылки C<IMPL::DOM::Schema::Node>, а свойство C<schema> например будет ссылаться на
 C<IMPL::DOM::Schema::ComplexType>.
 
--- a/Lib/IMPL/DOM/Schema/Node.pm	Thu Jan 23 17:26:34 2014 +0400
+++ b/Lib/IMPL/DOM/Schema/Node.pm	Mon Feb 10 17:41:34 2014 +0400
@@ -45,9 +45,9 @@
 }
 
 sub Validate {
-    my ($this,$node) = @_;
+    my ($this,$node,$ctx) = @_;
     
-    if (my $schemaType = $this->{$type} ? $this->document->resolveType($this->{$type}) : undef ) {
+    if (my $schemaType = $this->{$type} ? $this->document->ResolveType($this->{$type}) : undef ) {
         my @errors = $schemaType->Validate($node,{Source => $this});
         return @errors;
     } else {
@@ -67,12 +67,6 @@
     return ($this->{$maxOccur} eq 'unbounded' || $this->{$maxOccur} > 1 ) ? 1 : 0; 
 }
 
-sub inflateValue {
-    $_[1];
-}
-
-sub inflator { undef }
-
 sub qname {
     $_[0]->nodeName.'[name='.$_[0]->{$name}.']';
 }
@@ -123,18 +117,6 @@
 
 Имя узла.
 
-=item C<[get,set] display>
-
-Имя узла для отображения.
-
-=item C<[get,set] display_no>
-
-Имя узла для отображения (родительный падеж).
-
-=item C<[get,set] display_blame>
-
-Имя узла для отображения (винительный падеж).
-
 =back
 
 =cut
--- a/Lib/IMPL/DOM/XMLReader.pm	Thu Jan 23 17:26:34 2014 +0400
+++ b/Lib/IMPL/DOM/XMLReader.pm	Mon Feb 10 17:41:34 2014 +0400
@@ -61,7 +61,7 @@
 
 sub _OnEnd {
     my ($this,$element) = @_;
-    $this->{$_current}->nodeValue($this->Navigator->inflateValue( $this->{$_text} ) ) if length $this->{$_text} and (not $this->{$SkipWhitespace} or $this->{$_text} =~ /\S/);
+    $this->{$_current}->nodeValue($this->{$_text}) if length $this->{$_text} and (not $this->{$SkipWhitespace} or $this->{$_text} =~ /\S/);
     $this->{$_text} = pop @{$this->{$_textHistory}};
     $this->{$_current} = $this->Navigator->Back;
 }