Set xsi:type during object construction.
authorScott Cantor <cantor.2@osu.edu>
Wed, 29 Mar 2006 17:11:38 +0000 (17:11 +0000)
committerScott Cantor <cantor.2@osu.edu>
Wed, 29 Mar 2006 17:11:38 +0000 (17:11 +0000)
14 files changed:
xmltooling/AbstractXMLObject.cpp
xmltooling/AbstractXMLObject.h
xmltooling/XMLObject.h
xmltooling/XMLObjectBuilder.h
xmltooling/base.h
xmltooling/impl/AnyElement.cpp
xmltooling/impl/AnyElement.h
xmltooling/impl/UnknownElement.h
xmltooling/io/AbstractXMLObjectUnmarshaller.cpp
xmltooling/signature/impl/KeyInfoImpl.cpp
xmltooling/signature/impl/XMLSecSignatureImpl.cpp
xmltooling/signature/impl/XMLSecSignatureImpl.h
xmltoolingtest/MarshallingTest.h
xmltoolingtest/XMLObjectBaseTestCase.h

index 4e0005b..cdba177 100644 (file)
@@ -34,11 +34,15 @@ AbstractXMLObject::~AbstractXMLObject() {
     std::for_each(m_children.begin(), m_children.end(), cleanup<XMLObject>());\r
 }\r
 \r
