Added singleton methods on typed builders.
authorScott Cantor <cantor.2@osu.edu>
Wed, 19 Apr 2006 22:18:57 +0000 (22:18 +0000)
committerScott Cantor <cantor.2@osu.edu>
Wed, 19 Apr 2006 22:18:57 +0000 (22:18 +0000)
xmltooling/base.h
xmltooling/signature/Signature.h
xmltoolingtest/MarshallingTest.h
xmltoolingtest/SignatureTest.h
xmltoolingtest/XMLObjectBaseTestCase.h

index 7e7eefa..87e4361 100644 (file)
  */
  #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
     BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \
+    static cname* new##cname() { \
+        const cname##Builder* b = dynamic_cast<const cname##Builder*>( \
+            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
 
 /**
index 53bb10a..b4b6c3c 100644 (file)
@@ -27,6 +27,7 @@
 #include <xmltooling/XMLObjectBuilder.h>\r
 #include <xmltooling/signature/SigningContext.h>\r
 #include <xmltooling/signature/VerifyingContext.h>\r
+#include <xmltooling/util/XMLConstants.h>\r
 \r
 /**\r
  * @namespace xmlsignature\r
@@ -97,6 +98,17 @@ namespace xmlsignature {
          * @return empty Signature object\r
          */\r
         virtual Signature* buildObject() const;\r
+\r
+        static Signature* newSignature() {\r
+            const SignatureBuilder* b = dynamic_cast<const SignatureBuilder*>(\r
+                xmltooling::XMLObjectBuilder::getBuilder(\r
+                    xmltooling::QName(xmltooling::XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME)\r
+                    )\r
+                );\r
+            if (b)\r
+                return b->buildObject();\r
+            throw xmltooling::XMLObjectException("Unable to obtain typed builder for Signature.");\r
+        }\r
     };\r
 \r
     DECL_XMLTOOLING_EXCEPTION(SignatureException,xmlsignature,xmltooling::XMLToolingException,Exceptions in signature processing);\r
index 8c0314d..55f6f73 100644 (file)
@@ -38,8 +38,7 @@ public:
         TS_TRACE("testMarshallingWithAttributes");\r
 \r
         QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME);\r
-        const SimpleXMLObjectBuilder* b=dynamic_cast<const SimpleXMLObjectBuilder*>(XMLObjectBuilder::getBuilder(qname));\r
-        auto_ptr<SimpleXMLObject> sxObject(b->buildObject());\r
+        auto_ptr<SimpleXMLObject> sxObject(SimpleXMLObjectBuilder::newSimpleXMLObject());\r
         TS_ASSERT(sxObject.get()!=NULL);\r
         auto_ptr_XMLCh expected("Firefly");\r
         sxObject->setId(expected.get());\r
@@ -59,8 +58,7 @@ public:
         TS_TRACE("testMarshallingWithElementContent");\r
 \r
         QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME);\r
-        const SimpleXMLObjectBuilder* b=dynamic_cast<const SimpleXMLObjectBuilder*>(XMLObjectBuilder::getBuilder(qname));\r
-        auto_ptr<SimpleXMLObject> sxObject(b->buildObject());\r
+        auto_ptr<SimpleXMLObject> sxObject(SimpleXMLObjectBuilder::newSimpleXMLObject());\r
         TS_ASSERT(sxObject.get()!=NULL);\r
         auto_ptr_XMLCh expected("Sample Content");\r
         sxObject->setValue(expected.get());\r
index 70db6b0..be5c81f 100644 (file)
@@ -119,8 +119,7 @@ public:
         kids[1]->setValue(bar.get());\r
         \r
         // Append a Signature.\r
-        const SignatureBuilder* sigb=dynamic_cast<const SignatureBuilder*>(XMLObjectBuilder::getBuilder(QName(XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME)));\r
-        Signature* sig=sigb->buildObject();\r
+        Signature* sig=SignatureBuilder::newSignature();\r
         sxObject->setSignature(sig);\r
         \r
         // Signing context for the whole document.\r
index 34af4eb..b0088f5 100644 (file)
@@ -186,6 +186,15 @@ public:
         ) const {
         return new SimpleXMLObject(nsURI, localName, prefix, schemaType);
     }
+
+    static SimpleXMLObject* newSimpleXMLObject() {\r
+        const SimpleXMLObjectBuilder* b = dynamic_cast<const SimpleXMLObjectBuilder*>(\r
+            XMLObjectBuilder::getBuilder(QName(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME))\r
+            );\r
+        if (b)\r
+            return b->buildObject();\r
+        throw XMLObjectException("Unable to obtain typed builder for SimpleXMLObject.");\r
+    }\r
 };
 
 #if defined (_MSC_VER)