X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltoolingtest%2FXMLObjectBaseTestCase.h;h=99aa08f2c76512b9bd3c7ef8511214b3506e9c67;hb=bd026f07e729e66127b3efd48aee443fba815af3;hp=873f2275042943c610359af76e015f574057c66a;hpb=90b649c84f13dcfbebc2f15e43219401f222bcba;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltoolingtest/XMLObjectBaseTestCase.h b/xmltoolingtest/XMLObjectBaseTestCase.h index 873f227..99aa08f 100644 --- a/xmltoolingtest/XMLObjectBaseTestCase.h +++ b/xmltoolingtest/XMLObjectBaseTestCase.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005 Internet2 + * Copyright 2001-2007 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,26 +15,29 @@ */ #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 xercesc; using namespace std; -extern ParserPool* validatingPool; -extern ParserPool* nonvalidatingPool; extern string data_path; #if defined (_MSC_VER) @@ -42,15 +45,37 @@ 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), 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(dynamic_cast((*i)->clone())); + } + } + 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 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(); @@ -59,14 +84,25 @@ public: virtual ~SimpleXMLObject() { XMLString::release(&m_id); - XMLString::release(&m_value); } - + + XMLObject* 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* 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 { @@ -82,60 +118,49 @@ 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; } - void marshallAttributes(DOMElement* domElement) const { +protected: + 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 } } - void marshallElementContent(DOMElement* domElement) const { - if(getValue()) { - domElement->setTextContent(getValue()); + void processChildElement(XMLObject* childXMLObject, const xercesc::DOMElement* root) { + SimpleXMLObject* simple=dynamic_cast(childXMLObject); + if (simple) { + getSimpleXMLObjects().push_back(simple); + return; } - } - - void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { - if (XMLHelper::isNodeNamed(root, SimpleXMLObject::NAMESPACE, SimpleXMLObject::LOCAL_NAME)) - getSimpleXMLObjects().push_back(dynamic_cast(childXMLObject)); + #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) { + 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); - } - private: XMLCh* m_id; - XMLCh* m_value; vector m_simples; #ifndef XMLTOOLING_NO_XMLSEC list::iterator m_signature; @@ -145,86 +170,23 @@ private: class SimpleXMLObjectBuilder : public XMLObjectBuilder { public: - SimpleXMLObject* buildObject() const { - return new SimpleXMLObject(); - } -}; - -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; - } - - 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."); + XMLObject* buildObject() const { + return buildObject(SimpleXMLObject::NAMESPACE, SimpleXMLObject::LOCAL_NAME, SimpleXMLObject::NAMESPACE_PREFIX); } - WildcardXMLObject* buildObject(const QName& q) const { - return new WildcardXMLObject(q.getNamespaceURI(),q.getLocalPart(),q.getPrefix()); + XMLObject* buildObject( + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL + ) const { + return new SimpleXMLObject(nsURI, localName, prefix, schemaType); } - 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* 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."); } };