X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2FAbstractDOMCachingXMLObject.h;h=9ceda4419c8afad71d195ec0d3c137c25f832f97;hb=5cb314df178f78c6fa7b9826c2c5a5298ec7a473;hp=ce8d2c4efe7a8221e41d78b2c9d6eb0f5602896c;hpb=b3ed0767e4769c803e8e194f0634c7f83f3f1eeb;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/AbstractDOMCachingXMLObject.h b/xmltooling/AbstractDOMCachingXMLObject.h index ce8d2c4..9ceda44 100644 --- a/xmltooling/AbstractDOMCachingXMLObject.h +++ b/xmltooling/AbstractDOMCachingXMLObject.h @@ -1,156 +1,92 @@ -/* - * Copyright 2001-2006 Internet2 - * - * Licensed 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 AbstractDOMCachingXMLObject.h - * - * Extension of AbstractXMLObject that implements a DOMCachingXMLObject. - */ - -#if !defined(__xmltooling_abstractdomxmlobj_h__) -#define __xmltooling_abstractdomxmlobj_h__ - -#include -#include - -#if defined (_MSC_VER) - #pragma warning( push ) - #pragma warning( disable : 4250 4251 ) -#endif - -namespace xmltooling { - - /** - * Extension of AbstractXMLObject that implements a DOMCachingXMLObject. - * This is the primary base class for XMLObject implementation classes to use. - */ - class XMLTOOL_API AbstractDOMCachingXMLObject : public AbstractXMLObject, public DOMCachingXMLObject - { - public: - virtual ~AbstractDOMCachingXMLObject(); - - /** - * @see DOMCachingXMLObject::getDOM() - */ - DOMElement* getDOM() const { - return m_dom; - } - - /** - * @see DOMCachingXMLObject::setDOM() - */ - void setDOM(DOMElement* dom, bool bindDocument=false); - - /** - * @see DOMCachingXMLObject::setDocument() - */ - void setDocument(DOMDocument* doc) { - if (m_document) - m_document->release(); - m_document=doc; - } - - /** - * @see DOMCachingXMLObject::releaseDOM() - */ - virtual void releaseDOM(); - - /** - * @see DOMCachingXMLObject::releaseParentDOM() - */ - virtual void releaseParentDOM(bool propagateRelease=true); - - /** - * @see DOMCachingXMLObject::releaseChildrenDOM() - */ - virtual void releaseChildrenDOM(bool propagateRelease=true); - - /** - * A convenience method that is equal to calling releaseDOM() then releaseParentDOM(true). - */ - void releaseThisandParentDOM() { - if (m_dom) { - releaseDOM(); - releaseParentDOM(true); - } - } - - /** - * A convenience method that is equal to calling releaseChildrenDOM(true) then releaseDOM(). - */ - void releaseThisAndChildrenDOM() { - if (m_dom) { - releaseChildrenDOM(true); - releaseDOM(); - } - } - - /** - * @see XMLObject::clone() - */ - XMLObject* clone() const; - - protected: - /** - * Constructor - * - * @param namespaceURI the namespace the element is in - * @param elementLocalName the local name of the XML element this Object represents - * @param namespacePrefix the namespace prefix to use - */ - AbstractDOMCachingXMLObject(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL) - : AbstractXMLObject(namespaceURI,elementLocalName, namespacePrefix), m_dom(NULL), m_document(NULL) {} - - /** - * If a DOM representation exists, this clones it into a new document. - * - * @param doc the document to clone into, or NULL, in which case a new document is created - * @return the cloned DOM - */ - DOMElement* cloneDOM(DOMDocument* doc=NULL) const; - - /** - * A helper function for derived classes. - * This 'normalizes' newString and then if it is different from oldString - * invalidates the DOM. It returns the normalized value. - * - * @param oldValue - the current value - * @param newValue - the new value - * - * @return the value that should be assigned - */ - XMLCh* prepareForAssignment(const XMLCh* oldValue, const XMLCh* newValue) { - XMLCh* newString = XMLString::replicate(newValue); - XMLString::trim(newString); - - if (!XMLString::equals(oldValue,newValue)) - releaseThisandParentDOM(); - - return newString; - } - - private: - DOMElement* m_dom; - DOMDocument* m_document; - }; - -}; - -#if defined (_MSC_VER) - #pragma warning( pop ) -#endif - -#endif /* __xmltooling_abstractdomxmlobj_h__ */ +/* + * Copyright 2001-2007 Internet2 + * + * Licensed 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 AbstractDOMCachingXMLObject.h + * + * AbstractXMLObject mixin that implements DOM caching + */ + +#if !defined(__xmltooling_abstractdomxmlobj_h__) +#define __xmltooling_abstractdomxmlobj_h__ + +#include + +#if defined (_MSC_VER) + #pragma warning( push ) + #pragma warning( disable : 4250 4251 ) +#endif + +namespace xmltooling { + + /** + * AbstractXMLObject mixin that implements DOM caching. + * Inherit from this class to implement standard DOM caching behavior. + */ + class XMLTOOL_API AbstractDOMCachingXMLObject : public virtual AbstractXMLObject + { + public: + virtual ~AbstractDOMCachingXMLObject(); + + DOMElement* getDOM() const { + return m_dom; + } + + void setDOM(DOMElement* dom, bool bindDocument=false) const; + + void setDocument(DOMDocument* doc) const { + if (m_document) + m_document->release(); + m_document=doc; + } + + virtual void releaseDOM() const; + + virtual void releaseParentDOM(bool propagateRelease=true) const; + + virtual void releaseChildrenDOM(bool propagateRelease=true) const; + + XMLObject* clone() const; + + void detach(); + + protected: + AbstractDOMCachingXMLObject() : m_dom(NULL), m_document(NULL) {} + + /** Copy constructor. */ + AbstractDOMCachingXMLObject(const AbstractDOMCachingXMLObject& src) + : AbstractXMLObject(src), m_dom(NULL), m_document(NULL) {} + + /** + * If a DOM representation exists, this clones it into a new document. + * + * @param doc the document to clone into, or NULL, in which case a new document is created + * @return the cloned DOM + */ + DOMElement* cloneDOM(DOMDocument* doc=NULL) const; + + private: + mutable DOMElement* m_dom; + mutable DOMDocument* m_document; + }; + +}; + +#if defined (_MSC_VER) + #pragma warning( pop ) +#endif + +#endif /* __xmltooling_abstractdomxmlobj_h__ */