xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amass...@apache.org
Subject svn commit: r655707 - in /xerces/c/trunk/src/xercesc/dom: DOMXPathEvaluator.hpp DOMXPathNSResolver.hpp impl/DOMDocumentImpl.cpp impl/DOMDocumentImpl.hpp impl/DOMXPathNSResolverImpl.cpp impl/DOMXPathNSResolverImpl.hpp
Date Tue, 13 May 2008 01:27:11 GMT
Author: amassari
Date: Mon May 12 18:27:10 2008
New Revision: 655707

URL: http://svn.apache.org/viewvc?rev=655707&view=rev
Log:
Add addNamespaceBinding() and release() APIs to XPathNSResolver class (XERCESC-1802) - patch
by John Snelson

Modified:
    xerces/c/trunk/src/xercesc/dom/DOMXPathEvaluator.hpp
    xerces/c/trunk/src/xercesc/dom/DOMXPathNSResolver.hpp
    xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentImpl.cpp
    xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentImpl.hpp
    xerces/c/trunk/src/xercesc/dom/impl/DOMXPathNSResolverImpl.cpp
    xerces/c/trunk/src/xercesc/dom/impl/DOMXPathNSResolverImpl.hpp

Modified: xerces/c/trunk/src/xercesc/dom/DOMXPathEvaluator.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/DOMXPathEvaluator.hpp?rev=655707&r1=655706&r2=655707&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/DOMXPathEvaluator.hpp (original)
+++ xerces/c/trunk/src/xercesc/dom/DOMXPathEvaluator.hpp Mon May 12 18:27:10 2008
@@ -114,11 +114,13 @@
      * information available in the node's hierarchy at the time lookupNamespaceURI 
      * is called. also correctly resolving the implicit xml prefix.
      * @param nodeResolver of type <code>DOMNode</code> The node to be used as
a context 
-     * for namespace resolution.
+     * for namespace resolution. If this parameter is null, an unpopulated
+     * <code>DOMXPathNSResolver</code> is returned, which can be populated using
the
+     * Xerces-C extension <code>DOMXPathNSResolver::addNamespaceBinding()</code>.
      * @return <code>DOMXPathNSResolver</code> The object which resolves namespaces

      * with respect to the definitions in scope for the specified node.
      */
-    virtual const DOMXPathNSResolver*    createNSResolver(const DOMNode *nodeResolver) =
0;
+    virtual DOMXPathNSResolver*    createNSResolver(const DOMNode *nodeResolver) = 0;
 
 
     /**

Modified: xerces/c/trunk/src/xercesc/dom/DOMXPathNSResolver.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/DOMXPathNSResolver.hpp?rev=655707&r1=655706&r2=655707&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/DOMXPathNSResolver.hpp (original)
+++ xerces/c/trunk/src/xercesc/dom/DOMXPathNSResolver.hpp Mon May 12 18:27:10 2008
@@ -95,13 +95,28 @@
      *
      * XPath2 implementations require a reverse lookup in the static context.
      * Look up the prefix associated with the namespace URI
-     * The XPath evaluator must never call this with a null or empty argument, 
-     * because the result of doing this is undefined.
      * @param URI of type XMLCh - The namespace to look for.
      * @return the associated prefix or null if none is found.
      */
     virtual const XMLCh*          lookupPrefix(const XMLCh* URI) const = 0;
 
+    /**
+     * Non-standard extension
+     *
+     * Associate the given namespace prefix to the namespace URI.
+     * @param prefix of type XMLCh - The namespace prefix to bind.
+     * @param URI of type XMLCh - The associated namespace URI.
+     */
+    virtual void addNamespaceBinding(const XMLCh* prefix, const XMLCh* uri) = 0;
+
+    /**
+     * Called to indicate that this object (and its associated children) is no longer in
use
+     * and that the implementation may relinquish any resources associated with it and
+     * its associated children.
+     *
+     * Access to a released object will lead to unexpected result.
+     */
+    virtual void release() = 0;
 
     //@}
 };
@@ -110,3 +125,4 @@
 
 #endif
 
+

Modified: xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentImpl.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentImpl.cpp?rev=655707&r1=655706&r2=655707&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentImpl.cpp (original)
+++ xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentImpl.cpp Mon May 12 18:27:10 2008
@@ -427,9 +427,9 @@
     return new (getMemoryManager()) DOMXPathExpressionImpl(expression, resolver, getMemoryManager());
 }
 
