From 2d4144a048a3f248b688e19e1e303d4ee7047090 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Wed, 19 Apr 2006 22:18:57 +0000 Subject: [PATCH] Added singleton methods on typed builders. --- xmltooling/base.h | 8 ++++++++ xmltooling/signature/Signature.h | 12 ++++++++++++ xmltoolingtest/MarshallingTest.h | 6 ++---- xmltoolingtest/SignatureTest.h | 3 +-- xmltoolingtest/XMLObjectBaseTestCase.h | 9 +++++++++ 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/xmltooling/base.h b/xmltooling/base.h index 7e7eefa..87e4361 100644 --- a/xmltooling/base.h +++ b/xmltooling/base.h @@ -487,6 +487,14 @@ */ #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \ BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \ + static cname* new##cname() { \ + const cname##Builder* b = dynamic_cast( \ + XMLObjectBuilder::getBuilder(xmltooling::QName(namespaceURI,cname::LOCAL_NAME)) \ + ); \ + if (b) \ + return b->buildObject(); \ + throw xmltooling::XMLObjectException("Unable to obtain typed builder for "#cname"."); \ + } \ END_XMLOBJECTBUILDER /** diff --git a/xmltooling/signature/Signature.h b/xmltooling/signature/Signature.h index 53bb10a..b4b6c3c 100644 --- a/xmltooling/signature/Signature.h +++ b/xmltooling/signature/Signature.h @@ -27,6 +27,7 @@ #include #include #include +#include /** * @namespace xmlsignature @@ -97,6 +98,17 @@ namespace xmlsignature { * @return empty Signature object */ virtual Signature* buildObject() const; + + static Signature* newSignature() { + const SignatureBuilder* b = dynamic_cast( + xmltooling::XMLObjectBuilder::getBuilder( + xmltooling::QName(xmltooling::XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME) + ) + ); + if (b) + return b->buildObject(); + throw xmltooling::XMLObjectException("Unable to obtain typed builder for Signature."); + } }; DECL_XMLTOOLING_EXCEPTION(SignatureException,xmlsignature,xmltooling::XMLToolingException,Exceptions in signature processing); diff --git a/xmltoolingtest/MarshallingTest.h b/xmltoolingtest/MarshallingTest.h index 8c0314d..55f6f73 100644 --- a/xmltoolingtest/MarshallingTest.h +++ b/xmltoolingtest/MarshallingTest.h @@ -38,8 +38,7 @@ public: TS_TRACE("testMarshallingWithAttributes"); QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME); - const SimpleXMLObjectBuilder* b=dynamic_cast(XMLObjectBuilder::getBuilder(qname)); - auto_ptr sxObject(b->buildObject()); + auto_ptr sxObject(SimpleXMLObjectBuilder::newSimpleXMLObject()); TS_ASSERT(sxObject.get()!=NULL); auto_ptr_XMLCh expected("Firefly"); sxObject->setId(expected.get()); @@ -59,8 +58,7 @@ public: TS_TRACE("testMarshallingWithElementContent"); QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME); - const SimpleXMLObjectBuilder* b=dynamic_cast(XMLObjectBuilder::getBuilder(qname)); - auto_ptr sxObject(b->buildObject()); + auto_ptr sxObject(SimpleXMLObjectBuilder::newSimpleXMLObject()); TS_ASSERT(sxObject.get()!=NULL); auto_ptr_XMLCh expected("Sample Content"); sxObject->setValue(expected.get()); diff --git a/xmltoolingtest/SignatureTest.h b/xmltoolingtest/SignatureTest.h index 70db6b0..be5c81f 100644 --- a/xmltoolingtest/SignatureTest.h +++ b/xmltoolingtest/SignatureTest.h @@ -119,8 +119,7 @@ public: kids[1]->setValue(bar.get()); // Append a Signature. - const SignatureBuilder* sigb=dynamic_cast(XMLObjectBuilder::getBuilder(QName(XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME))); - Signature* sig=sigb->buildObject(); + Signature* sig=SignatureBuilder::newSignature(); sxObject->setSignature(sig); // Signing context for the whole document. diff --git a/xmltoolingtest/XMLObjectBaseTestCase.h b/xmltoolingtest/XMLObjectBaseTestCase.h index 34af4eb..b0088f5 100644 --- a/xmltoolingtest/XMLObjectBaseTestCase.h +++ b/xmltoolingtest/XMLObjectBaseTestCase.h @@ -186,6 +186,15 @@ public: ) const { return new SimpleXMLObject(nsURI, localName, prefix, schemaType); } + + 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) -- 2.1.4