Fixes associated with wildcard test classes.
authorScott Cantor <cantor.2@osu.edu>
Mon, 6 Mar 2006 06:05:41 +0000 (06:05 +0000)
committerScott Cantor <cantor.2@osu.edu>
Mon, 6 Mar 2006 06:05:41 +0000 (06:05 +0000)
xmltooling/AbstractAttributeExtensibleXMLObject.h
xmltooling/XMLToolingConfig.cpp
xmltooling/base.h
xmltooling/io/AbstractXMLObjectMarshaller.cpp
xmltooling/io/AbstractXMLObjectMarshaller.h
xmltooling/io/AbstractXMLObjectUnmarshaller.cpp
xmltooling/io/AbstractXMLObjectUnmarshaller.h
xmltooling/util/XMLHelper.cpp
xmltooling/util/XMLHelper.h
xmltoolingtest/XMLObjectBaseTestCase.h
xmltoolingtest/xmltoolingtest.h

index c172b50..d7c6daa 100644 (file)
@@ -69,7 +69,6 @@ namespace xmltooling {
             const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL\r
             ) : AbstractDOMCachingXMLObject(namespaceURI,elementLocalName, namespacePrefix) {}\r
 \r
-    private:\r
         std::map<QName,XMLCh*> m_attributeMap;\r
     };\r
     \r
