X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltoolingtest%2FXMLObjectBaseTestCase.h;h=d2d56c0f04abc40724347caac86de289fa804463;hb=38003505e53ef5b8c2590af38cfbb0d405ad245f;hp=873f2275042943c610359af76e015f574057c66a;hpb=90b649c84f13dcfbebc2f15e43219401f222bcba;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltoolingtest/XMLObjectBaseTestCase.h b/xmltoolingtest/XMLObjectBaseTestCase.h index 873f227..d2d56c0 100644 --- a/xmltoolingtest/XMLObjectBaseTestCase.h +++ b/xmltoolingtest/XMLObjectBaseTestCase.h @@ -15,26 +15,28 @@ */ #include -#include -#include +#include +#include #include #include #include #include #include -#ifndef XMLTOOLING_NO_XMLSEC - #include -#endif +#include +#include #include #include #include #include +#ifndef XMLTOOLING_NO_XMLSEC + #include + using namespace xmlsignature; +#endif + using namespace xmltooling; using namespace std; -extern ParserPool* validatingPool; -extern ParserPool* nonvalidatingPool; extern string data_path; #if defined (_MSC_VER) @@ -42,15 +44,36 @@ extern string data_path; #pragma warning( disable : 4250 4251 ) #endif -class SimpleXMLObject : public AbstractXMLObjectMarshaller, public AbstractXMLObjectUnmarshaller +class SimpleXMLObject + : 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)) { +#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); + } + } + public: static const XMLCh NAMESPACE[]; static const XMLCh NAMESPACE_PREFIX[]; static const XMLCh LOCAL_NAME[]; + static const XMLCh DERIVED_NAME[]; + static const XMLCh TYPE_NAME[]; static const XMLCh ID_ATTRIB_NAME[]; - SimpleXMLObject() : AbstractDOMCachingXMLObject(NAMESPACE, LOCAL_NAME, NAMESPACE_PREFIX), m_id(NULL), m_value(NULL) { + SimpleXMLObject( + const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL + ) : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_id(NULL), m_value(NULL) { #ifndef XMLTOOLING_NO_XMLSEC m_children.push_back(NULL); m_signature=m_children.begin(); @@ -61,7 +84,18 @@ public: XMLString::release(&m_id); XMLString::release(&m_value); } - + + SimpleXMLObject* clone() const { + auto_ptr domClone(AbstractDOMCachingXMLObject::clone()); + SimpleXMLObject* ret=dynamic_cast(domClone.get()); + if (ret) { + domClone.release(); + return ret; + } + + return new SimpleXMLObject(*this); + } + const XMLCh* getId() const { return m_id; } void setId(const XMLCh* id) { m_id=prepareForAssignment(m_id,id); } @@ -82,22 +116,11 @@ public: return VectorOf(SimpleXMLObject)(this, m_simples, &m_children, m_children.end()); } - SimpleXMLObject* clone() const { - auto_ptr domClone(AbstractDOMCachingXMLObject::clone()); - SimpleXMLObject* ret=dynamic_cast(domClone.get()); - if (ret) { - domClone.release(); - return ret; - } - - ret=new SimpleXMLObject(); - ret->m_namespaces=m_namespaces; - ret->setId(m_id); - ret->setValue(m_value); - xmltooling::clone(m_children, ret->m_children); - return ret; + const std::vector& getSimpleXMLObjects() const { + return m_simples; } +protected: void marshallAttributes(DOMElement* domElement) const { if(getId()) { domElement->setAttributeNS(NULL, SimpleXMLObject::ID_ATTRIB_NAME, getId()); @@ -112,14 +135,21 @@ public: } void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { - if (XMLHelper::isNodeNamed(root, SimpleXMLObject::NAMESPACE, SimpleXMLObject::LOCAL_NAME)) - getSimpleXMLObjects().push_back(dynamic_cast(childXMLObject)); + SimpleXMLObject* simple=dynamic_cast(childXMLObject); + if (simple) { + getSimpleXMLObjects().push_back(simple); + return; + } + #ifndef XMLTOOLING_NO_XMLSEC - else if (XMLHelper::isNodeNamed(root, XMLConstants::XMLSIG_NS, Signature::LOCAL_NAME)) - setSignature(dynamic_cast(childXMLObject)); + Signature* sig=dynamic_cast(childXMLObject); + if (sig) { + setSignature(sig); + return; + } #endif - else - throw UnmarshallingException("Unknown child element cannot be added to parent object."); + + throw UnmarshallingException("Unknown child element cannot be added to parent object."); } void processAttribute(const DOMAttr* attribute) { @@ -146,86 +176,23 @@ class SimpleXMLObjectBuilder : public XMLObjectBuilder { public: SimpleXMLObject* buildObject() const { - return new SimpleXMLObject(); + return buildObject(SimpleXMLObject::NAMESPACE, SimpleXMLObject::LOCAL_NAME, SimpleXMLObject::NAMESPACE_PREFIX); } -}; -class WildcardXMLObject : public AbstractElementProxy, public AbstractAttributeExtensibleXMLObject, - public AbstractXMLObjectMarshaller, public AbstractXMLObjectUnmarshaller -{ -public: - WildcardXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix) - : AbstractDOMCachingXMLObject(nsURI, localName, prefix), - AbstractElementProxy(nsURI, localName, prefix), - AbstractAttributeExtensibleXMLObject(nsURI, localName, prefix) {} - virtual ~WildcardXMLObject() {} - - WildcardXMLObject* clone() const { - auto_ptr domClone(AbstractDOMCachingXMLObject::clone()); - WildcardXMLObject* ret=dynamic_cast(domClone.get()); - if (ret) { - domClone.release(); - return ret; - } - - ret=new WildcardXMLObject( - getElementQName().getNamespaceURI(),getElementQName().getLocalPart(),getElementQName().getPrefix() - ); - ret->m_namespaces=m_namespaces; - for (map::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) { - ret->m_attributeMap[i->first]=XMLString::replicate(i->second); - } - ret->setTextContent(getTextContent()); - xmltooling::clone(m_children, ret->m_children); - return ret; + SimpleXMLObject* buildObject( + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL + ) const { + return new SimpleXMLObject(nsURI, localName, prefix, schemaType); } - 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()); - attr->setNodeValue(i->second); - domElement->setAttributeNode(attr); - } - } - - void marshallElementContent(DOMElement* domElement) const { - if(getTextContent()) { - domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); - } - } - - void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { - getXMLObjects().push_back(childXMLObject); - } - - void processAttribute(const DOMAttr* attribute) { - QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); - setAttribute(q,attribute->getNodeValue()); - } - - void processElementContent(const XMLCh* elementContent) { - setTextContent(elementContent); - } -}; - -class WildcardXMLObjectBuilder : public XMLObjectBuilder -{ -public: - WildcardXMLObject* buildObject() const { - throw XMLObjectException("Default build operation is unsupported."); - } - - WildcardXMLObject* buildObject(const QName& q) const { - return new WildcardXMLObject(q.getNamespaceURI(),q.getLocalPart(),q.getPrefix()); - } - - WildcardXMLObject* buildFromElement(DOMElement* e, bool bindDocument=false) const { - auto_ptr ret(new WildcardXMLObject(e->getNamespaceURI(),e->getLocalName(),e->getPrefix())); - ret->unmarshall(e,bindDocument); - return ret.release(); - } + static SimpleXMLObject* newSimpleXMLObject() { + const SimpleXMLObjectBuilder* b = dynamic_cast( + XMLObjectBuilder::getBuilder(QName(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME)) + ); + if (b) + return b->buildObject(); + throw XMLObjectException("Unable to obtain typed builder for SimpleXMLObject."); + } }; #if defined (_MSC_VER)