From c162396a9f005de0648b6e6598ff90b4d641deb1 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Wed, 29 Mar 2006 17:11:38 +0000 Subject: [PATCH] Set xsi:type during object construction. --- xmltooling/AbstractXMLObject.cpp | 10 +++++++--- xmltooling/AbstractXMLObject.h | 20 +++++++------------- xmltooling/XMLObject.h | 8 -------- xmltooling/XMLObjectBuilder.h | 16 ++++++++++------ xmltooling/base.h | 4 +++- xmltooling/impl/AnyElement.cpp | 8 ++++---- xmltooling/impl/AnyElement.h | 2 +- xmltooling/impl/UnknownElement.h | 4 ++-- xmltooling/io/AbstractXMLObjectUnmarshaller.cpp | 4 +--- xmltooling/signature/impl/KeyInfoImpl.cpp | 10 ++++++---- xmltooling/signature/impl/XMLSecSignatureImpl.cpp | 6 ++++-- xmltooling/signature/impl/XMLSecSignatureImpl.h | 4 +++- xmltoolingtest/MarshallingTest.h | 3 +-- xmltoolingtest/XMLObjectBaseTestCase.h | 8 ++++---- 14 files changed, 53 insertions(+), 54 deletions(-) diff --git a/xmltooling/AbstractXMLObject.cpp b/xmltooling/AbstractXMLObject.cpp index 4e0005b..cdba177 100644 --- a/xmltooling/AbstractXMLObject.cpp +++ b/xmltooling/AbstractXMLObject.cpp @@ -34,11 +34,15 @@ AbstractXMLObject::~AbstractXMLObject() { std::for_each(m_children.begin(), m_children.end(), cleanup()); } -AbstractXMLObject::AbstractXMLObject(const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix) - : m_elementQname(namespaceURI,elementLocalName, namespacePrefix), m_typeQname(NULL), m_parent(NULL), +AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) + : m_elementQname(nsURI, localName, prefix), m_typeQname(NULL), m_parent(NULL), m_log(&log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")) { - addNamespace(Namespace(namespaceURI, namespacePrefix)); + addNamespace(Namespace(nsURI, prefix)); + if (schemaType) { + m_typeQname = new QName(*schemaType); + addNamespace(Namespace(m_typeQname->getNamespaceURI(), m_typeQname->getPrefix())); + } } AbstractXMLObject::AbstractXMLObject(const AbstractXMLObject& src) diff --git a/xmltooling/AbstractXMLObject.h b/xmltooling/AbstractXMLObject.h index 6beecfd..7a4ff1f 100644 --- a/xmltooling/AbstractXMLObject.h +++ b/xmltooling/AbstractXMLObject.h @@ -62,15 +62,6 @@ namespace xmltooling { return m_typeQname; } - void setSchemaType(const QName* type) { - delete m_typeQname; - m_typeQname = NULL; - if (type) { - m_typeQname = new QName(*type); - addNamespace(Namespace(type->getNamespaceURI(), type->getPrefix())); - } - } - bool hasParent() const { return m_parent != NULL; } @@ -95,11 +86,14 @@ namespace xmltooling { /** * Constructor * - * @param namespaceURI the namespace the element is in - * @param elementLocalName the local name of the XML element this Object represents - * @param namespacePrefix the namespace prefix to use + * @param nsURI the namespace of the element + * @param localName the local name of the XML element this Object represents + * @param prefix the namespace prefix to use + * @param schemaType the xsi:type to use */ - AbstractXMLObject(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL); + AbstractXMLObject( + const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL + ); /** Copy constructor. */ AbstractXMLObject(const AbstractXMLObject& src); diff --git a/xmltooling/XMLObject.h b/xmltooling/XMLObject.h index 09e72c9..46157b8 100644 --- a/xmltooling/XMLObject.h +++ b/xmltooling/XMLObject.h @@ -133,14 +133,6 @@ namespace xmltooling { virtual const QName* getSchemaType() const=0; /** - * Sets the XML schema type of this element. This translates to contents the xsi:type - * attribute for the element. - * - * @param type XML schema type of this element - */ - virtual void setSchemaType(const QName* type)=0; - - /** * Checks to see if this object has a parent. * * @return true if the object has a parent, false if not diff --git a/xmltooling/XMLObjectBuilder.h b/xmltooling/XMLObjectBuilder.h index f78ae6d..25fcbb7 100644 --- a/xmltooling/XMLObjectBuilder.h +++ b/xmltooling/XMLObjectBuilder.h @@ -26,6 +26,7 @@ #include #include #include +#include #if defined (_MSC_VER) #pragma warning( push ) @@ -46,15 +47,16 @@ namespace xmltooling { /** * Creates an empty XMLObject with a particular element name. - * The results are undefined if elementLocalName is NULL or empty. + * The results are undefined if localName is NULL or empty. * - * @param namespaceURI namespace URI for element - * @param elementLocalName local name of element - * @param namespacePrefix prefix of element name + * @param nsURI namespace URI for element + * @param localName local name of element + * @param prefix prefix of element name + * @param schemaType xsi:type of the object * @return the empty XMLObject */ virtual XMLObject* buildObject( - const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix=NULL + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL ) const=0; /** @@ -75,7 +77,9 @@ namespace xmltooling { * @return the unmarshalled XMLObject */ XMLObject* buildFromElement(DOMElement* element, bool bindDocument=false) const { - std::auto_ptr ret(buildObject(element->getNamespaceURI(),element->getLocalName(),element->getPrefix())); + std::auto_ptr ret( + buildObject(element->getNamespaceURI(),element->getLocalName(),element->getPrefix(),XMLHelper::getXSIType(element)) + ); ret->unmarshall(element,bindDocument); return ret.release(); } diff --git a/xmltooling/base.h b/xmltooling/base.h index 9aa9bd9..d2060cb 100644 --- a/xmltooling/base.h +++ b/xmltooling/base.h @@ -186,7 +186,9 @@ #define BEGIN_XMLOBJECTBUILDERIMPL(cname,namespaceURI) \ class XMLTOOL_DLLLOCAL cname##BuilderImpl : public cname##Builder { \ public: \ - cname* buildObject(const XMLCh* ns, const XMLCh* name, const XMLCh* prefix=NULL) const; \ + cname* buildObject( \ + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL\ + ) const; \ cname* buildObject() const { \ return buildObject(namespaceURI,cname::LOCAL_NAME,cname::PREFIX); \ } diff --git a/xmltooling/impl/AnyElement.cpp b/xmltooling/impl/AnyElement.cpp index 8ed8a8d..9d26f51 100644 --- a/xmltooling/impl/AnyElement.cpp +++ b/xmltooling/impl/AnyElement.cpp @@ -54,8 +54,8 @@ namespace xmltooling { public: virtual ~AnyElementImpl() {} - AnyElementImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix) - : AbstractXMLObject(nsURI, localName, prefix) {} + AnyElementImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL) + : AbstractXMLObject(nsURI, localName, prefix, schemaType) {} AnyElementImpl* clone() const { auto_ptr domClone(AbstractDOMCachingXMLObject::clone()); @@ -114,7 +114,7 @@ namespace xmltooling { XMLObject* AnyElementBuilder::buildObject( - const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType ) const { - return new AnyElementImpl(namespaceURI,elementLocalName,namespacePrefix); + return new AnyElementImpl(nsURI, localName, prefix, schemaType); } diff --git a/xmltooling/impl/AnyElement.h b/xmltooling/impl/AnyElement.h index 27654a0..4bda237 100644 --- a/xmltooling/impl/AnyElement.h +++ b/xmltooling/impl/AnyElement.h @@ -36,7 +36,7 @@ namespace xmltooling { { public: XMLObject* buildObject( - const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix=NULL + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL ) const; }; diff --git a/xmltooling/impl/UnknownElement.h b/xmltooling/impl/UnknownElement.h index dd7f3be..4e2e03b 100644 --- a/xmltooling/impl/UnknownElement.h +++ b/xmltooling/impl/UnknownElement.h @@ -75,9 +75,9 @@ namespace xmltooling { { public: XMLObject* buildObject( - const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix=NULL + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL ) const { - return new UnknownElementImpl(namespaceURI,elementLocalName,namespacePrefix); + return new UnknownElementImpl(nsURI,localName,prefix); } }; diff --git a/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp b/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp index 12e0327..465b432 100644 --- a/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp +++ b/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp @@ -117,9 +117,7 @@ void AbstractXMLObjectUnmarshaller::unmarshallAttributes(const DOMElement* domEl } } else if (XMLString::equals(nsuri,XMLConstants::XSI_NS) && XMLString::equals(attribute->getLocalName(),type)) { - XT_log.debug("found xsi:type declaration, setting the schema type of the XMLObject"); - auto_ptr xsitype(XMLHelper::getAttributeValueAsQName(attribute)); - setSchemaType(xsitype.get()); + XT_log.debug("skipping xsi:type declaration"); continue; } else if (nsuri && !XMLString::equals(nsuri,XMLConstants::XML_NS)) { diff --git a/xmltooling/signature/impl/KeyInfoImpl.cpp b/xmltooling/signature/impl/KeyInfoImpl.cpp index d49d0ba..2d73ed8 100644 --- a/xmltooling/signature/impl/KeyInfoImpl.cpp +++ b/xmltooling/signature/impl/KeyInfoImpl.cpp @@ -49,8 +49,8 @@ namespace xmltooling { public: virtual ~KeyInfoImpl() {} - KeyInfoImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix) - : AbstractXMLObject(nsURI, localName, prefix), m_Id(NULL) {} + KeyInfoImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) + : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_Id(NULL) {} KeyInfoImpl(const KeyInfoImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractElementProxy(src), AbstractValidatingXMLObject(src), m_Id(XMLString::replicate(src.m_Id)) { @@ -96,7 +96,9 @@ namespace xmltooling { #pragma warning( pop ) #endif -KeyInfo* KeyInfoBuilderImpl::buildObject(const XMLCh* ns, const XMLCh* name, const XMLCh* prefix) const +KeyInfo* KeyInfoBuilderImpl::buildObject( + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType + ) const { - return new KeyInfoImpl(ns,name,prefix); + return new KeyInfoImpl(nsURI,localName,prefix,schemaType); } diff --git a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp index afb65d9..d320a3d 100644 --- a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp +++ b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp @@ -401,9 +401,11 @@ XMLObject* XMLSecSignatureImpl::unmarshall(DOMElement* element, bool bindDocumen return this; } -Signature* XMLSecSignatureBuilder::buildObject(const XMLCh* ns, const XMLCh* name, const XMLCh* prefix) const +Signature* XMLSecSignatureBuilder::buildObject( + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType + ) const { - if (!XMLString::equals(ns,XMLConstants::XMLSIG_NS) || !XMLString::equals(name,Signature::LOCAL_NAME)) + if (!XMLString::equals(nsURI,XMLConstants::XMLSIG_NS) || !XMLString::equals(localName,Signature::LOCAL_NAME)) throw XMLObjectException("XMLSecSignatureBuilder requires standard Signature element name."); return buildObject(); } diff --git a/xmltooling/signature/impl/XMLSecSignatureImpl.h b/xmltooling/signature/impl/XMLSecSignatureImpl.h index 6bcc4eb..41b2470 100644 --- a/xmltooling/signature/impl/XMLSecSignatureImpl.h +++ b/xmltooling/signature/impl/XMLSecSignatureImpl.h @@ -30,7 +30,9 @@ namespace xmltooling { class XMLTOOL_DLLLOCAL XMLSecSignatureBuilder : public SignatureBuilder { public: - Signature* buildObject(const XMLCh* ns, const XMLCh* name, const XMLCh* prefix=NULL) const; + Signature* buildObject( + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL + ) const; Signature* buildObject() const; }; diff --git a/xmltoolingtest/MarshallingTest.h b/xmltoolingtest/MarshallingTest.h index af687e3..a5f5091 100644 --- a/xmltoolingtest/MarshallingTest.h +++ b/xmltoolingtest/MarshallingTest.h @@ -95,8 +95,7 @@ public: kids.erase(kids.begin()+1); TS_ASSERT_SAME_DATA(kids.back()->getValue(), bar.get(), XMLString::stringLen(bar.get())); - kids.push_back(b->buildObject(SimpleXMLObject::NAMESPACE,SimpleXMLObject::DERIVED_NAME,SimpleXMLObject::NAMESPACE_PREFIX)); - kids.back()->setSchemaType(&m_qtype); + kids.push_back(b->buildObject(SimpleXMLObject::NAMESPACE,SimpleXMLObject::DERIVED_NAME,SimpleXMLObject::NAMESPACE_PREFIX,&m_qtype)); kids.back()->setValue(baz.get()); DOMElement* rootElement = sxObject->marshall(); diff --git a/xmltoolingtest/XMLObjectBaseTestCase.h b/xmltoolingtest/XMLObjectBaseTestCase.h index f74e9a5..ba1116f 100644 --- a/xmltoolingtest/XMLObjectBaseTestCase.h +++ b/xmltoolingtest/XMLObjectBaseTestCase.h @@ -67,8 +67,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 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(); @@ -171,9 +171,9 @@ public: } SimpleXMLObject* buildObject( - const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix=NULL + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL ) const { - return new SimpleXMLObject(namespaceURI,elementLocalName,namespacePrefix); + return new SimpleXMLObject(nsURI, localName, prefix, schemaType); } }; -- 2.1.4