Bug fixes and API changes from second unit test.
[shibboleth/cpp-xmltooling.git] / xmltooling / io / AbstractXMLObjectUnmarshaller.cpp
index ce3f358..ad168d1 100644 (file)
@@ -59,14 +59,14 @@ XMLObject* AbstractXMLObjectUnmarshaller::unmarshall(DOMElement* element, bool b
     XMLObject* xmlObject = buildXMLObject(element);\r
 \r
     if (element->hasAttributes()) {\r
-        unmarshallAttributes(element, xmlObject);\r
+        unmarshallAttributes(element, *xmlObject);\r
     }\r
 \r
     if (element->getTextContent()) {\r
-        processElementContent(xmlObject, element->getTextContent());\r
+        processElementContent(*xmlObject, element->getTextContent());\r
     }\r
 \r
-    unmarshallChildElements(element, xmlObject);\r
+    unmarshallChildElements(element, *xmlObject);\r
 \r
     /* TODO: Signing\r
     if (xmlObject instanceof SignableXMLObject) {\r
@@ -89,7 +89,7 @@ XMLObject* AbstractXMLObjectUnmarshaller::buildXMLObject(const DOMElement* domEl
     throw UnmarshallingException("Failed to locate XMLObjectBuilder for element.");\r
 }\r
 \r
-void AbstractXMLObjectUnmarshaller::unmarshallAttributes(const DOMElement* domElement, XMLObject* xmlObject) const\r
+void AbstractXMLObjectUnmarshaller::unmarshallAttributes(const DOMElement* domElement, XMLObject& xmlObject) const\r
 {\r
 #ifdef _DEBUG\r
     xmltooling::NDC ndc("unmarshallAttributes");\r
@@ -121,25 +121,28 @@ void AbstractXMLObjectUnmarshaller::unmarshallAttributes(const DOMElement* domEl
         attribute = static_cast<DOMAttr*>(childNode);\r
         \r
         const XMLCh* nsuri=attribute->getNamespaceURI();\r
-        if (!XMLString::compareString(nsuri,XMLConstants::XMLNS_NS)) {\r
+        if (XMLString::equals(nsuri,XMLConstants::XMLNS_NS)) {\r
             XT_log.debug("found namespace declaration, adding it to the list of namespaces on the XMLObject");\r
-            xmlObject->addNamespace(Namespace(attribute->getValue(), attribute->getLocalName()));\r
+            xmlObject.addNamespace(Namespace(attribute->getValue(), attribute->getLocalName(), true));\r
             continue;\r
         }\r
-        else if (!XMLString::compareString(nsuri,XMLConstants::XSI_NS) &&\r
-                    !XMLString::compareString(attribute->getLocalName(),type)) {\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
-            xmlObject->setSchemaType(xsitype.get());\r
+            xmlObject.setSchemaType(xsitype.get());\r
             continue;\r
         }\r
+        else if (nsuri) {\r
+            XT_log.debug("found namespace-qualified attribute, adding prefix to the list of namespaces on the XMLObject");\r
+            xmlObject.addNamespace(Namespace(nsuri, attribute->getPrefix()));\r
+        }\r
 \r
         XT_log.debug("processing generic attribute");\r
         processAttribute(xmlObject, attribute);\r
     }\r
 }\r
 \r
-void AbstractXMLObjectUnmarshaller::unmarshallChildElements(const DOMElement* domElement, XMLObject* xmlObject) const\r
+void AbstractXMLObjectUnmarshaller::unmarshallChildElements(const DOMElement* domElement, XMLObject& xmlObject) const\r
 {\r
 #ifdef _DEBUG\r
     xmltooling::NDC ndc("unmarshallChildElements");\r
@@ -164,27 +167,11 @@ void AbstractXMLObjectUnmarshaller::unmarshallChildElements(const DOMElement* do
         if (childNode->getNodeType() == DOMNode::ELEMENT_NODE) {\r
             unmarshaller = Unmarshaller::getUnmarshaller(static_cast<DOMElement*>(childNode));\r
             if (!unmarshaller) {\r
-                if (config.ignoreUnknownElements) {\r
-                    unmarshaller=Unmarshaller::getDefaultUnmarshaller();\r
-                    if (!unmarshaller) {\r
-                        auto_ptr<QName> cname(XMLHelper::getNodeQName(childNode));\r
-                        XT_log.error(\r
-                            "no default unmarshaller installed, found unknown child element %s",\r
-                            cname->toString().c_str()\r
-                            );\r
-                        throw UnmarshallingException(\r
-                            "Unmarshaller found unknown child element, but no default unmarshaller was found."\r
-                            );\r
-                    }\r
-                    else {\r
-                        XT_log.debug("using default unmarshaller");\r
-                    }\r
-                }\r
-                else {\r
-                    auto_ptr<QName> cname(XMLHelper::getNodeQName(childNode));\r
-                    XT_log.error("detected unknown child element %s", cname->toString().c_str());\r
-                    throw UnknownElementException("Unmarshaller found unknown child element.");\r
-                }\r
+                auto_ptr<QName> cname(XMLHelper::getNodeQName(childNode));\r
+                XT_log.error(\r
+                    "no default unmarshaller installed, found unknown child element %s", cname->toString().c_str()\r
+                    );\r
+                throw UnmarshallingException("Unmarshaller found unknown child element, but no default unmarshaller was found.");\r
             }\r
 \r
             if (XT_log.isDebugEnabled()) {\r