Cezar Andrei has proposed merging lp:~zorba-coders/zorba/bug891209-xsiType into 
lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
Related bugs:
  Bug #891209 in Zorba: "validation with xsi:type returns untyped"
  https://bugs.launchpad.net/zorba/+bug/891209

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug891209-xsiType/+merge/95476

Fix for bug 891209 : validation with xsi:type returns untyped.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug891209-xsiType/+merge/95476
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-03-01 21:22:16 +0000
+++ ChangeLog	2012-03-01 21:44:20 +0000
@@ -58,6 +58,7 @@
   * Fixed bug with unversioned modules with C++ external functions
   * Fixed bug #878508 (JSON Module not escaping escape characters)
   * Fixed bug #912579 (validate-in-place on non-root elements)
+  * Fixed bug #891209 (validation with xsi:type returns untyped)
 
 version 2.1
 

=== modified file 'src/types/schema/EventSchemaValidator.cpp'
--- src/types/schema/EventSchemaValidator.cpp	2011-08-19 03:26:59 +0000
+++ src/types/schema/EventSchemaValidator.cpp	2012-03-01 21:44:20 +0000
@@ -163,7 +163,7 @@
   StrX typeName(theSchemaValidatorFilter->getTypeName());
   StrX typeUri(theSchemaValidatorFilter->getTypeUri());
 
-  //cout << "  - getTypeQName: " << typeName << "@" << typeUri <<" ";
+  //cout << "  - getTypeQName:  " << typeName << " @ " << typeUri <<" ";
 
   store::Item_t typeQName;
   GENV_ITEMFACTORY->createQName(typeQName,
@@ -172,7 +172,7 @@
                                 typeName.localFormOrDefault ("untyped"));
 
   //cout << " : " << typeQName->getLocalName() << " @ "
-  //     << typeQName->getNamespace() <<"\n";
+  //     << typeQName->getNamespace() <<"\n"; std::cout.flush();
 
   return typeQName;
 }

=== modified file 'src/types/schema/SchemaValidatorFilter.cpp'
--- src/types/schema/SchemaValidatorFilter.cpp	2011-06-14 17:26:33 +0000
+++ src/types/schema/SchemaValidatorFilter.cpp	2012-03-01 21:44:20 +0000
@@ -867,7 +867,7 @@
     }
     --theAttrCount;  // remove att from the list but still needs to be reported
 
-    //cout << "   svf attrEvent: " << StrX(localname) << "  T: " <<
+    //std::cout << "   svf attrEvent: " << StrX(localname) << "  T: " <<
     //    StrX(typeName) << "\n";
     theEventBuffer->attributeEvent(emptyToNull(prefix), emptyToNull(uri),
         localname, value, emptyToNull(typeURI), typeName);
