xmltooling::AbstractDOMCachingXMLObject(src) {} \
IMPL_XMLOBJECT_CLONE(cname) \
}
-
+
+#ifdef HAVE_COVARIANT_RETURNS
+
/**
* Begins the declaration of an XMLObjectBuilder specialization.
* Basic boilerplate includes an empty virtual destructor, and
return new cname##Impl(nsURI,localName,prefix,schemaType); \
}
+#else /* !HAVE_COVARIANT_RETURNS */\r
+
+/**
+ * Begins the declaration of an XMLObjectBuilder specialization.
+ * Basic boilerplate includes an empty virtual destructor, and
+ * a default builder that defaults the element name.
+ *
+ * @param linkage linkage specifier for the class
+ * @param cname the name of the XMLObject specialization
+ * @param namespaceURI the XML namespace of the default associated element
+ * @param namespacePrefix the XML namespace prefix of the default associated element
+ */
+#define BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
+ XMLTOOLING_DOXYGEN(Builder for cname objects.) \
+ class linkage cname##Builder : public xmltooling::XMLObjectBuilder { \
+ public: \
+ virtual ~cname##Builder() {} \
+ XMLTOOLING_DOXYGEN(Default builder.) \
+ virtual xmltooling::XMLObject* buildObject() const { \
+ return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \
+ } \
+ XMLTOOLING_DOXYGEN(Builder that allows element/type override.) \
+ virtual xmltooling::XMLObject* buildObject( \
+ const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL \
+ ) const
+
+/**
+ * Ends the declaration of an XMLObjectBuilder specialization.
+ */
+#define END_XMLOBJECTBUILDER }
+
+/**
+ * Declares a generic XMLObjectBuilder specialization.
+ *
+ * @param linkage linkage specifier for the class
+ * @param cname the name of the XMLObject specialization
+ * @param namespaceURI the XML namespace of the default associated element
+ * @param namespacePrefix the XML namespace prefix of the default associated element
+ */
+ #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
+ BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \
+ XMLTOOLING_DOXYGEN(Singleton builder.) \
+ static cname* build##cname() { \
+ const cname##Builder* b = dynamic_cast<const cname##Builder*>( \
+ XMLObjectBuilder::getBuilder(xmltooling::QName(namespaceURI,cname::LOCAL_NAME)) \
+ ); \
+ if (b) \
+ return dynamic_cast<cname*>(b->buildObject()); \
+ throw xmltooling::XMLObjectException("Unable to obtain typed builder for "#cname"."); \
+ } \
+ END_XMLOBJECTBUILDER
+
+/**
+ * Implements the standard XMLObjectBuilder specialization function.
+ *
+ * @param cname the name of the XMLObject specialization
+ */
+#define IMPL_XMLOBJECTBUILDER(cname) \
+ xmltooling::XMLObject* cname##Builder::buildObject( \
+ const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \
+ ) const \
+ { \
+ return new cname##Impl(nsURI,localName,prefix,schemaType); \
+ }
+
+#endif /* HAVE_COVARIANT_RETURNS */
+
/**
* Begins the declaration of a Schema Validator specialization.
*
+/* Define if C++ compiler supports covariant virtual methods. */
+#undef HAVE_COVARIANT_RETURNS
+
/* Define to 1 if you have an STL implementation that supports useful string
specialization. */
#undef HAVE_GOOD_STL
+/* Define if C++ compiler supports covariant virtual methods. */
+#define HAVE_COVARIANT_RETURNS 1
+
/* Define to 1 if you have an STL implementation that supports useful string
specialization. */
#define HAVE_GOOD_STL 1
*
* @return empty Signature object
*/
+#ifdef HAVE_COVARIANT_RETURNS
virtual Signature* buildObject() const;
-
+#else
+ virtual xmltooling::XMLObject* buildObject() const;
+#endif
static Signature* buildSignature() {
const SignatureBuilder* b = dynamic_cast<const SignatureBuilder*>(
xmltooling::XMLObjectBuilder::getBuilder(
xmltooling::QName(xmlconstants::XMLSIG_NS,Signature::LOCAL_NAME)
)
);
- if (b)
+ if (b) {
+#ifdef HAVE_COVARIANT_RETURNS
return b->buildObject();
+#else
+ return dynamic_cast<Signature*>(b->buildObject());
+#endif
+ }
throw xmltooling::XMLObjectException("Unable to obtain typed builder for Signature.");
}
};
return buildObject();
}
-Signature* SignatureBuilder::buildObject() const
+#ifdef HAVE_COVARIANT_RETURNS
+Signature*
+#else
+XMLObject*
+#endif
+SignatureBuilder::buildObject() const
{
return new XMLSecSignatureImpl();
}
void testMarshallingWithAttributes() {
QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME);
- auto_ptr<SimpleXMLObject> sxObject(SimpleXMLObjectBuilder::newSimpleXMLObject());
+ auto_ptr<SimpleXMLObject> sxObject(SimpleXMLObjectBuilder::buildSimpleXMLObject());
TS_ASSERT(sxObject.get()!=NULL);
auto_ptr_XMLCh expected("Firefly");
sxObject->setId(expected.get());
void testMarshallingWithElementContent() {
QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME);
- auto_ptr<SimpleXMLObject> sxObject(SimpleXMLObjectBuilder::newSimpleXMLObject());
+ auto_ptr<SimpleXMLObject> sxObject(SimpleXMLObjectBuilder::buildSimpleXMLObject());
TS_ASSERT(sxObject.get()!=NULL);
auto_ptr_XMLCh expected("Sample Content");
sxObject->setValue(expected.get());
const SimpleXMLObjectBuilder* b=dynamic_cast<const SimpleXMLObjectBuilder*>(XMLObjectBuilder::getBuilder(qname));
TS_ASSERT(b!=NULL);
- auto_ptr<SimpleXMLObject> sxObject(b->buildObject());
+ auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
TS_ASSERT(sxObject.get()!=NULL);
VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects();
- kids.push_back(b->buildObject());
- kids.push_back(b->buildObject());
- kids.push_back(b->buildObject());
+ kids.push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
+ kids.push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
+ kids.push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
// Test some collection stuff
auto_ptr_XMLCh foo("Foo");
QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME,SimpleXMLObject::NAMESPACE_PREFIX);
kids.push_back(
- b->buildObject(SimpleXMLObject::NAMESPACE,SimpleXMLObject::DERIVED_NAME,SimpleXMLObject::NAMESPACE_PREFIX,&qtype)
+ dynamic_cast<SimpleXMLObject*>(
+ b->buildObject(SimpleXMLObject::NAMESPACE,SimpleXMLObject::DERIVED_NAME,SimpleXMLObject::NAMESPACE_PREFIX,&qtype)
+ )
);
kids.back()->setValue(baz.get());
const SimpleXMLObjectBuilder* b=dynamic_cast<const SimpleXMLObjectBuilder*>(XMLObjectBuilder::getBuilder(qname));
TS_ASSERT(b!=NULL);
- auto_ptr<SimpleXMLObject> sxObject(b->buildObject());
+ auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
TS_ASSERT(sxObject.get()!=NULL);
VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects();
- kids.push_back(b->buildObject());
- kids.push_back(b->buildObject());
+ kids.push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
+ kids.push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
// Test some collection stuff
auto_ptr_XMLCh foo("Foo");
TS_ASSERT(sxObject.get()!=NULL);
sxObject->releaseThisAndChildrenDOM();
- auto_ptr<SimpleXMLObject> clonedObject(sxObject->clone());
+ auto_ptr<SimpleXMLObject> clonedObject(dynamic_cast<SimpleXMLObject*>(sxObject->clone()));
VectorOf(SimpleXMLObject) kids=clonedObject->getSimpleXMLObjects();
TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, kids.size());
#endif
VectorOf(SimpleXMLObject) mine=getSimpleXMLObjects();
for (vector<SimpleXMLObject*>::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<SimpleXMLObject*>((*i)->clone()));
}
}
XMLString::release(&m_id);
}
- SimpleXMLObject* clone() const {
+ XMLObject* clone() const {
auto_ptr<XMLObject> domClone(AbstractDOMCachingXMLObject::clone());
SimpleXMLObject* ret=dynamic_cast<SimpleXMLObject*>(domClone.get());
if (ret) {
class SimpleXMLObjectBuilder : public XMLObjectBuilder
{
public:
- SimpleXMLObject* buildObject() const {
+ XMLObject* buildObject() const {
return buildObject(SimpleXMLObject::NAMESPACE, SimpleXMLObject::LOCAL_NAME, SimpleXMLObject::NAMESPACE_PREFIX);
}
- SimpleXMLObject* buildObject(
+ XMLObject* buildObject(
const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL
) const {
return new SimpleXMLObject(nsURI, localName, prefix, schemaType);
}
- static SimpleXMLObject* newSimpleXMLObject() {
+ static SimpleXMLObject* buildSimpleXMLObject() {
const SimpleXMLObjectBuilder* b = dynamic_cast<const SimpleXMLObjectBuilder*>(
XMLObjectBuilder::getBuilder(QName(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME))
);
if (b)
- return b->buildObject();
+ return dynamic_cast<SimpleXMLObject*>(b->buildObject());
throw XMLObjectException("Unable to obtain typed builder for SimpleXMLObject.");
}
};