Set fourth file version digit to signify rebuild.
[shibboleth/cpp-xmltooling.git] / xmltooling / XMLObjectBuilder.h
index ef54e17..bb0b3ef 100644 (file)
-/*\r
- *  Copyright 2001-2007 Internet2\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/**\r
- * @file xmltooling/XMLObjectBuilder.h\r
- * \r
- * Factory interface for XMLObjects.\r
- */\r
-\r
-#ifndef __xmltooling_xmlobjbuilder_h__\r
-#define __xmltooling_xmlobjbuilder_h__\r
-\r
-#include <map>\r
-#include <memory>\r
-#include <xmltooling/QName.h>\r
-#include <xmltooling/XMLObject.h>\r
-#include <xmltooling/util/XMLHelper.h>\r
-\r
-#if defined (_MSC_VER)\r
-    #pragma warning( push )\r
-    #pragma warning( disable : 4250 4251 )\r
-#endif\r
-\r
-namespace xmltooling {\r
-\r
-    /**\r
-     * A factory interface for obtaining XMLObjects.\r
-     * Subclasses MAY supply additional factory methods.\r
-     */\r
-    class XMLTOOL_API XMLObjectBuilder\r
-    {\r
-    MAKE_NONCOPYABLE(XMLObjectBuilder);\r
-    public:\r
-        virtual ~XMLObjectBuilder() {}\r
-        \r
-        /**\r
-         * Creates an empty XMLObject with a particular element name.\r
-         * <p>The results are undefined if localName is NULL or empty.\r
-         * \r
-         * @param nsURI         namespace URI for element\r
-         * @param localName     local name of element\r
-         * @param prefix        prefix of element name\r
-         * @param schemaType    xsi:type of the object\r
-         * @return the empty XMLObject\r
-         */\r
-        virtual XMLObject* buildObject(\r
-            const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL\r
-            ) const=0;\r
-\r
-        /**\r
-         * Creates an empty XMLObject with a particular element name.\r
-         * \r
-         * @param q     QName of element for object\r
-         * @return the empty XMLObject\r
-         */\r
-        XMLObject* buildFromQName(const QName& q) const {\r
-            return buildObject(q.getNamespaceURI(),q.getLocalPart(),q.getPrefix());\r
-        }\r
-\r
-        /**\r
-         * Creates an unmarshalled XMLObject from a DOM Element.\r
-         * \r
-         * @param element       the unmarshalling source\r
-         * @param bindDocument  true iff the XMLObject should take ownership of the DOM Document\r
-         * @return the unmarshalled XMLObject\r
-         */\r
-        XMLObject* buildFromElement(xercesc::DOMElement* element, bool bindDocument=false) const {\r
-            std::auto_ptr<XMLObject> ret(\r
-                buildObject(element->getNamespaceURI(),element->getLocalName(),element->getPrefix(),XMLHelper::getXSIType(element))\r
-                );\r
-            ret->unmarshall(element,bindDocument);\r
-            return ret.release();\r
-        }\r
-\r
-        /**\r
-         * Creates an unmarshalled XMLObject from the root of a DOM Document.\r
-         * \r
-         * @param doc           the unmarshalling source\r
-         * @param bindDocument  true iff the XMLObject should take ownership of the DOM Document\r
-         * @return the unmarshalled XMLObject\r
-         */\r
-        XMLObject* buildFromDocument(xercesc::DOMDocument* doc, bool bindDocument=true) const {\r
-            return buildFromElement(doc->getDocumentElement(),bindDocument);\r
-        }\r
-\r
-        /**\r
-         * Creates an unmarshalled XMLObject using the default build method, if a builder can be found.\r
-         * \r
-         * @param element       the unmarshalling source\r
-         * @param bindDocument  true iff the new XMLObject should take ownership of the DOM Document\r
-         * @return  the unmarshalled object or NULL if no builder is available \r
-         */\r
-        static XMLObject* buildOneFromElement(xercesc::DOMElement* element, bool bindDocument=false) {\r
-            const XMLObjectBuilder* b=getBuilder(element);\r
-            return b ? b->buildFromElement(element,bindDocument) : NULL;\r
-        }\r
-\r
-        /**\r
-         * Retrieves an XMLObjectBuilder using the key it was registered with.\r
-         * \r
-         * @param key the key used to register the builder\r
-         * @return the builder or NULL\r
-         */\r
-        static const XMLObjectBuilder* getBuilder(const QName& key) {\r
-            std::map<QName,XMLObjectBuilder*>::const_iterator i=m_map.find(key);\r
-            return (i==m_map.end()) ? NULL : i->second;\r
-        }\r
-\r
-        /**\r
-         * Retrieves an XMLObjectBuilder for a given DOM element.\r
-         * If no match is found, the default builder is returned, if any.\r
-         * \r
-         * @param element the element for which to locate a builder\r
-         * @return the builder or NULL\r
-         */\r
-        static const XMLObjectBuilder* getBuilder(const xercesc::DOMElement* element);\r
-\r
-        /**\r
-         * Retrieves the default XMLObjectBuilder for DOM elements\r
-         * \r
-         * @return the default builder or NULL\r
-         */\r
-        static const XMLObjectBuilder* getDefaultBuilder() {\r
-            return m_default;\r
-        }\r
-\r
-        /**\r
-         * Gets an immutable list of all the builders currently registered.\r
-         * \r
-         * @return list of all the builders currently registered\r
-         */\r
-        static const std::map<QName,XMLObjectBuilder*>& getBuilders() {\r
-            return m_map;\r
-        }\r
-    \r
-        /**\r
-         * Registers a new builder for the given key.\r
-         * \r
-         * @param builderKey the key used to retrieve this builder later\r
-         * @param builder the builder\r
-         */\r
-        static void registerBuilder(const QName& builderKey, XMLObjectBuilder* builder) {\r
-            deregisterBuilder(builderKey);\r
-            m_map[builderKey]=builder;\r
-        }\r
-\r
-        /**\r
-         * Registers a default builder\r
-         * \r
-         * @param builder the default builder\r
-         */\r
-        static void registerDefaultBuilder(XMLObjectBuilder* builder) {\r
-            deregisterDefaultBuilder();\r
-            m_default=builder;\r
-        }\r
-\r
-        /**\r
-         * Deregisters a builder.\r
-         * \r
-         * @param builderKey the key for the builder to be deregistered\r
-         */\r
-        static void deregisterBuilder(const QName& builderKey) {\r
-            delete getBuilder(builderKey);\r
-            m_map.erase(builderKey);\r
-        }\r
-\r
-        /**\r
-         * Deregisters default builder.\r
-         */\r
-        static void deregisterDefaultBuilder() {\r
-            delete m_default;\r
-            m_default=NULL;\r
-        }\r
-\r
-        /**\r
-         * Unregisters and destroys all registered builders. \r
-         */\r
-        static void destroyBuilders();\r
-\r
-    protected:\r
-        XMLObjectBuilder() {}\r
-    \r
-    private:\r
-        static std::map<QName,XMLObjectBuilder*> m_map;\r
-        static XMLObjectBuilder* m_default;\r
-    };\r
-\r
-};\r
-\r
-#if defined (_MSC_VER)\r
-    #pragma warning( pop )\r
-#endif\r
-\r
-#endif /* __xmltooling_xmlobjbuilder_h__ */\r
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
+ *
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+
+/**
+ * @file xmltooling/XMLObjectBuilder.h
+ * 
+ * Factory interface for XMLObjects.
+ */
+
+#ifndef __xmltooling_xmlobjbuilder_h__
+#define __xmltooling_xmlobjbuilder_h__
+
+#include <xmltooling/QName.h>
+#include <xmltooling/XMLObject.h>
+#include <xmltooling/util/XMLHelper.h>
+
+#include <map>
+#include <memory>
+
+#if defined (_MSC_VER)
+    #pragma warning( push )
+    #pragma warning( disable : 4250 4251 )
+#endif
+
+namespace xmltooling {
+
+    /**
+     * A factory interface for obtaining an XMLObject.
+     */
+    class XMLTOOL_API XMLObjectBuilder
+    {
+    MAKE_NONCOPYABLE(XMLObjectBuilder);
+    public:
+        virtual ~XMLObjectBuilder();
+        
+        /**
+         * Creates an empty XMLObject with a particular element name.
+         * <p>The results are undefined if localName is nullptr or empty.
+         * <p>The caller is responsible for freeing the resulting object.
+         * 
+         * @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* nsURI, const XMLCh* localName, const XMLCh* prefix=nullptr, const QName* schemaType=nullptr
+            ) const=0;
+
+        /**
+         * Creates an empty XMLObject with a particular element name.
+         * <p>The caller is responsible for freeing the resulting object.
+         * 
+         * @param q     QName of element for object
+         * @return the empty XMLObject
+         */
+        XMLObject* buildFromQName(const QName& q) const;
+
+        /**
+         * Creates an unmarshalled XMLObject from a DOM Element.
+         * <p>The caller is responsible for freeing the resulting object.
+         * 
+         * @param element       the unmarshalling source
+         * @param bindDocument  true iff the XMLObject should take ownership of the DOM Document
+         * @return the unmarshalled XMLObject
+         */
+        XMLObject* buildFromElement(xercesc::DOMElement* element, bool bindDocument=false) const;
+
+        /**
+         * Creates an unmarshalled XMLObject from the root of a DOM Document.
+         * <p>The caller is responsible for freeing the resulting object.
+         * 
+         * @param doc           the unmarshalling source
+         * @param bindDocument  true iff the XMLObject should take ownership of the DOM Document
+         * @return the unmarshalled XMLObject
+         */
+        XMLObject* buildFromDocument(xercesc::DOMDocument* doc, bool bindDocument=true) const;
+
+        /**
+         * Creates an unmarshalled XMLObject using the default build method, if a builder can be found.
+         * <p>The caller is responsible for freeing the resulting object.
+         * 
+         * @param element       the unmarshalling source
+         * @param bindDocument  true iff the new XMLObject should take ownership of the DOM Document
+         * @return  the unmarshalled object or nullptr if no builder is available 
+         */
+        static XMLObject* buildOneFromElement(xercesc::DOMElement* element, bool bindDocument=false);
+
+        /**
+         * Retrieves an XMLObjectBuilder using the key it was registered with.
+         * 
+         * @param key the key used to register the builder
+         * @return the builder or nullptr
+         */
+        static const XMLObjectBuilder* getBuilder(const QName& key);
+
+        /**
+         * Retrieves an XMLObjectBuilder for a given DOM element.
+         * If no match is found, the default builder is returned, if any.
+         * 
+         * @param element the element for which to locate a builder
+         * @return the builder or nullptr
+         */
+        static const XMLObjectBuilder* getBuilder(const xercesc::DOMElement* element);
+
+        /**
+         * Retrieves the default XMLObjectBuilder for DOM elements
+         * 
+         * @return the default builder or nullptr
+         */
+        static const XMLObjectBuilder* getDefaultBuilder();
+
+        /**
+         * Gets an immutable list of all the builders currently registered.
+         * 
+         * @return list of all the builders currently registered
+         */
+        static const std::map<QName,XMLObjectBuilder*>& getBuilders();
+    
+        /**
+         * Registers a new builder for the given key.
+         * 
+         * @param builderKey the key used to retrieve this builder later
+         * @param builder the builder
+         */
+        static void registerBuilder(const QName& builderKey, XMLObjectBuilder* builder);
+
+        /**
+         * Registers a default builder
+         * 
+         * @param builder the default builder
+         */
+        static void registerDefaultBuilder(XMLObjectBuilder* builder);
+
+        /**
+         * Deregisters a builder.
+         * 
+         * @param builderKey the key for the builder to be deregistered
+         */
+        static void deregisterBuilder(const QName& builderKey);
+
+        /**
+         * Deregisters default builder.
+         */
+        static void deregisterDefaultBuilder();
+
+        /**
+         * Unregisters and destroys all registered builders. 
+         */
+        static void destroyBuilders();
+
+    protected:
+        XMLObjectBuilder();
+    
+    private:
+        static std::map<QName,XMLObjectBuilder*> m_map;
+        static XMLObjectBuilder* m_default;
+    };
+
+};
+
+#if defined (_MSC_VER)
+    #pragma warning( pop )
+#endif
+
+#endif /* __xmltooling_xmlobjbuilder_h__ */