-const DOMXPathNSResolver* DOMDocumentImpl::createNSResolver(const DOMNode *nodeResolver)
+DOMXPathNSResolver* DOMDocumentImpl::createNSResolver(const DOMNode *nodeResolver)
 {
-    return new (this) DOMXPathNSResolverImpl(nodeResolver);
+    return new (getMemoryManager()) DOMXPathNSResolverImpl(nodeResolver, getMemoryManager());
 }
 
 void* DOMDocumentImpl::evaluate(const XMLCh *expression, const DOMNode *contextNode, const
DOMXPathNSResolver *resolver, 

Modified: xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentImpl.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentImpl.hpp?rev=655707&r1=655706&r2=655707&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentImpl.hpp (original)
+++ xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentImpl.hpp Mon May 12 18:27:10 2008
@@ -142,7 +142,7 @@
     virtual void                 removeNodeIterator(DOMNodeIteratorImpl* nodeIterator); //non-standard
api
 
     virtual const DOMXPathExpression*    createExpression(const XMLCh *expression, const
DOMXPathNSResolver *resolver);
-    virtual const DOMXPathNSResolver*    createNSResolver(const DOMNode *nodeResolver);
+    virtual DOMXPathNSResolver*    createNSResolver(const DOMNode *nodeResolver);
     virtual void* evaluate(const XMLCh *expression, const DOMNode *contextNode, const DOMXPathNSResolver
*resolver, 
                            unsigned short type, void* result);
 

Modified: xerces/c/trunk/src/xercesc/dom/impl/DOMXPathNSResolverImpl.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/impl/DOMXPathNSResolverImpl.cpp?rev=655707&r1=655706&r2=655707&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/impl/DOMXPathNSResolverImpl.cpp (original)
+++ xerces/c/trunk/src/xercesc/dom/impl/DOMXPathNSResolverImpl.cpp Mon May 12 18:27:10 2008
@@ -18,30 +18,68 @@
 #include "DOMXPathNSResolverImpl.hpp"
 #include <xercesc/dom/DOMNode.hpp>
 #include <xercesc/util/XMLString.hpp>
+#include <xercesc/util/Janitor.hpp>
+#include <xercesc/util/XMLString.hpp>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
-DOMXPathNSResolverImpl::DOMXPathNSResolverImpl(const DOMNode *nodeResolver):
- fResolverNode(nodeResolver)
+DOMXPathNSResolverImpl::DOMXPathNSResolverImpl(const DOMNode *nodeResolver, MemoryManager*
const manager) :
+    fNamespaceBindings(7, true, manager),
+    fResolverNode(nodeResolver),
+    fManager(manager)
 {
 }
 
 const XMLCh* DOMXPathNSResolverImpl::lookupNamespaceURI(const XMLCh* prefix) const
 {
-    if (XMLString::equals(prefix, XMLUni::fgXMLString))
+    if(XMLString::equals(prefix, XMLUni::fgXMLString))
         return XMLUni::fgXMLURIName;
+
+    const KVStringPair *pair = fNamespaceBindings.get((void*)prefix);
+    if(pair) {
+        if(*pair->getValue() == 0) return NULL;
+        return pair->getValue();
+    }
+
     if(fResolverNode)
         return fResolverNode->lookupNamespaceURI(prefix);
+
     return NULL;
 }
 
-const XMLCh* DOMXPathNSResolverImpl::lookupPrefix(const XMLCh* URI) const
+const XMLCh* DOMXPathNSResolverImpl::lookupPrefix(const XMLCh* uri) const
 {
-    if (XMLString::equals(URI, XMLUni::fgXMLURIName))
+    if(XMLString::equals(uri, XMLUni::fgXMLURIName))
         return XMLUni::fgXMLString;
+
+    RefHashTableOfEnumerator<KVStringPair> enumerator((RefHashTableOf<KVStringPair>*)&fNamespaceBindings);
+    while(enumerator.hasMoreElements()) {
+        KVStringPair &pair = enumerator.nextElement();
+        if(XMLString::equals(pair.getValue(), uri)) {
+            return pair.getKey();
+        }
+    }
+
     if(fResolverNode)
-        return fResolverNode->lookupPrefix(URI);
+        return fResolverNode->lookupPrefix(uri);
+
     return NULL;
 }
 
+void DOMXPathNSResolverImpl::addNamespaceBinding(const XMLCh* prefix, const XMLCh* uri)
+{
+    if(prefix == 0) prefix = XMLUni::fgZeroLenString;
+    if(uri == 0) uri = XMLUni::fgZeroLenString;
+
+    KVStringPair* pair = new (fManager) KVStringPair(prefix, uri, fManager);
+
+    fNamespaceBindings.put((void*)pair->getKey(), pair);
+}
+
+void DOMXPathNSResolverImpl::release()
+{
+    DOMXPathNSResolverImpl* me=(DOMXPathNSResolverImpl*)this;
+    delete me;
+}
+
 XERCES_CPP_NAMESPACE_END

Modified: xerces/c/trunk/src/xercesc/dom/impl/DOMXPathNSResolverImpl.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/impl/DOMXPathNSResolverImpl.hpp?rev=655707&r1=655706&r2=655707&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/impl/DOMXPathNSResolverImpl.hpp (original)
+++ xerces/c/trunk/src/xercesc/dom/impl/DOMXPathNSResolverImpl.hpp Mon May 12 18:27:10 2008
@@ -23,25 +23,35 @@
 #define XERCESC_INCLUDE_GUARD_DOMXPATHNSRESOLVERIMPL_HPP
 
 #include <xercesc/util/XercesDefs.hpp>
+#include <xercesc/util/XMemory.hpp>
+#include <xercesc/util/PlatformUtils.hpp>
 #include <xercesc/dom/DOMXPathNSResolver.hpp>
+#include <xercesc/util/KVStringPair.hpp>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
 class DOMNode;
 
-class CDOM_EXPORT DOMXPathNSResolverImpl : public DOMXPathNSResolver
+class CDOM_EXPORT DOMXPathNSResolverImpl : public XMemory,
+                                           public DOMXPathNSResolver
 {
 public:
-    DOMXPathNSResolverImpl(const DOMNode *nodeResolver);
+    DOMXPathNSResolverImpl(const DOMNode* nodeResolver = 0, MemoryManager* const manager
= XMLPlatformUtils::fgMemoryManager);
 
     virtual const XMLCh*          lookupNamespaceURI(const XMLCh* prefix) const;
     virtual const XMLCh*          lookupPrefix(const XMLCh* URI) const;
+    virtual void                  addNamespaceBinding(const XMLCh* prefix, const XMLCh* uri);
+
+    virtual void                  release();
 
 protected:
+    RefHashTableOf<KVStringPair>  fNamespaceBindings;
     const DOMNode*                fResolverNode;
+    MemoryManager*                fManager;
 };
 
 XERCES_CPP_NAMESPACE_END
 
 #endif
 
+



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org


Mime
View raw message