diff Lib/IMPL/DOM/Schema/ComplexType.pm @ 103:c289ed9662ca

Schema beta 2 More strict validation, support for inflating a simple nodes and properties
author wizard
date Fri, 07 May 2010 18:17:40 +0400
parents cf3b6ef2be22
children a6e9759ff88a
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Schema/ComplexType.pm	Fri May 07 08:05:23 2010 +0400
+++ b/Lib/IMPL/DOM/Schema/ComplexType.pm	Fri May 07 18:17:40 2010 +0400
@@ -8,6 +8,7 @@
 
 BEGIN {
     public _direct property nativeType => prop_get;
+    public _direct property messageWrongType => prop_get;
 }
 
 our %CTOR = (
@@ -25,10 +26,25 @@
     my ($this,%args) = @_;
     
     $this->{$nativeType} = $args{nativeType};
+    $this->{$messageWrongType} = $args{messageWrongType} || "A complex node '%Node.path%' is expected to be %Schema.nativeType%";
+}
+
+sub Validate {
+	my ($this, $node) = @_;
+	
+	if ($this->{$nativeType}) {
+		return new IMPL::DOM::Schema::ValidationError(
+			Node => $node,
+			Source => $this,
+			Schema => $this,
+			Message => $this->messageWrongType
+		) unless $node->isa($this->{$nativeType});
+	}
+	return $this->SUPER::Validate($node);
 }
 
 sub qname {
-	$_[0]->nodeName.'[name='.$_[0]->type.']';
+	$_[0]->nodeName.'[type='.$_[0]->type.']';
 }