X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fcpp-xmltooling.git;a=blobdiff_plain;f=xmltoolingtest%2FXMLObjectBaseTestCase.h;h=f36c032bda2cc6376cad4295d4709482cf4b3640;hp=18d02d55aadcdc98d4bcf23f996f8e55993aba6b;hb=c5183613326e3d36a544b2941654d0667a29b836;hpb=e48e1c0c331276a2c312cc798809a11385badc13 diff --git a/xmltoolingtest/XMLObjectBaseTestCase.h b/xmltoolingtest/XMLObjectBaseTestCase.h index 18d02d5..f36c032 100644 --- a/xmltoolingtest/XMLObjectBaseTestCase.h +++ b/xmltoolingtest/XMLObjectBaseTestCase.h @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -43,7 +42,7 @@ extern string data_path; #pragma warning( disable : 4250 4251 ) #endif -class SimpleXMLObject : public AbstractDOMCachingXMLObject +class SimpleXMLObject : public AbstractXMLObjectMarshaller, public AbstractXMLObjectUnmarshaller { public: static const XMLCh NAMESPACE[]; @@ -99,88 +98,61 @@ public: return ret; } -private: - XMLCh* m_id; - XMLCh* m_value; - vector m_simples; -#ifndef XMLTOOLING_NO_XMLSEC - list::iterator m_signature; -#endif -}; - -class SimpleXMLObjectBuilder : public XMLObjectBuilder -{ -public: - SimpleXMLObject* buildObject() const { - return new SimpleXMLObject(); - } -}; - -class SimpleXMLObjectMarshaller : public AbstractXMLObjectMarshaller -{ -public: - SimpleXMLObjectMarshaller() {} - -private: - void marshallAttributes(const XMLObject& xmlObject, DOMElement* domElement) const { - const SimpleXMLObject& simpleXMLObject = dynamic_cast(xmlObject); - - if(simpleXMLObject.getId()) { - domElement->setAttributeNS(NULL, SimpleXMLObject::ID_ATTRIB_NAME, simpleXMLObject.getId()); + void marshallAttributes(DOMElement* domElement) const { + if(getId()) { + domElement->setAttributeNS(NULL, SimpleXMLObject::ID_ATTRIB_NAME, getId()); domElement->setIdAttributeNS(NULL, SimpleXMLObject::ID_ATTRIB_NAME); } } - void marshallElementContent(const XMLObject& xmlObject, DOMElement* domElement) const { - const SimpleXMLObject& simpleXMLObject = dynamic_cast(xmlObject); - - if(simpleXMLObject.getValue()) { - domElement->setTextContent(simpleXMLObject.getValue()); + void marshallElementContent(DOMElement* domElement) const { + if(getValue()) { + domElement->setTextContent(getValue()); } } -}; - -class SimpleXMLObjectUnmarshaller : public AbstractXMLObjectUnmarshaller -{ -public: - SimpleXMLObjectUnmarshaller() {} - -private: - void processChildElement(XMLObject& parentXMLObject, XMLObject* childXMLObject, const DOMElement* root) const { - SimpleXMLObject& simpleXMLObject = dynamic_cast(parentXMLObject); + void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { if (XMLHelper::isNodeNamed(root, SimpleXMLObject::NAMESPACE, SimpleXMLObject::LOCAL_NAME)) - simpleXMLObject.getSimpleXMLObjects().push_back(dynamic_cast(childXMLObject)); + getSimpleXMLObjects().push_back(dynamic_cast(childXMLObject)); #ifndef XMLTOOLING_NO_XMLSEC else if (XMLHelper::isNodeNamed(root, XMLConstants::XMLSIG_NS, Signature::LOCAL_NAME)) - simpleXMLObject.setSignature(dynamic_cast(childXMLObject)); + setSignature(dynamic_cast(childXMLObject)); #endif else throw UnmarshallingException("Unknown child element cannot be added to parent object."); } - void processAttribute(XMLObject& xmlObject, const DOMAttr* attribute) const { - SimpleXMLObject& simpleXMLObject = dynamic_cast(xmlObject); - + void processAttribute(const DOMAttr* attribute) { if (XMLHelper::isNodeNamed(attribute, NULL, SimpleXMLObject::ID_ATTRIB_NAME)) - simpleXMLObject.setId(attribute->getValue()); + setId(attribute->getValue()); else throw UnmarshallingException("Unknown attribute cannot be processed by parent object."); } - void processElementContent(XMLObject& xmlObject, const XMLCh* elementContent) const { - SimpleXMLObject& simpleXMLObject = dynamic_cast(xmlObject); - - simpleXMLObject.setValue(elementContent); + void processElementContent(const XMLCh* elementContent) { + setValue(elementContent); } +private: + XMLCh* m_id; + XMLCh* m_value; + vector m_simples; +#ifndef XMLTOOLING_NO_XMLSEC + list::iterator m_signature; +#endif }; -class WildcardXMLObjectMarshaller; +class SimpleXMLObjectBuilder : public XMLObjectBuilder +{ +public: + SimpleXMLObject* buildObject(const DOMElement* e=NULL) const { + return new SimpleXMLObject(); + } +}; -class WildcardXMLObject : public AbstractElementProxy, public AbstractAttributeExtensibleXMLObject +class WildcardXMLObject : public AbstractElementProxy, public AbstractAttributeExtensibleXMLObject, + public AbstractXMLObjectMarshaller, public AbstractXMLObjectUnmarshaller { - friend class WildcardXMLObjectMarshaller; public: WildcardXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix) : AbstractDOMCachingXMLObject(nsURI, localName, prefix), @@ -207,30 +179,9 @@ public: xmltooling::clone(m_children, ret->m_children); return ret; } -}; - -class WildcardXMLObjectBuilder : public XMLObjectBuilder -{ -public: - XMLObject* buildObject() const { - throw XMLObjectException("No default builder available."); - } - - WildcardXMLObject* buildObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix) const { - return new WildcardXMLObject(nsURI,localName,prefix); - } -}; - -class WildcardXMLObjectMarshaller : public AbstractXMLObjectMarshaller -{ -public: - WildcardXMLObjectMarshaller() : AbstractXMLObjectMarshaller() {} -private: - void marshallAttributes(const XMLObject& xmlObject, DOMElement* domElement) const { - const WildcardXMLObject& wcXMLObject = dynamic_cast(xmlObject); - - for (map::const_iterator i=wcXMLObject.m_attributeMap.begin(); i!=wcXMLObject.m_attributeMap.end(); i++) { + void marshallAttributes(DOMElement* domElement) const { + for (map::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) { DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart()); if (i->first.hasPrefix()) attr->setPrefix(i->first.getPrefix()); @@ -239,48 +190,32 @@ private: } } - void marshallElementContent(const XMLObject& xmlObject, DOMElement* domElement) const { - const WildcardXMLObject& wcXMLObject = dynamic_cast(xmlObject); - - if(wcXMLObject.getTextContent()) { - domElement->appendChild(domElement->getOwnerDocument()->createTextNode(wcXMLObject.getTextContent())); + void marshallElementContent(DOMElement* domElement) const { + if(getTextContent()) { + domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); } } -}; -class WildcardXMLObjectUnmarshaller : public AbstractXMLObjectUnmarshaller -{ -public: - WildcardXMLObjectUnmarshaller() {} - -private: - XMLObject* buildXMLObject(const DOMElement* domElement) const { - const WildcardXMLObjectBuilder* builder = - dynamic_cast(XMLObjectBuilder::getBuilder(domElement)); - if (builder) - return builder->buildObject(domElement->getNamespaceURI(),domElement->getLocalName(),domElement->getPrefix()); - throw UnmarshallingException("Failed to locate WildcardObjectBuilder for element."); + void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { + getXMLObjects().push_back(childXMLObject); } - void processChildElement(XMLObject& parentXMLObject, XMLObject* childXMLObject, const DOMElement* root) const { - WildcardXMLObject& wcXMLObject = dynamic_cast(parentXMLObject); - - wcXMLObject.getXMLObjects().push_back(childXMLObject); - } - - void processAttribute(XMLObject& xmlObject, const DOMAttr* attribute) const { - WildcardXMLObject& wcXMLObject = dynamic_cast(xmlObject); - + void processAttribute(const DOMAttr* attribute) { QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); - wcXMLObject.setAttribute(q,attribute->getNodeValue()); + setAttribute(q,attribute->getNodeValue()); } - void processElementContent(XMLObject& xmlObject, const XMLCh* elementContent) const { - WildcardXMLObject& wcXMLObject = dynamic_cast(xmlObject); - - wcXMLObject.setTextContent(elementContent); + void processElementContent(const XMLCh* elementContent) { + setTextContent(elementContent); } +}; +class WildcardXMLObjectBuilder : public XMLObjectBuilder +{ +public: + WildcardXMLObject* buildObject(const DOMElement* e=NULL) const { + return new WildcardXMLObject(e->getNamespaceURI(),e->getLocalName(),e->getPrefix()); + } }; #if defined (_MSC_VER)