--- /dev/null
+/*\r
+ * Copyright 2001-2006 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 ILockable.h\r
+ * \r
+ * Locking abstraction \r
+ */\r
+\r
+#if !defined(__xmltooling_lockable_h__)\r
+#define __xmltooling_lockable_h__\r
+\r
+#include <xmltooling/base.h>\r
+\r
+namespace xmltooling {\r
+\r
+ /**\r
+ * Singleton object that manages library startup/shutdown.configuration.\r
+ */\r
+ struct XMLTOOL_API ILockable\r
+ {\r
+ virtual ~ILockable() {}\r
+ \r
+ /**\r
+ * Lock the associated object for exclusive access.\r
+ * \r
+ * @return a reference to the object being locked\r
+ */\r
+ virtual ILockable& lock()=0;\r
+\r
+ /**\r
+ * Unlock the associated object from exclusive access.\r
+ */\r
+ virtual void unlock()=0;\r
+ };\r
+\r
+ /**\r
+ * RAII wrapper for lockable objects to ensure lock release\r
+ */\r
+ class XMLTOOL_API Locker\r
+ {\r
+ MAKE_NONCOPYABLE(Locker);\r
+ public:\r
+ /**\r
+ * Locks an object and stores it for later release.\r
+ * \r
+ * @param lockee Pointer to an object to lock and hold\r
+ */\r
+ Locker(ILockable* lockee) : m_lockee(lockee->lock()) {}\r
+ \r
+ /**\r
+ * Locks an object and stores it for later release.\r
+ * \r
+ * @param lockee Reference to an object to lock and hold\r
+ */\r
+ Locker(ILockable& lockee) : m_lockee(lockee.lock()) {}\r
+\r
+ /**\r
+ * Releases lock on held pointer, if any.\r
+ */\r
+ ~Locker() {m_lockee.unlock();}\r
+ private:\r
+ ILockable& m_lockee;\r
+ };\r
+\r
+};\r
+\r
+#endif /* __xmltooling_lockable_h__ */\r
* limitations under the License.\r
*/\r
\r
-/* Namespace.cpp\r
+/**\r
+ * @file Namespace.cpp\r
* \r
- * Data structure for representing XML namespace attributes \r
- * \r
- * $Id:$\r
+ * Representing XML namespace attributes \r
*/\r
\r
#include "internal.h"\r
-#include "unicode.h"\r
#include "Namespace.h"\r
\r
-using namespace std;\r
using namespace xmltooling;\r
\r
-Namespace::Namespace()\r
+Namespace::Namespace(const XMLCh* uri, const XMLCh* prefix)\r
{\r
#ifndef HAVE_GOOD_STL\r
m_uri=m_prefix=NULL;\r
#endif\r
-}\r
-\r
-Namespace::Namespace(const XMLCh* uri, const XMLCh* prefix)\r
-{\r
setNamespaceURI(uri);\r
setNamespacePrefix(prefix);\r
}\r
#if !defined(__xmltooling_namespace_h__)\r
#define __xmltooling_namespace_h__\r
\r
-#include <string>\r
-#include <xmltooling/Namespace.h>\r
+#include <xmltooling/unicode.h>\r
\r
namespace xmltooling {\r
\r
{\r
public:\r
/**\r
- * Default constructor\r
- */\r
- Namespace();\r
- \r
- /**\r
- * Constructor that takes an existing declaration\r
+ * Constructor\r
* @param uri namespace URI\r
* @param prefix namespace prefix (without the colon)\r
*/\r
- Namespace(const XMLCh* uri, const XMLCh* prefix);\r
+ Namespace(const XMLCh* uri=NULL, const XMLCh* prefix=NULL);\r
\r
~Namespace();\r
#ifndef HAVE_GOOD_STL\r
/**\r
* Deep copy constructor\r
*/\r
- Namespace(const Namespace&);\r
+ Namespace(const Namespace& src);\r
\r
/**\r
* Deep assignment operator\r
*/\r
- Namespace& operator=(const Namespace&);\r
+ Namespace& operator=(const Namespace& src);\r
#endif\r
\r
#ifdef HAVE_GOOD_STL\r
--- /dev/null
+/*\r
+ * Copyright 2001-2006 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 QName.cpp\r
+ * \r
+ * Representing XML QNames \r
+ */\r
+\r
+#include "internal.h"\r
+#include "QName.h"\r
+\r
+using namespace xmltooling;\r
+\r
+QName::QName(const XMLCh* uri, const XMLCh* localPart, const XMLCh* prefix)\r
+{\r
+#ifndef HAVE_GOOD_STL\r
+ m_uri=m_prefix=m_local=NULL;\r
+#endif\r
+ setNamespaceURI(uri);\r
+ setLocalPart(localPart);\r
+ setPrefix(prefix);\r
+}\r
+\r
+QName::~QName()\r
+{\r
+#ifndef HAVE_GOOD_STL\r
+ XMLString::release(&m_uri);\r
+ XMLString::release(&m_prefix);\r
+ XMLString::release(&m_local);\r
+#endif\r
+}\r
+\r
+void QName::setPrefix(const XMLCh* prefix)\r
+{\r
+#ifdef HAVE_GOOD_STL\r
+ if (prefix)\r
+ m_prefix=prefix;\r
+ else\r
+ m_prefix.erase();\r
+#else\r
+ if (m_prefix)\r
+ XMLString::release(&m_prefix);\r
+ m_prefix=XMLString::replicate(prefix);\r
+#endif\r
+}\r
+\r
+void QName::setNamespaceURI(const XMLCh* uri)\r
+{\r
+#ifdef HAVE_GOOD_STL\r
+ if (uri)\r
+ m_uri=uri;\r
+ else\r
+ m_uri.erase();\r
+#else\r
+ if (m_uri)\r
+ XMLString::release(&m_uri);\r
+ m_uri=XMLString::replicate(uri);\r
+#endif\r
+}\r
+\r
+void QName::setLocalPart(const XMLCh* localPart)\r
+{\r
+#ifdef HAVE_GOOD_STL\r
+ if (localPart)\r
+ m_local=localPart;\r
+ else\r
+ m_local.erase();\r
+#else\r
+ if (m_local)\r
+ XMLString::release(&m_local);\r
+ m_local=XMLString::replicate(localPart);\r
+#endif\r
+}\r
+\r
+#ifndef HAVE_GOOD_STL\r
+QName::QName(const QName& src)\r
+{\r
+ m_uri=XMLString::replicate(src.getNamespaceURI());\r
+ m_prefix=XMLString::replicate(src.getPrefix());\r
+ m_local=XMLString::replicate(src.getLocalPart());\r
+}\r
+\r
+QName& QName::operator=(const QName& src)\r
+{\r
+ m_uri=XMLString::replicate(src.getNamespaceURI());\r
+ m_prefix=XMLString::replicate(src.getPrefix());\r
+ m_local=XMLString::replicate(src.getLocalPart());\r
+ return *this;\r
+}\r
+\r
+bool xmltooling::operator==(const QName& op1, const QName& op2)\r
+{\r
+ return (!XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI()) &&\r
+ !XMLString::compareString(op1.getLocalPart(),op2.getLocalPart()));\r
+}\r
+#endif\r
+\r
+bool xmltooling::operator<(const QName& op1, const QName& op2)\r
+{\r
+ int i=XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI());\r
+ if (i<0)\r
+ return true;\r
+ else if (i==0)\r
+ return (XMLString::compareString(op1.getLocalPart(),op2.getLocalPart())<0);\r
+ else\r
+ return false;\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2001-2006 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 QName.h\r
+ * \r
+ * Representing XML QNames \r
+ */\r
+\r
+#if !defined(__xmltooling_qname_h__)\r
+#define __xmltooling_qname_h__\r
+\r
+#include <algorithm>\r
+#include <xmltooling/unicode.h>\r
+\r
+namespace xmltooling {\r
+ \r
+ /**\r
+ * A data structure for encapsulating XML QNames.\r
+ * The Xerces class is too limited to use at the moment.\r
+ */\r
+ class XMLTOOL_API QName\r
+ {\r
+ public:\r
+ /**\r
+ * Constructor\r
+ * @param uri namespace URI\r
+ * @param localPart local name\r
+ * @param prefix namespace prefix (without the colon)\r
+ */\r
+ QName(const XMLCh* uri=NULL, const XMLCh* localPart=NULL, const XMLCh* prefix=NULL);\r
+ \r
+ ~QName();\r
+#ifndef HAVE_GOOD_STL\r
+ /**\r
+ * Deep copy constructor\r
+ */\r
+ QName(const QName& src);\r
+\r
+ /**\r
+ * Deep assignment operator\r
+ */\r
+ QName& operator=(const QName& src);\r
+#endif\r
+ \r
+#ifdef HAVE_GOOD_STL\r
+ /**\r
+ * Returns the namespace prefix\r
+ * @return Null-terminated Unicode string containing the prefix, without the colon\r
+ */\r
+ const XMLCh* getPrefix() const { return m_prefix.c_str(); }\r
+\r
+ /**\r
+ * Returns the namespace URI\r
+ * @return Null-terminated Unicode string containing the URI\r
+ */\r
+ const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }\r
+\r
+ /**\r
+ * Returns the local part of the name\r
+ * @return Null-terminated Unicode string containing the local name\r
+ */\r
+ const XMLCh* getLocalPart() const { return m_local.c_str(); }\r
+#else\r
+ /**\r
+ * Returns the namespace prefix\r
+ * @return Null-terminated Unicode string containing the prefix, without the colon\r
+ */\r
+ const XMLCh* getPrefix() const { return m_prefix; }\r
+\r
+ /**\r
+ * Returns the namespace URI\r
+ * @return Null-terminated Unicode string containing the URI\r
+ */\r
+ const XMLCh* getNamespaceURI() const { return m_uri; }\r
+\r
+ /**\r
+ * Returns the local part of the name\r
+ * @return Null-terminated Unicode string containing the local name\r
+ */\r
+ const XMLCh* getLocalPart() const { return m_local; }\r
+#endif\r
+\r
+ /**\r
+ * Sets the namespace prefix\r
+ * @param prefix Null-terminated Unicode string containing the prefix, without the colon\r
+ */\r
+ void setPrefix(const XMLCh* prefix);\r
+\r
+ /**\r
+ * Sets the namespace URI\r
+ * @param uri Null-terminated Unicode string containing the URI\r
+ */\r
+ void setNamespaceURI(const XMLCh* uri);\r
+ \r
+ /**\r
+ * Sets the local part of the name\r
+ * @param localPart Null-terminated Unicode string containing the local name\r
+ */\r
+ void setLocalPart(const XMLCh* localPart);\r
+ \r
+ private:\r
+#ifdef HAVE_GOOD_STL\r
+ xstring m_uri;\r
+ xstring m_local;\r
+ xstring m_prefix;\r
+#else\r
+ XMLCh* m_uri;\r
+ XMLCh* m_local;\r
+ XMLCh* m_prefix;\r
+#endif\r
+ };\r
+\r
+ /**\r
+ * Returns true iff op1's namespace lexically compares less than op2's namespace,\r
+ * or if equal, iff op1's prefix lexically compares less than op2's prefix.\r
+ * \r
+ * Needed for use with sorted STL containers.\r
+ * \r
+ * @param op1 First qname to compare\r
+ * @param op2 Second qname to compare\r
+ */\r
+ extern XMLTOOL_API bool operator<(const QName& op1, const QName& op2);\r
+\r
+#ifndef HAVE_GOOD_STL\r
+ /**\r
+ * Returns true iff op1's components are equal to op2's components.\r
+ * @param op1 First qname to compare\r
+ * @param op2 Second qname to compare\r
+ */\r
+ extern XMLTOOL_API bool operator==(const QName& op1, const QName& op2);\r
+#endif\r
+\r
+};\r
+\r
+#endif /* __xmltooling_qname_h__ */\r
--- /dev/null
+/*\r
+ * Copyright 2001-2006 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 XMLObject.h\r
+ * \r
+ * Abstract interface to objects that can be manipulated in and out of XML form. \r
+ */\r
+\r
+#if !defined(__xmltooling_xmlobj_h__)\r
+#define __xmltooling_xmlobj_h__\r
+\r
+#include <set>\r
+#include <list>\r
+#include <xmltooling/QName.h>\r
+#include <xmltooling/Namespace.h>\r
+\r
+namespace xmltooling {\r
+\r
+ /**\r
+ * Object that represents an XML Element that has been unmarshalled into this C++ object.\r
+ */\r
+ class XMLTOOL_API XMLObject\r
+ {\r
+ MAKE_NONCOPYABLE(XMLObject);\r
+ public:\r
+ virtual ~XMLObject() {}\r
+ \r
+ /**\r
+ * Creates a copy of the object, along with all of its children.\r
+ * \r
+ * The new object tree will be completely distinct and independent of\r
+ * the original in all respects.\r
+ */\r
+ virtual XMLObject* clone() const=0;\r
+ \r
+ /**\r
+ * Gets the QName for this element. This QName <strong>MUST</strong> \r
+ * contain the namespace URI, namespace prefix, and local element name.\r
+ * \r
+ * @return constant reference to the QName for this object\r
+ */\r
+ virtual const QName& getElementQName() const=0;\r
+ \r
+ /**\r
+ * Sets the namespace prefix for this element.\r
+ * \r
+ * @param prefix the prefix for this element\r
+ */\r
+ virtual void setElementNamespacePrefix(const XMLCh* prefix)=0;\r
+ \r
+ /**\r
+ * Gets the namespaces that are scoped to this element.\r
+ * \r
+ * The caller MUST NOT modify the set returned, but may use any\r
+ * non-modifying operations or algorithms on it. Iterators will\r
+ * remain valid unless the set member referenced is removed using\r
+ * the removeNamespace method.\r
+ * \r
+ * @return the namespaces that are scoped to this element\r
+ */\r
+ virtual const std::set<Namespace>& getNamespaces() const=0;\r
+ \r
+ /**\r
+ * Adds a namespace to the ones already scoped to this element\r
+ * \r
+ * @param ns the namespace to add\r
+ */\r
+ virtual void addNamespace(const Namespace& ns)=0;\r
+ \r
+ /**\r
+ * Removes a namespace from this element\r
+ * \r
+ * @param ns the namespace to remove\r
+ */\r
+ virtual void removeNamespace(const Namespace& ns)=0;\r
+ \r
+ /**\r
+ * Gets the XML schema type of this element. This translates to contents the xsi:type\r
+ * attribute for the element.\r
+ * \r
+ * @return XML schema type of this element\r
+ */\r
+ virtual const QName* getSchemaType() const=0;\r
+ \r
+ /**\r
+ * Sets the XML schema type of this element. This translates to contents the xsi:type\r
+ * attribute for the element.\r
+ * \r
+ * @param type XML schema type of this element\r
+ */\r
+ virtual void setSchemaType(const QName* type)=0;\r
+ \r
+ /**\r
+ * Checks to see if this object has a parent.\r
+ * \r
+ * @return true if the object has a parent, false if not\r
+ */\r
+ virtual bool hasParent() const=0;\r
+ \r
+ /**\r
+ * Gets the parent of this element or null if there is no parent.\r
+ * \r
+ * @return the parent of this element or null\r
+ */\r
+ virtual XMLObject* getParent() const=0;\r
+ \r
+ /**\r
+ * Sets the parent of this element.\r
+ * \r
+ * @param parent the parent of this element\r
+ */\r
+ virtual void setParent(XMLObject* parent)=0;\r
+ \r
+ /**\r
+ * Checks if this XMLObject has children.\r
+ * \r
+ * @return true if this XMLObject has children, false if not\r
+ */\r
+ virtual bool hasChildren() const=0;\r
+ \r
+ /**\r
+ * Stores an unmodifiable list of child objects in the order that they\r
+ * will appear in the serialized representation.\r
+ * \r
+ * The validity of the returned objects is not maintained if any non-const\r
+ * operations are performed on the parent object. \r
+ * \r
+ * @param v vector in which to store pointers to child objects\r
+ * @return the number of children\r
+ */\r
+ virtual size_t getOrderedChildren(std::vector<XMLObject*>& v)=0;\r
+ };\r
+\r
+};\r
+\r
+#endif /* __xmltooling_xmlobj_h__ */\r
--- /dev/null
+/*\r
+ * Copyright 2001-2006 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 XMLObjectBuilder.h\r
+ * \r
+ * Factory interface for XMLObjects \r
+ */\r
+\r
+#if !defined(__xmltooling_xmlobjbuilder_h__)\r
+#define __xmltooling_xmlobjbuilder_h__\r
+\r
+#include <xmltooling/XMLObject.h>\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_NON_COPYABLE(XMLObjectBuilder);\r
+ public:\r
+ virtual ~XMLObjectBuilder() {}\r
+ \r
+ /**\r
+ * Creates an empty XMLObject.\r
+ * \r
+ * @return the empty XMLObject\r
+ */\r
+ public XMLObject* buildObject();\r
+ };\r
+\r
+};\r
+\r
+#endif /* __xmltooling_xmlobjbuilder_h__ */\r
--- /dev/null
+/*\r
+ * Copyright 2001-2006 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 XMLToolingConfig.cpp\r
+ * \r
+ * Library configuration \r
+ */\r
+\r
+#include "internal.h"\r
+#include "XMLToolingConfig.h"\r
+#include "util/NDC.h"\r
+\r
+#ifdef HAVE_DLFCN_H\r
+# include <dlfcn.h>\r
+#endif\r
+\r
+#include <log4cpp/Category.hh>\r
+#include <log4cpp/PropertyConfigurator.hh>\r
+#include <log4cpp/OstreamAppender.hh>\r
+#include <xercesc/util/PlatformUtils.hpp>\r
+#include <xsec/framework/XSECProvider.hpp>\r
+\r
+#include <stdexcept>\r
+\r
+using namespace log4cpp;\r
+using namespace xmltooling;\r
+using namespace std;\r
+\r
+namespace {\r
+ XMLToolingInternalConfig g_config;\r
+}\r
+\r
+XMLToolingConfig& XMLToolingConfig::getConfig()\r
+{\r
+ return g_config;\r
+}\r
+\r
+bool XMLToolingInternalConfig::log_config(const char* config)\r
+{\r
+ try {\r
+ if (!config && !*config)\r
+ config=getenv("XMLTOOLING_LOG_CONFIG");\r
+ if (!config && !*config)\r
+ config="WARN";\r
+ \r
+ bool level=false;\r
+ Category& root = Category::getRoot();\r
+ if (!strcmp(config,"DEBUG")) {\r
+ root.setPriority(Priority::DEBUG);\r
+ level=true;\r
+ }\r
+ else if (!strcmp(config,"INFO")) {\r
+ root.setPriority(Priority::INFO);\r
+ level=true;\r
+ }\r
+ else if (!strcmp(config,"NOTICE")) {\r
+ root.setPriority(Priority::NOTICE);\r
+ level=true;\r
+ }\r
+ else if (!strcmp(config,"WARN")) {\r
+ root.setPriority(Priority::WARN);\r
+ level=true;\r
+ }\r
+ else if (!strcmp(config,"ERROR")) {\r
+ root.setPriority(Priority::ERROR);\r
+ level=true;\r
+ }\r
+ else if (!strcmp(config,"CRIT")) {\r
+ root.setPriority(Priority::CRIT);\r
+ level=true;\r
+ }\r
+ else if (!strcmp(config,"ALERT")) {\r
+ root.setPriority(Priority::ALERT);\r
+ level=true;\r
+ }\r
+ else if (!strcmp(config,"EMERG")) {\r
+ root.setPriority(Priority::EMERG);\r
+ level=true;\r
+ }\r
+ else if (!strcmp(config,"FATAL")) {\r
+ root.setPriority(Priority::FATAL);\r
+ level=true;\r
+ }\r
+ if (level)\r
+ root.setAppender(new OstreamAppender("default",&cerr));\r
+ else\r
+ PropertyConfigurator::configure(config);\r
+ }\r
+ catch (const ConfigureFailure& e) {\r
+ Category::getInstance(XMLTOOLING_LOGCAT".Logging").crit("failed to initialize log4cpp: %s", e.what());\r
+ return false;\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+bool XMLToolingInternalConfig::init()\r
+{\r
+#ifdef _DEBUG\r
+ xmltooling::NDC ndc("init");\r
+#endif\r
+ Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLToolingConfig");\r
+ try {\r
+ log.debug("library initialization started");\r
+\r
+ xercesc::XMLPlatformUtils::Initialize();\r
+ log.debug("Xerces initialization complete");\r
+\r
+ XSECPlatformUtils::Initialise();\r
+ //m_xsec=new XSECProvider();\r
+ log.debug("XMLSec initialization complete");\r
+ \r
+ m_lock=xercesc::XMLPlatformUtils::makeMutex();\r
+ }\r
+ catch (const xercesc::XMLException&) {\r
+ log.fatal("caught exception while initializing Xerces");\r
+ return false;\r
+ }\r
+\r
+ log.info("library initialization complete");\r
+ return true;\r
+}\r
+\r
+void XMLToolingInternalConfig::term()\r
+{\r
+ for (vector<void*>::reverse_iterator i=m_libhandles.rbegin(); i!=m_libhandles.rend(); i++) {\r
+#if defined(WIN32)\r
+ FARPROC fn=GetProcAddress(static_cast<HMODULE>(*i),"xmltooling_extension_term");\r
+ if (fn)\r
+ fn();\r
+ FreeLibrary(static_cast<HMODULE>(*i));\r
+#elif defined(HAVE_DLFCN_H)\r
+ void (*fn)()=(void (*)())dlsym(*i,"xmltooling_extension_term");\r
+ if (fn)\r
+ fn();\r
+ dlclose(*i);\r
+#else\r
+# error "Don't know about dynamic loading on this platform!"\r
+#endif\r
+ }\r
+ m_libhandles.clear();\r
+ \r
+ //delete m_xsec; m_xsec=NULL;\r
+ XSECPlatformUtils::Terminate();\r
+ xercesc::XMLPlatformUtils::closeMutex(m_lock);\r
+ xercesc::XMLPlatformUtils::Terminate();\r
+\r
+ #ifdef _DEBUG\r
+ xmltooling::NDC ndc("term");\r
+#endif\r
+ Category::getInstance(XMLTOOLING_LOGCAT".XMLToolingConfig").info("library shutdown complete");\r
+}\r
+\r
+ILockable& XMLToolingInternalConfig::lock()\r
+{\r
+ xercesc::XMLPlatformUtils::lockMutex(m_lock);\r
+ return *this;\r
+}\r
+\r
+void XMLToolingInternalConfig::unlock()\r
+{\r
+ xercesc::XMLPlatformUtils::unlockMutex(m_lock);\r
+}\r
+\r
+bool XMLToolingInternalConfig::load_library(const char* path, void* context)\r
+{\r
+#ifdef _DEBUG\r
+ xmltooling::NDC ndc("LoadLibrary");\r
+#endif\r
+ Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLToolingConfig");\r
+ log.info("loading extension: %s", path);\r
+\r
+#if defined(WIN32)\r
+ HMODULE handle=NULL;\r
+ char* fixed=const_cast<char*>(path);\r
+ if (strchr(fixed,'/')) {\r
+ fixed=strdup(path);\r
+ char* p=fixed;\r
+ while (p=strchr(p,'/'))\r
+ *p='\\';\r
+ }\r
+\r
+ UINT em=SetErrorMode(SEM_FAILCRITICALERRORS);\r
+ try {\r
+ handle=LoadLibraryEx(fixed,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);\r
+ if (!handle)\r
+ handle=LoadLibraryEx(fixed,NULL,0);\r
+ if (!handle)\r
+ throw runtime_error(string("unable to load extension library: ") + fixed);\r
+ FARPROC fn=GetProcAddress(handle,"xmltooling_extension_init");\r
+ if (!fn)\r
+ throw runtime_error(string("unable to locate xmltooling_extension_init entry point: ") + fixed);\r
+ if (reinterpret_cast<int(*)(void*)>(fn)(context)!=0)\r
+ throw runtime_error(string("detected error in xmltooling_extension_init: ") + fixed);\r
+ if (fixed!=path)\r
+ free(fixed);\r
+ SetErrorMode(em);\r
+ }\r
+ catch(runtime_error& e) {\r
+ log.error(e.what());\r
+ if (handle)\r
+ FreeLibrary(handle);\r
+ SetErrorMode(em);\r
+ if (fixed!=path)\r
+ free(fixed);\r
+ return false;\r
+ }\r
+\r
+#elif defined(HAVE_DLFCN_H)\r
+ void* handle=dlopen(path,RTLD_LAZY);\r
+ if (!handle)\r
+ throw runtime_error(string("unable to load extension library '") + path + "': " + dlerror());\r
+ int (*fn)(void*)=(int (*)(void*))(dlsym(handle,"xmltooling_extension_init"));\r
+ if (!fn) {\r
+ dlclose(handle);\r
+ throw runtime_error(\r
+ string("unable to locate xmltooling_extension_init entry point in '") + path + "': " +\r
+ (dlerror() ? dlerror() : "unknown error")\r
+ );\r
+ }\r
+ try {\r
+ if (fn(context)!=0)\r
+ throw runtime_error(string("detected error in xmltooling_extension_init in ") + path);\r
+ }\r
+ catch(runtime_error& e) {\r
+ log.error(e.what());\r
+ if (handle)\r
+ dlclose(handle);\r
+ return false;\r
+ }\r
+#else\r
+# error "Don't know about dynamic loading on this platform!"\r
+#endif\r
+ m_libhandles.push_back(handle);\r
+ log.info("loaded extension: %s", path);\r
+ return true;\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2001-2006 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 XMLToolingConfig.h\r
+ * \r
+ * Library configuration \r
+ */\r
+\r
+#if !defined(__xmltooling_config_h__)\r
+#define __xmltooling_config_h__\r
+\r
+#include <xmltooling/ILockable.h>\r
+\r
+namespace xmltooling {\r
+\r
+ /**\r
+ * Singleton object that manages library startup/shutdown.configuration.\r
+ */\r
+ class XMLTOOL_API XMLToolingConfig : public ILockable\r
+ {\r
+ MAKE_NONCOPYABLE(XMLToolingConfig);\r
+ public:\r
+ virtual ~XMLToolingConfig() {}\r
+\r
+ /**\r
+ * Returns the global configuration object for the library.\r
+ * \r
+ * @return reference to the global library configuration object\r
+ */\r
+ static XMLToolingConfig& getConfig();\r
+ \r
+ /**\r
+ * Initializes library\r
+ * \r
+ * Each process using the library MUST call this function exactly once\r
+ * before using any library classes except for the LogConfig method.\r
+ * \r
+ * @return true iff initialization was successful \r
+ */\r
+ virtual bool init()=0;\r
+ \r
+ /**\r
+ * Shuts down library\r
+ * \r
+ * Each process using the library SHOULD call this function exactly once\r
+ * before terminating itself\r
+ */\r
+ virtual void term()=0;\r
+\r
+ /**\r
+ * Loads a shared/dynamic library extension.\r
+ * \r
+ * Extension libraries are managed using a pair of "C" linkage functions:<br>\r
+ * extern "C" int xmltooling_extension_init(void* context);<br>\r
+ * extern "C" void xmltooling_extension_term();\r
+ * \r
+ * @param path pathname of shared library to load into process\r
+ * @param context arbitrary data to pass to library initialization hook\r
+ * @return true iff library was loaded successfully\r
+ */\r
+ virtual bool load_library(const char* path, void* context=NULL)=0;\r
+ \r
+ /**\r
+ * Configure logging system.\r
+ * \r
+ * May be called first, before initializing the library.\r
+ * \r
+ * @param config either a logging configuration file, or a level from the set\r
+ * (DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, FATAL, EMERG)\r
+ * @return true iff configuration was successful\r
+ */\r
+ virtual bool log_config(const char* config=NULL)=0;\r
+\r
+ protected:\r
+ XMLToolingConfig() {}\r
+ };\r
+\r
+};\r
+\r
+#endif /* __xmltooling_config_h__ */\r
#define XMLTOOL_EXCEPTIONAPI(api)\r
#endif\r
\r
+// Macro to block copy c'tor and assignment operator for a class\r
+#define MAKE_NONCOPYABLE(type) \\r
+ private: \\r
+ type(const type&); \\r
+ type& operator=(const type&)\r
+\r
+#ifndef NULL\r
+#define NULL 0\r
+#endif\r
+\r
#endif /* __xmltooling_base_h__ */\r
#endif\r
\r
#include "base.h"\r
+#include "XMLToolingConfig.h"\r
+\r
+#include <vector>\r
\r
#define XMLTOOLING_LOGCAT "XMLTooling"\r
\r
+namespace {\r
+ \r
+ class XMLToolingInternalConfig : public xmltooling::XMLToolingConfig\r
+ {\r
+ public:\r
+ XMLToolingInternalConfig() : m_lock(NULL) {}\r
+\r
+ // global per-process setup and shutdown of runtime\r
+ bool init();\r
+ void term();\r
+\r
+ // global mutex available to library applications\r
+ xmltooling::ILockable& lock();\r
+ void unlock();\r
+\r
+ // configuration\r
+ bool load_library(const char* path, void* context=NULL);\r
+ bool log_config(const char* config=NULL);\r
+\r
+ private:\r
+ std::vector<void*> m_libhandles;\r
+ void* m_lock;\r
+ //XSECProvider* m_xsec;\r
+ //PlugManager m_plugMgr;\r
+ };\r
+\r
+};\r
+\r
#endif /* __xmltooling_internal_h__ */\r
*/\r
char* release() { char* temp=m_buf; m_buf=NULL; return temp; }\r
\r
- private:\r
- auto_ptr_char(const auto_ptr_char&);\r
- auto_ptr_char& operator=(const auto_ptr_char&);\r
- \r
+ private: \r
char* m_buf;\r
+ MAKE_NONCOPYABLE(auto_ptr_char);\r
};\r
\r
/**\r
XMLCh* release() { XMLCh* temp=m_buf; m_buf=NULL; return temp; }\r
\r
private:\r
- auto_ptr_XMLCh(const auto_ptr_XMLCh&);\r
- auto_ptr_XMLCh& operator=(const auto_ptr_XMLCh&);\r
-\r
XMLCh* m_buf;\r
+ MAKE_NONCOPYABLE(auto_ptr_XMLCh);\r
};\r
\r
};\r
MinimalRebuild="true"\r
BasicRuntimeChecks="3"\r
RuntimeLibrary="3"\r
- DisableLanguageExtensions="true"\r
UsePrecompiledHeader="0"\r
BrowseInformation="1"\r
WarningLevel="3"\r
/>\r
<Tool\r
Name="VCLinkerTool"\r
- AdditionalDependencies="log4cppD.lib xerces-c_2D.lib"\r
+ AdditionalDependencies="log4cppD.lib xerces-c_2D.lib xsec_1D.lib"\r
OutputFile="$(OutDir)\$(ProjectName)_1D.dll"\r
LinkIncremental="2"\r
GenerateDebugInformation="true"\r
AdditionalIncludeDirectories=""$(SolutionDir)";"$(ProjectDir)""\r
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;XMLTOOLING_EXPORTS"\r
RuntimeLibrary="2"\r
- DisableLanguageExtensions="true"\r
UsePrecompiledHeader="0"\r
WarningLevel="3"\r
Detect64BitPortabilityProblems="true"\r
/>\r
<Tool\r
Name="VCLinkerTool"\r
- AdditionalDependencies="log4cpp.lib xerces-c_2.lib"\r
+ AdditionalDependencies="log4cpp.lib xerces-c_2.lib xsec_1.lib"\r
OutputFile="$(OutDir)\$(ProjectName)_1.dll"\r
LinkIncremental="2"\r
GenerateDebugInformation="true"\r
RelativePath=".\Namespace.cpp"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\QName.cpp"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\XMLToolingConfig.cpp"\r
+ >\r
+ </File>\r
<Filter\r
Name="util"\r
>\r
RelativePath=".\util\NDC.cpp"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\util\XMLConstants.cpp"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\util\XMLHelper.cpp"\r
+ >\r
+ </File>\r
</Filter>\r
</Filter>\r
<Filter\r
>\r
</File>\r
<File\r
+ RelativePath=".\ILockable.h"\r
+ >\r
+ </File>\r
+ <File\r
RelativePath=".\internal.h"\r
>\r
</File>\r
>\r
</File>\r
<File\r
+ RelativePath=".\QName.h"\r
+ >\r
+ </File>\r
+ <File\r
RelativePath=".\unicode.h"\r
>\r
</File>\r
RelativePath=".\version.h"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\XMLObject.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\XMLObjectBuilder.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\XMLToolingConfig.h"\r
+ >\r
+ </File>\r
<Filter\r
Name="util"\r
>\r
RelativePath=".\util\NDC.h"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\util\XMLConstants.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\util\XMLHelper.h"\r
+ >\r
+ </File>\r
</Filter>\r
</Filter>\r
<Filter\r