@@ -1062,7 +1062,9 @@
     {
       const ElemStack::StackElem* topElem = fElemStack.topElement();
       DatatypeValidator *currentDV = 0;
-      if(topElem->fThisElement->isDeclared())
+      if(topElem->fThisElement->isDeclared() ||
+         theXsiType  // this is when there is no schema import but xsiType is used
+        )
       {
         ComplexTypeInfo *currentTypeInfo = ((XercSchemaValidator*)fValidator)->
             getCurrentTypeInfo();

=== modified file 'src/types/schema/XercSchemaValidator.cpp'
--- src/types/schema/XercSchemaValidator.cpp	2011-06-14 17:26:33 +0000
+++ src/types/schema/XercSchemaValidator.cpp	2012-03-01 21:44:20 +0000
@@ -23,7 +23,6 @@
 //  Includes
 // ---------------------------------------------------------------------------
 #include "stdafx.h"
-#include "XercSchemaValidator.h"
 
 #include <xercesc/util/Janitor.hpp>
 #include <xercesc/framework/XMLDocumentHandler.hpp>
@@ -54,7 +53,8 @@
 
 
 #include "diagnostics/assert.h"
-//#include "StrX.h"
+#include "StrX.h"
+#include "XercSchemaValidator.h"
 
 using namespace XERCES_CPP_NAMESPACE;
 

=== modified file 'src/types/schema/validate.cpp'
--- src/types/schema/validate.cpp	2011-09-22 21:50:20 +0000
+++ src/types/schema/validate.cpp	2012-03-01 21:44:20 +0000
@@ -54,7 +54,7 @@
 #include "diagnostics/assert.h"
 #include "zorba/store_consts.h"
 
-using namespace std;
+//using namespace std;
 
 namespace zorba
 {
@@ -145,16 +145,26 @@
     //cout << "No schema: isNode() " << sourceNode->isNode() << "  nodeKind: "<<
     // sourceNode->getNodeKind() << endl;
 
-    if ( validationMode == ParseConstants::val_strict )
-    {
-      throw XQUERY_EXCEPTION( err::XQDY0084, ERROR_LOC( loc ) );
-    }
-    else
-    {
+    // if we got here it basicaly means that there was no import but
+    // validation is used so we need to set up schema in the typeManager anyway
+    // validation has to work for xsiType and built-in types
+
+    TypeManagerImpl *typeManagerImpl = static_cast<TypeManagerImpl*>(typeManager);
+    typeManagerImpl->initializeSchema();
+    schema = typeManager->getSchema();
+
+
+
+//    if ( validationMode == ParseConstants::val_strict )
+//    {
+//      throw XQUERY_EXCEPTION( err::XQDY0084, ERROR_LOC( loc ) );
+//    }
+//    else
+//    {
       // no schema available - items remain the same
-      result = sourceNode;
-      return true;    
-    }
+//      result = sourceNode;
+//      return true;
+//    }
   }
 
 #ifndef ZORBA_NO_XMLSCHEMA
@@ -382,8 +392,8 @@
     ZORBA_ASSERT(attribute->isNode());
     ZORBA_ASSERT(attribute->getNodeKind() == store::StoreConsts::attributeNode);
 
-    //cout << " v    - attr: " << attribute->getNodeName()->getLocalName()->
-    //  c_str() << "\n"; cout.flush();
+    //cout << " v    - attr: " << attribute->getNodeName()->getLocalName() << ":" <<
+    //        attribute->getStringValue() << "\n"; cout.flush();
 
     store::Item_t attName = attribute->getNodeName();
     schemaValidator.attr(attName, attribute->getStringValue());
@@ -472,9 +482,9 @@
   {
     if ( child->isNode() )
     {
-      //cout << "  > child: " << child->getNodeKind() << " " <<
-      // (child->getType() != NULL ? child->getType()->getLocalName()
-      // : "type_NULL" ) << "\n"; cout.flush();
+      //cout << "  > child: " << (long)child->getNodeKind() << " " <<
+      //  //(child->getType() != NULL ? child->getType()->getLocalName() : "type_NULL" ) <<
+      //  "\n"; cout.flush();
 
       switch ( child->getNodeKind() )
       {
@@ -515,7 +525,7 @@
           cout << "     - text: '" << childStringValue << "' T: " <<
             typeQName->getLocalName() << "\n"; cout.flush();
           cout << "        xqT: " << xqType->toString() << "  content_kind: " <<
-            xqType->content_kind() << " tKind:" << xqType->type_kind() << " \n";
+            (long)xqType->content_kind() << " tKind:" << (long)xqType->type_kind() << " \n";
           cout.flush();
         }
         else
@@ -649,9 +659,9 @@
   xqtref_t type = typeManager->create_named_type(typeQName.getp(),
                                                  TypeConstants::QUANT_ONE);
 
-  //cout << "     - processTextValue: " << typeQName->getPrefix()->str()
-  //     << ":" << typeQName->getLocalName()->str() << "@"
-  //     << typeQName->getNamespace()->str() ; cout.flush();
+  //cout << "     - processTextValue: " << typeQName->getPrefix()
+  //     << ":" << typeQName->getLocalName() << "@"
+  //     << typeQName->getNamespace() ; cout.flush();
   //cout << " type: " << (type==NULL ? "NULL" : type->toString()) << "\n"; cout.flush();
 
   // TODO: we probably need the ns bindings from the static context

=== modified file 'src/types/typemanagerimpl.cpp'
--- src/types/typemanagerimpl.cpp	2012-01-26 19:56:14 +0000
+++ src/types/typemanagerimpl.cpp	2012-03-01 21:44:20 +0000
@@ -336,11 +336,11 @@
       {
         if (error != zerr::ZXQP0000_NO_ERROR)
         {
-					throw XQUERY_EXCEPTION_VAR(
-						error,
-						ERROR_PARAMS(qname->getStringValue(), ZED(NotAmongInScopeSchemaTypes)),
-						ERROR_LOC( loc )
-					);
+            throw XQUERY_EXCEPTION_VAR(
+                error,
+                ERROR_PARAMS(qname->getStringValue(), ZED(NotAmongInScopeSchemaTypes)),
+                ERROR_LOC( loc )
+            );
         }
         else
         {

=== added file 'test/rbkt/ExpQueryResults/zorba/schemas/val-xsiType-noSchemaImport.xml.res'
--- test/rbkt/ExpQueryResults/zorba/schemas/val-xsiType-noSchemaImport.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/schemas/val-xsiType-noSchemaImport.xml.res	2012-03-01 21:44:20 +0000
@@ -0,0 +1,1 @@
+xs:integer

=== added file 'test/rbkt/Queries/zorba/schemas/val-xsiType-noSchemaImport.xq'
--- test/rbkt/Queries/zorba/schemas/val-xsiType-noSchemaImport.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/schemas/val-xsiType-noSchemaImport.xq	2012-03-01 21:44:20 +0000
@@ -0,0 +1,11 @@
+import module namespace schema = "http://www.zorba-xquery.com/modules/schema";;
+
+schema:schema-type(
+  data(
+    validate lax { 
+      <a 
+        xmlns:xs="http://www.w3.org/2001/XMLSchema";
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+        xsi:type="xs:integer">2</a> }
+  )
+)

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to