index e6fe259..3f15fac 100644 (file)
@@ -58,9 +58,9 @@ XMLToolingInternalConfig& XMLToolingInternalConfig::getInternalConfig()
 bool XMLToolingInternalConfig::log_config(const char* config)\r
 {\r
     try {\r
-        if (!config && !*config)\r
+        if (!config || !*config)\r
             config=getenv("XMLTOOLING_LOG_CONFIG");\r
-        if (!config && !*config)\r
+        if (!config || !*config)\r
             config="WARN";\r
         \r
         bool level=false;\r
@@ -149,6 +149,11 @@ bool XMLToolingInternalConfig::init()
 \r
 void XMLToolingInternalConfig::term()\r
 {\r
+    // default registrations\r
+    XMLObjectBuilder::deregisterDefaultBuilder();\r
+    Marshaller::deregisterDefaultMarshaller();\r
+    Unmarshaller::deregisterDefaultUnmarshaller();\r
+\r
     for (vector<void*>::reverse_iterator i=m_libhandles.rbegin(); i!=m_libhandles.rend(); i++) {\r
 #if defined(WIN32)\r
         FARPROC fn=GetProcAddress(static_cast<HMODULE>(*i),"xmltooling_extension_term");\r
index 2fbfda4..ab86bc7 100644 (file)
@@ -94,8 +94,12 @@ namespace xmltooling {
      * @param out   output sequence to copy cloned pointers into
      */
     template<class InputSequence,class OutputSequence> void clone(const InputSequence& in, OutputSequence& out) {
-        for (typename InputSequence::const_iterator i=in.begin(); i!=in.end(); i++)
-            out.push_back((*i)->clone());
+        for (typename InputSequence::const_iterator i=in.begin(); i!=in.end(); i++) {
+            if (*i)
+                out.push_back((*i)->clone());
+            else
+                out.push_back(*i);
+        }
     }
 
     /*
index 42a4080..da5cf65 100644 (file)
@@ -39,12 +39,8 @@ using namespace std;
 \r
 #define XT_log (*static_cast<Category*>(m_log))\r
 \r
-AbstractXMLObjectMarshaller::AbstractXMLObjectMarshaller(const XMLCh* targetNamespaceURI, const XMLCh* targetLocalName)\r
-        : m_targetQName(targetNamespaceURI, targetLocalName),\r
-        m_log(&Category::getInstance(XMLTOOLING_LOGCAT".Marshaller")) {\r
-    if (!targetLocalName || !*targetLocalName)\r
-        throw MarshallingException("targetLocalName cannot be null or empty");\r
-}\r
+AbstractXMLObjectMarshaller::AbstractXMLObjectMarshaller()\r
+    : m_log(&Category::getInstance(XMLTOOLING_LOGCAT".Marshaller")) {}\r
 \r
 DOMElement* AbstractXMLObjectMarshaller::marshall(XMLObject* xmlObject, DOMDocument* document) const\r
 {\r
index 2fd6511..beed4b3 100644 (file)
@@ -47,15 +47,7 @@ namespace xmltooling {
     \r
         \r
     protected:\r
-        /**\r
-         * Constructor.\r
-         * \r
-         * @param targetNamespaceURI the namespace URI of either the schema type QName or element QName of the elements this\r
-         *            marshaller operates on\r
-         * @param targetLocalName the local name of either the schema type QName or element QName of the elements this\r
-         *            marshaller operates on\r
-         */\r
-        AbstractXMLObjectMarshaller(const XMLCh* targetNamespaceURI, const XMLCh* targetLocalName);\r
+        AbstractXMLObjectMarshaller();\r
 \r
         /**\r
          * Sets the given element as the Document Element of the given Document.\r
@@ -132,8 +124,6 @@ namespace xmltooling {
         virtual void marshallElementContent(const XMLObject& xmlObject, DOMElement* domElement) const=0;\r
 \r
         void* m_log;\r
-    private:\r
-        QName m_targetQName;\r
     };\r
     \r
 };\r
index 939311f..03c7293 100644 (file)
@@ -38,12 +38,8 @@ using namespace std;
 \r
 #define XT_log (*static_cast<Category*>(m_log))\r
 \r
-AbstractXMLObjectUnmarshaller::AbstractXMLObjectUnmarshaller(const XMLCh* targetNamespaceURI, const XMLCh* targetLocalName)\r
-        : m_targetQName(targetNamespaceURI, targetLocalName),\r
-        m_log(&Category::getInstance(XMLTOOLING_LOGCAT".Unmarshaller")) {\r
-    if (!targetLocalName || !*targetLocalName)\r
-        throw UnmarshallingException("targetLocalName cannot be null or empty");\r
-}\r
+AbstractXMLObjectUnmarshaller::AbstractXMLObjectUnmarshaller()\r
+    : m_log(&Category::getInstance(XMLTOOLING_LOGCAT".Unmarshaller")) {}\r
 \r
 XMLObject* AbstractXMLObjectUnmarshaller::unmarshall(DOMElement* element, bool bindDocument) const\r
 {\r
@@ -62,12 +58,6 @@ XMLObject* AbstractXMLObjectUnmarshaller::unmarshall(DOMElement* element, bool b
         unmarshallAttributes(element, *(xmlObject.get()));\r
     }\r
 \r
-    const XMLCh* textContent=element->getTextContent();\r
-    if (textContent && *textContent) {\r
-        XT_log.debug("processing element content");\r
-        processElementContent(*(xmlObject.get()), textContent);\r
-    }\r
-\r
     unmarshallChildElements(element, *(xmlObject.get()));\r
 \r
     /* TODO: Signing\r
@@ -195,5 +185,9 @@ void AbstractXMLObjectUnmarshaller::unmarshallChildElements(const DOMElement* do
             processChildElement(xmlObject, childObject.get());\r
             childObject.release();\r
         }\r
+        else if (childNode->getNodeType() == DOMNode::TEXT_NODE) {\r
+            XT_log.debug("processing element content");\r
+            processElementContent(xmlObject, childNode->getNodeValue());\r
+        }\r
     }\r
 }\r
index acab0d2..89c8556 100644 (file)
@@ -41,15 +41,7 @@ namespace xmltooling {
         XMLObject* unmarshall(DOMElement* element, bool bindDocument=false) const;\r
             \r
     protected:\r
-        /**\r
-         * Constructor.\r
-         * \r
-         * @param targetNamespaceURI the namespace URI of either the schema type QName or element QName of the elements this\r
-         *            unmarshaller operates on\r
-         * @param targetLocalName the local name of either the schema type QName or element QName of the elements this\r
-         *            unmarshaller operates on\r
-         */\r
-        AbstractXMLObjectUnmarshaller(const XMLCh* targetNamespaceURI, const XMLCh* targetLocalName);\r
+        AbstractXMLObjectUnmarshaller();\r
 \r
         /**\r
          * Constructs the XMLObject that the given DOM Element will be unmarshalled into. If the DOM element has an XML\r
@@ -120,8 +112,6 @@ namespace xmltooling {
         virtual void processElementContent(XMLObject& xmlObject, const XMLCh* elementContent) const=0;\r
 \r
         void* m_log;\r
-    private:\r
-        QName m_targetQName;\r
     };\r
     \r
 };\r
index d4cd911..0c3691e 100644 (file)
@@ -117,6 +117,17 @@ DOMElement* XMLHelper::appendChildElement(DOMElement* parentElement, DOMElement*
     return childElement;\r
 }\r
 \r
+const XMLCh* XMLHelper::getTextContent(const DOMElement* e)\r
+{\r
+    DOMNode* child=e->getFirstChild();\r
+    while (child) {\r
+        if (child->getNodeType()==DOMNode::TEXT_NODE)\r
+            return child->getNodeValue();\r
+        child=child->getNextSibling();\r
+    }\r
+    return NULL;\r
+}\r
+\r
 void XMLHelper::serialize(const DOMElement* e, std::string& buf)\r
 {\r
     static const XMLCh impltype[] = { chLatin_L, chLatin_S, chNull };\r
index 3642029..c1ad4fe 100644 (file)
@@ -99,6 +99,16 @@ namespace xmltooling {
         }\r
 \r
         /**\r
+         * Returns the content of the first Text node found in the element, if any.\r
+         * This is roughly similar to the DOM getTextContent function, but only\r
+         * examples the immediate children of the element.\r
+         *\r
+         * @param e     element to examine\r
+         * @return the content of the first Text node found, or NULL\r
+         */\r
+        static const XMLCh* getTextContent(const DOMElement* e);\r
+\r
+        /**\r
          * Serializes the DOM Element provided into a buffer using UTF-8 encoding and\r
          * the default XML serializer available. No manipulation or formatting is applied.\r
          * \r
index 48aa272..9adb659 100644 (file)
@@ -15,7 +15,9 @@
  */\r
 \r
 #include <cxxtest/TestSuite.h>\r
+#include <xmltooling/AbstractAttributeExtensibleXMLObject.h>\r
 #include <xmltooling/AbstractDOMCachingXMLObject.h>\r
+#include <xmltooling/AbstractExtensibleXMLObject.h>\r
 #include <xmltooling/exceptions.h>\r
 #include <xmltooling/XMLObjectBuilder.h>\r
 #include <xmltooling/XMLToolingConfig.h>\r
@@ -37,8 +39,6 @@ extern string data_path;
     #pragma warning( disable : 4250 4251 )\r
 #endif\r
 \r
-class SimpleXMLObjectUnmarshaller;\r
-\r
 class SimpleXMLObject : public AbstractDOMCachingXMLObject\r
 {\r
 public:\r
@@ -87,7 +87,7 @@ private:
 class SimpleXMLObjectBuilder : public XMLObjectBuilder\r
 {\r
 public:\r
-    XMLObject* buildObject() const {\r
+    SimpleXMLObject* buildObject() const {\r
         return new SimpleXMLObject();\r
     }\r
 };\r
@@ -95,7 +95,7 @@ public:
 class SimpleXMLObjectMarshaller : public AbstractXMLObjectMarshaller\r
 {\r
 public:\r
-    SimpleXMLObjectMarshaller() : AbstractXMLObjectMarshaller(SimpleXMLObject::NAMESPACE, SimpleXMLObject::LOCAL_NAME) {}\r
+    SimpleXMLObjectMarshaller() {}\r
 \r
 private:\r
     void marshallAttributes(const XMLObject& xmlObject, DOMElement* domElement) const {\r
@@ -119,7 +119,7 @@ private:
 class SimpleXMLObjectUnmarshaller : public AbstractXMLObjectUnmarshaller\r
 {\r
 public:\r
-    SimpleXMLObjectUnmarshaller() : AbstractXMLObjectUnmarshaller(SimpleXMLObject::NAMESPACE, SimpleXMLObject::LOCAL_NAME) {}\r
+    SimpleXMLObjectUnmarshaller() {}\r
 \r
 private:\r
     void processChildElement(XMLObject& parentXMLObject, XMLObject* childXMLObject) const {\r
@@ -153,6 +153,112 @@ private:
 \r
 };\r
 \r
+class WildcardXMLObjectMarshaller;\r
+\r
+class WildcardXMLObject : public AbstractExtensibleXMLObject, public AbstractAttributeExtensibleXMLObject\r
+{\r
+    friend class WildcardXMLObjectMarshaller;\r
+public:\r
+    WildcardXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix)\r
+        : AbstractDOMCachingXMLObject(nsURI, localName, prefix),\r
+        AbstractExtensibleXMLObject(nsURI, localName, prefix),\r
+        AbstractAttributeExtensibleXMLObject(nsURI, localName, prefix) {}\r
+    virtual ~WildcardXMLObject() {}\r
+    \r
+    WildcardXMLObject* clone() const {\r
+        auto_ptr<XMLObject> domClone(AbstractDOMCachingXMLObject::clone());\r
+        WildcardXMLObject* ret=dynamic_cast<WildcardXMLObject*>(domClone.get());\r
+        if (ret) {\r
+            domClone.release();\r
+            return ret;\r
+        }\r
+\r
+        ret=new WildcardXMLObject(\r
+            getElementQName().getNamespaceURI(),getElementQName().getLocalPart(),getElementQName().getPrefix()\r
+            );\r
+        for (map<QName,XMLCh*>::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) {\r
+            ret->m_attributeMap[i->first]=XMLString::replicate(i->second);\r
+        }\r
+        xmltooling::clone(m_children, ret->m_children);\r
+        return ret;\r
+    }\r
+};\r
+\r
+class WildcardXMLObjectBuilder : public XMLObjectBuilder\r
+{\r
+public:\r
+    XMLObject* buildObject() const {\r
+        throw XMLObjectException("No default builder available.");\r
+    }\r
+\r
+    WildcardXMLObject* buildObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix) const {\r
+        return new WildcardXMLObject(nsURI,localName,prefix);\r
+    }\r
+};\r
+\r
+class WildcardXMLObjectMarshaller : public AbstractXMLObjectMarshaller\r
+{\r
+public:\r
+    WildcardXMLObjectMarshaller() : AbstractXMLObjectMarshaller() {}\r
+\r
+private:\r
+    void marshallAttributes(const XMLObject& xmlObject, DOMElement* domElement) const {\r
+        const WildcardXMLObject& wcXMLObject = dynamic_cast<const WildcardXMLObject&>(xmlObject);\r
+\r
+        for (map<QName,XMLCh*>::const_iterator i=wcXMLObject.m_attributeMap.begin(); i!=wcXMLObject.m_attributeMap.end(); i++) {\r
+            DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart());\r
+            if (i->first.hasPrefix())\r
+                attr->setPrefix(i->first.getPrefix());\r
+            attr->setNodeValue(i->second);\r
+            domElement->setAttributeNode(attr);\r
+        }\r
+    }\r
+\r
+    void marshallElementContent(const XMLObject& xmlObject, DOMElement* domElement) const {\r
+        const WildcardXMLObject& wcXMLObject = dynamic_cast<const WildcardXMLObject&>(xmlObject);\r
+\r
+        if(wcXMLObject.getTextContent()) {\r
+            domElement->appendChild(domElement->getOwnerDocument()->createTextNode(wcXMLObject.getTextContent()));\r
+        }\r
+    }\r
+};\r
+\r
+class WildcardXMLObjectUnmarshaller : public AbstractXMLObjectUnmarshaller\r
+{\r
+public:\r
+    WildcardXMLObjectUnmarshaller() {}\r
+\r
+private:\r
+    XMLObject* buildXMLObject(const DOMElement* domElement) const {\r
+        const WildcardXMLObjectBuilder* builder =\r
+            dynamic_cast<const WildcardXMLObjectBuilder*>(XMLObjectBuilder::getBuilder(domElement));\r
+        if (builder)\r
+            return builder->buildObject(domElement->getNamespaceURI(),domElement->getLocalName(),domElement->getPrefix());\r
+        throw UnmarshallingException("Failed to locate WildcardObjectBuilder for element.");\r
+    }\r
+\r
+    void processChildElement(XMLObject& parentXMLObject, XMLObject* childXMLObject) const {\r
+        WildcardXMLObject& wcXMLObject = dynamic_cast<WildcardXMLObject&>(parentXMLObject);\r
+\r
+        wcXMLObject.getXMLObjects().push_back(childXMLObject);\r
+    }\r
+\r
+    void processAttribute(XMLObject& xmlObject, const DOMAttr* attribute) const {\r
+        WildcardXMLObject& wcXMLObject = dynamic_cast<WildcardXMLObject&>(xmlObject);\r
+        \r
+        wcXMLObject.setAttribute(\r
+            QName(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()),\r
+            attribute->getNodeValue()\r
+            );\r
+    }\r
+\r
+    void processElementContent(XMLObject& xmlObject, const XMLCh* elementContent) const {\r
+        WildcardXMLObject& wcXMLObject = dynamic_cast<WildcardXMLObject&>(xmlObject);\r
+        \r
+        wcXMLObject.setTextContent(elementContent);\r
+    }\r
+\r
+};\r
 \r
 #if defined (_MSC_VER)\r
     #pragma warning( pop )\r
index 543758d..42c21c9 100644 (file)
@@ -30,7 +30,7 @@ class ToolingFixture : public CxxTest::GlobalFixture
 {\r
 public:\r
     bool setUpWorld() {\r
-        XMLToolingConfig::getConfig().log_config("DEBUG");\r
+        XMLToolingConfig::getConfig().log_config();\r
         if (!XMLToolingConfig::getConfig().init())\r
             return false;\r
         validatingPool = new ParserPool(true,true);\r