X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltoolingtest%2FXMLObjectBaseTestCase.h;h=1962683c96dd350fb113876601f6f7d49e5a8add;hb=ce200eaef5c771e132b64437d78540bfd4683572;hp=f74e9a5c20da2014e29b289ce629c130fd694c93;hpb=a039baceeda19f0e5c3269332a668763c0889e90;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltoolingtest/XMLObjectBaseTestCase.h b/xmltoolingtest/XMLObjectBaseTestCase.h index f74e9a5..1962683 100644 --- a/xmltoolingtest/XMLObjectBaseTestCase.h +++ b/xmltoolingtest/XMLObjectBaseTestCase.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005 Internet2 + * Copyright 2001-2010 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ #include +#include +#include #include #include #include @@ -23,19 +25,20 @@ #include #include #include -#ifndef XMLTOOLING_NO_XMLSEC - #include -#endif #include #include #include #include +#ifndef XMLTOOLING_NO_XMLSEC + #include + using namespace xmlsignature; +#endif + using namespace xmltooling; +using namespace xercesc; using namespace std; -extern ParserPool* validatingPool; -extern ParserPool* nonvalidatingPool; extern string data_path; #if defined (_MSC_VER) @@ -43,18 +46,24 @@ extern string data_path; #pragma warning( disable : 4250 4251 ) #endif -class SimpleXMLObject : public AbstractDOMCachingXMLObject, public AbstractXMLObjectMarshaller, public AbstractXMLObjectUnmarshaller +class SimpleXMLObject + : public AbstractAttributeExtensibleXMLObject, + public AbstractComplexElement, + public AbstractDOMCachingXMLObject, + public AbstractXMLObjectMarshaller, + public AbstractXMLObjectUnmarshaller { protected: - SimpleXMLObject(const SimpleXMLObject& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), - m_id(XMLString::replicate(src.m_id)), m_value(XMLString::replicate(src.m_value)) { + SimpleXMLObject(const SimpleXMLObject& src) + : AbstractXMLObject(src), AbstractAttributeExtensibleXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src), + m_id(XMLString::replicate(src.m_id)) { #ifndef XMLTOOLING_NO_XMLSEC m_children.push_back(NULL); m_signature=m_children.begin(); #endif VectorOf(SimpleXMLObject) mine=getSimpleXMLObjects(); for (vector::const_iterator i=src.m_simples.begin(); i!=src.m_simples.end(); i++) { - mine.push_back((*i) ? (*i)->clone() : NULL); + mine.push_back(dynamic_cast((*i)->clone())); } } @@ -67,8 +76,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 xmltooling::QName* schemaType=NULL + ) : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_id(NULL) { #ifndef XMLTOOLING_NO_XMLSEC m_children.push_back(NULL); m_signature=m_children.begin(); @@ -77,10 +86,9 @@ public: virtual ~SimpleXMLObject() { XMLString::release(&m_id); - XMLString::release(&m_value); } - SimpleXMLObject* clone() const { + XMLObject* clone() const { auto_ptr domClone(AbstractDOMCachingXMLObject::clone()); SimpleXMLObject* ret=dynamic_cast(domClone.get()); if (ret) { @@ -91,11 +99,12 @@ public: return new SimpleXMLObject(*this); } + const XMLCh* getXMLID() const { return getId(); } const XMLCh* getId() const { return m_id; } void setId(const XMLCh* id) { m_id=prepareForAssignment(m_id,id); } - const XMLCh* getValue() const { return m_value; } - void setValue(const XMLCh* value) { m_value=prepareForAssignment(m_value,value); } + const XMLCh* getValue() const { return getTextContent(); } + void setValue(const XMLCh* value) { setTextContent(value); } #ifndef XMLTOOLING_NO_XMLSEC Signature* getSignature() const { @@ -110,22 +119,25 @@ public: VectorOf(SimpleXMLObject) getSimpleXMLObjects() { return VectorOf(SimpleXMLObject)(this, m_simples, &m_children, m_children.end()); } + + const std::vector& getSimpleXMLObjects() const { + return m_simples; + } protected: - void marshallAttributes(DOMElement* domElement) const { + void marshallAttributes(xercesc::DOMElement* domElement) const { if(getId()) { domElement->setAttributeNS(NULL, SimpleXMLObject::ID_ATTRIB_NAME, getId()); +#ifdef XMLTOOLING_XERCESC_BOOLSETIDATTRIBUTE + domElement->setIdAttributeNS(NULL, SimpleXMLObject::ID_ATTRIB_NAME, true); +#else domElement->setIdAttributeNS(NULL, SimpleXMLObject::ID_ATTRIB_NAME); +#endif } + marshallExtensionAttributes(domElement); } - void marshallElementContent(DOMElement* domElement) const { - if(getValue()) { - domElement->setTextContent(getValue()); - } - } - - void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { + void processChildElement(XMLObject* childXMLObject, const xercesc::DOMElement* root) { SimpleXMLObject* simple=dynamic_cast(childXMLObject); if (simple) { getSimpleXMLObjects().push_back(simple); @@ -143,20 +155,16 @@ protected: throw UnmarshallingException("Unknown child element cannot be added to parent object."); } - void processAttribute(const DOMAttr* attribute) { - if (XMLHelper::isNodeNamed(attribute, NULL, SimpleXMLObject::ID_ATTRIB_NAME)) + void processAttribute(const xercesc::DOMAttr* attribute) { + if (XMLHelper::isNodeNamed(attribute, NULL, SimpleXMLObject::ID_ATTRIB_NAME)) { setId(attribute->getValue()); - else - throw UnmarshallingException("Unknown attribute cannot be processed by parent object."); - } - - void processElementContent(const XMLCh* elementContent) { - setValue(elementContent); + return; + } + unmarshallExtensionAttribute(attribute); } private: XMLCh* m_id; - XMLCh* m_value; vector m_simples; #ifndef XMLTOOLING_NO_XMLSEC list::iterator m_signature; @@ -166,14 +174,23 @@ private: class SimpleXMLObjectBuilder : public XMLObjectBuilder { public: - SimpleXMLObject* buildObject() const { + XMLObject* buildObject() const { return buildObject(SimpleXMLObject::NAMESPACE, SimpleXMLObject::LOCAL_NAME, SimpleXMLObject::NAMESPACE_PREFIX); } - SimpleXMLObject* buildObject( - const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix=NULL + XMLObject* buildObject( + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL ) const { - return new SimpleXMLObject(namespaceURI,elementLocalName,namespacePrefix); + return new SimpleXMLObject(nsURI, localName, prefix, schemaType); + } + + static SimpleXMLObject* buildSimpleXMLObject() { + const SimpleXMLObjectBuilder* b = dynamic_cast( + XMLObjectBuilder::getBuilder(xmltooling::QName(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME)) + ); + if (b) + return dynamic_cast(b->buildObject()); + throw XMLObjectException("Unable to obtain typed builder for SimpleXMLObject."); } };