-AbstractXMLObject::AbstractXMLObject(const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix)\r
-    : m_elementQname(namespaceURI,elementLocalName, namespacePrefix), m_typeQname(NULL), m_parent(NULL),\r
+AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)\r
+    : m_elementQname(nsURI, localName, prefix), m_typeQname(NULL), m_parent(NULL),\r
         m_log(&log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject"))\r
 {\r
-    addNamespace(Namespace(namespaceURI, namespacePrefix));\r
+    addNamespace(Namespace(nsURI, prefix));\r
+    if (schemaType) {\r
+        m_typeQname = new QName(*schemaType);\r
+        addNamespace(Namespace(m_typeQname->getNamespaceURI(), m_typeQname->getPrefix()));\r
+    }\r
 }\r
 \r
 AbstractXMLObject::AbstractXMLObject(const AbstractXMLObject& src)\r
index 6beecfd..7a4ff1f 100644 (file)
@@ -62,15 +62,6 @@ namespace xmltooling {
             return m_typeQname;\r
         }\r
     \r
-        void setSchemaType(const QName* type) {\r
-            delete m_typeQname;\r
-            m_typeQname = NULL;\r
-            if (type) {\r
-                m_typeQname = new QName(*type);\r
-                addNamespace(Namespace(type->getNamespaceURI(), type->getPrefix()));\r
-            }\r
-        }\r
-    \r
         bool hasParent() const {\r
             return m_parent != NULL;\r
         }\r
@@ -95,11 +86,14 @@ namespace xmltooling {
         /**\r
          * Constructor\r
          * \r
-         * @param namespaceURI the namespace the element is in\r
-         * @param elementLocalName the local name of the XML element this Object represents\r
-         * @param namespacePrefix the namespace prefix to use\r
+         * @param nsURI         the namespace of the element\r
+         * @param localName     the local name of the XML element this Object represents\r
+         * @param prefix        the namespace prefix to use\r
+         * @param schemaType    the xsi:type to use\r
          */\r
-        AbstractXMLObject(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL);\r
+        AbstractXMLObject(\r
+            const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL\r
+            );\r
 \r
         /** Copy constructor. */\r
         AbstractXMLObject(const AbstractXMLObject& src);\r
index 09e72c9..46157b8 100644 (file)
@@ -133,14 +133,6 @@ namespace xmltooling {
         virtual const QName* getSchemaType() const=0;\r
         \r
         /**\r
-         * Sets the XML schema type of this element.  This translates to contents the xsi:type\r
-         * attribute for the element.\r
-         * \r
-         * @param type XML schema type of this element\r
-         */\r
-        virtual void setSchemaType(const QName* type)=0;\r
-        \r
-        /**\r
          * Checks to see if this object has a parent.\r
          * \r
          * @return true if the object has a parent, false if not\r
index f78ae6d..25fcbb7 100644 (file)
@@ -26,6 +26,7 @@
 #include <map>
 #include <xmltooling/QName.h>
 #include <xmltooling/XMLObject.h>
+#include <xmltooling/util/XMLHelper.h>
 
 #if defined (_MSC_VER)
     #pragma warning( push )
@@ -46,15 +47,16 @@ namespace xmltooling {
         
         /**
          * Creates an empty XMLObject with a particular element name.
-         * The results are undefined if elementLocalName is NULL or empty.
+         * The results are undefined if localName is NULL or empty.
          * 
-         * @param namespaceURI          namespace URI for element
-         * @param elementLocalName      local name of element
-         * @param namespacePrefix       prefix of element name
+         * @param nsURI         namespace URI for element
+         * @param localName     local name of element
+         * @param prefix        prefix of element name
+         * @param schemaType    xsi:type of the object
          * @return the empty XMLObject
          */
         virtual XMLObject* buildObject(
-            const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix=NULL
+            const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL
             ) const=0;
 
         /**
@@ -75,7 +77,9 @@ namespace xmltooling {
          * @return the unmarshalled XMLObject
          */
         XMLObject* buildFromElement(DOMElement* element, bool bindDocument=false) const {
-            std::auto_ptr<XMLObject> ret(buildObject(element->getNamespaceURI(),element->getLocalName(),element->getPrefix()));
+            std::auto_ptr<XMLObject> ret(
+                buildObject(element->getNamespaceURI(),element->getLocalName(),element->getPrefix(),XMLHelper::getXSIType(element))
+                );
             ret->unmarshall(element,bindDocument);
             return ret.release();
         }
index 9aa9bd9..d2060cb 100644 (file)
 #define BEGIN_XMLOBJECTBUILDERIMPL(cname,namespaceURI) \
     class XMLTOOL_DLLLOCAL cname##BuilderImpl : public cname##Builder { \
     public: \
-        cname* buildObject(const XMLCh* ns, const XMLCh* name, const XMLCh* prefix=NULL) const; \
+        cname* buildObject( \
+            const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL\
+            ) const; \
         cname* buildObject() const { \
             return buildObject(namespaceURI,cname::LOCAL_NAME,cname::PREFIX); \
         }
index 8ed8a8d..9d26f51 100644 (file)
@@ -54,8 +54,8 @@ namespace xmltooling {
     public:
         virtual ~AnyElementImpl() {}
 
-        AnyElementImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix)
-            : AbstractXMLObject(nsURI, localName, prefix) {}
+        AnyElementImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL)
+            : AbstractXMLObject(nsURI, localName, prefix, schemaType) {}
         
         AnyElementImpl* clone() const {
             auto_ptr<XMLObject> domClone(AbstractDOMCachingXMLObject::clone());
@@ -114,7 +114,7 @@ namespace xmltooling {
 
 
 XMLObject* AnyElementBuilder::buildObject(
-    const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix
+    const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType
     ) const {
-    return new AnyElementImpl(namespaceURI,elementLocalName,namespacePrefix);
+    return new AnyElementImpl(nsURI, localName, prefix, schemaType);
 }
index 27654a0..4bda237 100644 (file)
@@ -36,7 +36,7 @@ namespace xmltooling {
     {
     public:
         XMLObject* buildObject(
-            const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix=NULL
+            const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL
             ) const;
     };
 
index dd7f3be..4e2e03b 100644 (file)
@@ -75,9 +75,9 @@ namespace xmltooling {
     {\r
     public:\r
         XMLObject* buildObject(\r
-            const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix=NULL\r
+            const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL\r
             ) const {\r
-            return new UnknownElementImpl(namespaceURI,elementLocalName,namespacePrefix);\r
+            return new UnknownElementImpl(nsURI,localName,prefix);\r
         }\r
     };\r
 \r
index 12e0327..465b432 100644 (file)
@@ -117,9 +117,7 @@ void AbstractXMLObjectUnmarshaller::unmarshallAttributes(const DOMElement* domEl
             }\r
         }\r
         else if (XMLString::equals(nsuri,XMLConstants::XSI_NS) && XMLString::equals(attribute->getLocalName(),type)) {\r
-            XT_log.debug("found xsi:type declaration, setting the schema type of the XMLObject");\r
-            auto_ptr<QName> xsitype(XMLHelper::getAttributeValueAsQName(attribute));\r
-            setSchemaType(xsitype.get());\r
+            XT_log.debug("skipping xsi:type declaration");\r
             continue;\r
         }\r
         else if (nsuri && !XMLString::equals(nsuri,XMLConstants::XML_NS)) {\r
index d49d0ba..2d73ed8 100644 (file)
@@ -49,8 +49,8 @@ namespace xmltooling {
     public:\r
         virtual ~KeyInfoImpl() {}\r
 \r
-        KeyInfoImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix)\r
-            : AbstractXMLObject(nsURI, localName, prefix), m_Id(NULL) {}\r
+        KeyInfoImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)\r
+            : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_Id(NULL) {}\r
             \r
         KeyInfoImpl(const KeyInfoImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src),\r
             AbstractElementProxy(src), AbstractValidatingXMLObject(src), m_Id(XMLString::replicate(src.m_Id)) {\r
@@ -96,7 +96,9 @@ namespace xmltooling {
     #pragma warning( pop )\r
 #endif\r
 \r
-KeyInfo* KeyInfoBuilderImpl::buildObject(const XMLCh* ns, const XMLCh* name, const XMLCh* prefix) const\r
+KeyInfo* KeyInfoBuilderImpl::buildObject(\r
+    const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType\r
+    ) const\r
 {\r
-    return new KeyInfoImpl(ns,name,prefix);\r
+    return new KeyInfoImpl(nsURI,localName,prefix,schemaType);\r
 }\r
index afb65d9..d320a3d 100644 (file)
@@ -401,9 +401,11 @@ XMLObject* XMLSecSignatureImpl::unmarshall(DOMElement* element, bool bindDocumen
     return this;\r
 }\r
 \r
-Signature* XMLSecSignatureBuilder::buildObject(const XMLCh* ns, const XMLCh* name, const XMLCh* prefix) const\r
+Signature* XMLSecSignatureBuilder::buildObject(\r
+    const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType\r
+    ) const\r
 {\r
-    if (!XMLString::equals(ns,XMLConstants::XMLSIG_NS) || !XMLString::equals(name,Signature::LOCAL_NAME))\r
+    if (!XMLString::equals(nsURI,XMLConstants::XMLSIG_NS) || !XMLString::equals(localName,Signature::LOCAL_NAME))\r
         throw XMLObjectException("XMLSecSignatureBuilder requires standard Signature element name.");\r
     return buildObject();\r
 }\r
index 6bcc4eb..41b2470 100644 (file)
@@ -30,7 +30,9 @@ namespace xmltooling {
     class XMLTOOL_DLLLOCAL XMLSecSignatureBuilder : public SignatureBuilder\r
     {\r
     public:\r
-        Signature* buildObject(const XMLCh* ns, const XMLCh* name, const XMLCh* prefix=NULL) const;\r
+        Signature* buildObject(\r
+            const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL\r
+            ) const;\r
         Signature* buildObject() const;\r
     };\r
 \r
index af687e3..a5f5091 100644 (file)
@@ -95,8 +95,7 @@ public:
         kids.erase(kids.begin()+1);\r
         TS_ASSERT_SAME_DATA(kids.back()->getValue(), bar.get(), XMLString::stringLen(bar.get()));\r
         \r
-        kids.push_back(b->buildObject(SimpleXMLObject::NAMESPACE,SimpleXMLObject::DERIVED_NAME,SimpleXMLObject::NAMESPACE_PREFIX));\r
-        kids.back()->setSchemaType(&m_qtype);\r
+        kids.push_back(b->buildObject(SimpleXMLObject::NAMESPACE,SimpleXMLObject::DERIVED_NAME,SimpleXMLObject::NAMESPACE_PREFIX,&m_qtype));\r
         kids.back()->setValue(baz.get());\r
         \r
         DOMElement* rootElement = sxObject->marshall();\r
index f74e9a5..ba1116f 100644 (file)
@@ -67,8 +67,8 @@ public:
     static const XMLCh ID_ATTRIB_NAME[];
 
     SimpleXMLObject(
-        const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL
-        ) : AbstractXMLObject(namespaceURI, elementLocalName, namespacePrefix), m_id(NULL), m_value(NULL) {
+        const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL
+        ) : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_id(NULL), m_value(NULL) {
 #ifndef XMLTOOLING_NO_XMLSEC
         m_children.push_back(NULL);
         m_signature=m_children.begin();
@@ -171,9 +171,9 @@ public:
     }
 
     SimpleXMLObject* buildObject(
-        const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix=NULL
+        const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL
         ) const {
-        return new SimpleXMLObject(namespaceURI,elementLocalName,namespacePrefix);
+        return new SimpleXMLObject(nsURI, localName, prefix, schemaType);
     }
 };