*/\r
\r
#include "internal.h"\r
-#include "DOMCachingXMLObject.h"\r
#include "exceptions.h"\r
#include "XMLObjectBuilder.h"\r
#include "io/AbstractXMLObjectUnmarshaller.h"\r
\r
#define XT_log (*static_cast<Category*>(m_log))\r
\r
-AbstractXMLObjectUnmarshaller::AbstractXMLObjectUnmarshaller()\r
- : m_log(&Category::getInstance(XMLTOOLING_LOGCAT".Unmarshaller")) {}\r
-\r
-XMLObject* AbstractXMLObjectUnmarshaller::unmarshall(DOMElement* element, bool bindDocument) const\r
+XMLObject* AbstractXMLObjectUnmarshaller::unmarshall(DOMElement* element, bool bindDocument)\r
{\r
#ifdef _DEBUG\r
xmltooling::NDC ndc("unmarshall");\r
XT_log.debug("unmarshalling DOM element (%s)", dname.get());\r
}\r
\r
- auto_ptr<XMLObject> xmlObject(buildXMLObject(element));\r
-\r
if (element->hasAttributes()) {\r
- unmarshallAttributes(element, *(xmlObject.get()));\r
+ unmarshallAttributes(element);\r
}\r
\r
- unmarshallChildElements(element, *(xmlObject.get()));\r
+ unmarshallChildElements(element);\r
\r
/* TODO: Signing\r
if (xmlObject instanceof SignableXMLObject) {\r
}\r
*/\r
\r
- DOMCachingXMLObject* dc=dynamic_cast<DOMCachingXMLObject*>(xmlObject.get());\r
- if (dc)\r
- dc->setDOM(element,bindDocument);\r
- else if (bindDocument)\r
- throw UnmarshallingException("Unable to bind document to non-DOM caching XMLObject instance.");\r
- \r
- return xmlObject.release();\r
-}\r
-\r
-XMLObject* AbstractXMLObjectUnmarshaller::buildXMLObject(const DOMElement* domElement) const\r
-{\r
- const XMLObjectBuilder* xmlObjectBuilder = XMLObjectBuilder::getBuilder(domElement);\r
- if (xmlObjectBuilder)\r
- return xmlObjectBuilder->buildObject();\r
- throw UnmarshallingException("Failed to locate XMLObjectBuilder for element.");\r
+ setDOM(element,bindDocument);\r
+ return this;\r
}\r
\r
-void AbstractXMLObjectUnmarshaller::unmarshallAttributes(const DOMElement* domElement, XMLObject& xmlObject) const\r
+void AbstractXMLObjectUnmarshaller::unmarshallAttributes(const DOMElement* domElement)\r
{\r
#ifdef _DEBUG\r
xmltooling::NDC ndc("unmarshallAttributes");\r
if (XMLString::equals(nsuri,XMLConstants::XMLNS_NS)) {\r
if (XMLString::equals(attribute->getLocalName(),XMLConstants::XMLNS_PREFIX)) {\r
XT_log.debug("found default namespace declaration, adding it to the list of namespaces on the XMLObject");\r
- xmlObject.addNamespace(Namespace(attribute->getValue(), NULL, true));\r
+ addNamespace(Namespace(attribute->getValue(), NULL, true));\r
continue;\r
}\r
else {\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(), true));\r
+ addNamespace(Namespace(attribute->getValue(), attribute->getLocalName(), true));\r
continue;\r
}\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
- xmlObject.setSchemaType(xsitype.get());\r
+ setSchemaType(xsitype.get());\r
continue;\r
}\r
else if (nsuri && !XMLString::equals(nsuri,XMLConstants::XML_NS)) {\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
+ addNamespace(Namespace(nsuri, attribute->getPrefix()));\r
}\r
\r
XT_log.debug("processing generic attribute");\r
- processAttribute(xmlObject, attribute);\r
+ processAttribute(attribute);\r
}\r
}\r
\r
-void AbstractXMLObjectUnmarshaller::unmarshallChildElements(const DOMElement* domElement, XMLObject& xmlObject) const\r
+void AbstractXMLObjectUnmarshaller::unmarshallChildElements(const DOMElement* domElement)\r
{\r
#ifdef _DEBUG\r
xmltooling::NDC ndc("unmarshallChildElements");\r
\r
DOMNodeList* childNodes = domElement->getChildNodes();\r
DOMNode* childNode;\r
- const Unmarshaller* unmarshaller;\r
if (!childNodes || childNodes->getLength()==0) {\r
XT_log.debug("element had no children");\r
return;\r
for (XMLSize_t i = 0; i < childNodes->getLength(); i++) {\r
childNode = childNodes->item(i);\r
if (childNode->getNodeType() == DOMNode::ELEMENT_NODE) {\r
- unmarshaller = Unmarshaller::getUnmarshaller(static_cast<DOMElement*>(childNode));\r
- if (!unmarshaller) {\r
+ const XMLObjectBuilder* builder = XMLObjectBuilder::getBuilder(static_cast<DOMElement*>(childNode));\r
+ if (!builder) {\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
+ XT_log.error("no default builder installed, found unknown child element (%s)", cname->toString().c_str());\r
+ throw UnmarshallingException("Unmarshaller found unknown child element, but no default builder was found.");\r
}\r
\r
if (XT_log.isDebugEnabled()) {\r
}\r
\r
// Retain ownership of the unmarshalled child until it's processed by the parent.\r
- auto_ptr<XMLObject> childObject(unmarshaller->unmarshall(static_cast<DOMElement*>(childNode)));\r
- processChildElement(xmlObject, childObject.get(), static_cast<DOMElement*>(childNode));\r
+ auto_ptr<XMLObject> childObject(builder->buildObject(static_cast<DOMElement*>(childNode)));\r
+ childObject->unmarshall(static_cast<DOMElement*>(childNode));\r
+ processChildElement(childObject.get(), static_cast<DOMElement*>(childNode));\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
+ processElementContent(childNode->getNodeValue());\r
}\r
}\r
}\r