You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@locus.apache.org on 2000/05/01 17:11:43 UTC
cvs commit: xml-xalan/c/src/XPath XPath.cpp XPathEnvSupport.hpp XPathEnvSupportDefault.cpp XPathEnvSupportDefault.hpp XPathExecutionContext.hpp XPathExecutionContextDefault.cpp XPathExecutionContextDefault.hpp XPathProcessorImpl.cpp
dbertoni 00/05/01 08:11:43
Modified: c/src/XPath XPath.cpp XPathEnvSupport.hpp
XPathEnvSupportDefault.cpp
XPathEnvSupportDefault.hpp
XPathExecutionContext.hpp
XPathExecutionContextDefault.cpp
XPathExecutionContextDefault.hpp
XPathProcessorImpl.cpp
Log:
Fixed a bug in calling external functions, and added better support for installing external functions.
Revision Changes Path
1.14 +6 -2 xml-xalan/c/src/XPath/XPath.cpp
Index: XPath.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XPath.cpp 2000/04/27 15:11:25 1.13
+++ XPath.cpp 2000/05/01 15:11:42 1.14
@@ -53,7 +53,10 @@
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
+ *
+ * @author <a href="mailto:david_n_bertoni@lotus.com">David N. Bertoni</a>
*/
+
// Class header file.
#include "XPath.hpp"
@@ -1387,7 +1390,7 @@
XObject*
XPath::extfunction(
- XalanNode* /* context */,
+ XalanNode* context,
int /* opPos */,
const XalanDOMString& theNamespace,
const XalanDOMString& extensionName,
@@ -1395,7 +1398,8 @@
XPathExecutionContext& executionContext) const
{
return executionContext.extFunction(theNamespace,
- extensionName,
+ extensionName,
+ context,
argVec);
}
1.7 +3 -0 xml-xalan/c/src/XPath/XPathEnvSupport.hpp
Index: XPathEnvSupport.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathEnvSupport.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XPathEnvSupport.hpp 2000/04/14 21:08:52 1.6
+++ XPathEnvSupport.hpp 2000/05/01 15:11:42 1.7
@@ -53,6 +53,8 @@
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
+ *
+ * @author <a href="mailto:david_n_bertoni@lotus.com">David N. Bertoni</a>
*/
#if !defined(XPATHENVSUPPORT_HEADER_GUARD_1357924680)
#define XPATHENVSUPPORT_HEADER_GUARD_1357924680
@@ -230,6 +232,7 @@
XPathExecutionContext& executionContext,
const XalanDOMString& theNamespace,
const XalanDOMString& extensionName,
+ XalanNode* context,
const XObjectArgVectorType& argVec) const = 0;
/**
1.8 +215 -8 xml-xalan/c/src/XPath/XPathEnvSupportDefault.cpp
Index: XPathEnvSupportDefault.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathEnvSupportDefault.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XPathEnvSupportDefault.cpp 2000/04/14 21:08:52 1.7
+++ XPathEnvSupportDefault.cpp 2000/05/01 15:11:42 1.8
@@ -53,7 +53,10 @@
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
+ *
+ * @author <a href="mailto:david_n_bertoni@lotus.com">David N. Bertoni</a>
*/
+
#include "XPathEnvSupportDefault.hpp"
@@ -83,9 +86,14 @@
+XPathEnvSupportDefault::NamespaceFunctionTablesType XPathEnvSupportDefault::s_externalFunctions;
+
+
+
XPathEnvSupportDefault::XPathEnvSupportDefault() :
XPathEnvSupport(),
- m_sourceDocs()
+ m_sourceDocs(),
+ m_externalFunctions()
{
}
@@ -98,6 +106,109 @@
void
+XPathEnvSupportDefault::updateFunctionTable(
+ NamespaceFunctionTablesType& theTable,
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName,
+ const Function* function)
+{
+ // See if there's a table for that namespace...
+ const NamespaceFunctionTablesType::iterator i =
+ theTable.find(theNamespace);
+
+ if (i == theTable.end())
+ {
+ // The namespace was not found. If function is not
+ // 0, then add a clone of the function.
+ if (function != 0)
+ {
+ theTable[theNamespace][extensionName] =
+ function->clone();
+ }
+ }
+ else
+ {
+ // There is already a table for the namespace,
+ // so look for the function...
+ const FunctionTableType::iterator j =
+ i->second.find(extensionName);
+
+ if (j == i->second.end())
+ {
+ // The function was not found. If function is not
+ // 0, then add a clone of the function.
+ if (function != 0)
+ {
+ i->second[extensionName] = function->clone();
+ }
+ }
+ else
+ {
+ // Found it, so delete the function...
+
+ delete j->second;
+
+ // If function is not 0, then we update
+ // the entry. Otherwise, we erase it...
+ if (function != 0)
+ {
+ // Update it...
+ j->second = function->clone();
+ }
+ else
+ {
+ // Erase it...
+ i->second.erase(j);
+ }
+ }
+ }
+}
+
+
+
+void
+XPathEnvSupportDefault::installExternalFunctionGlobal(
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName,
+ const Function& function)
+{
+ updateFunctionTable(s_externalFunctions, theNamespace, extensionName, &function);
+}
+
+
+
+void
+XPathEnvSupportDefault::uninstallExternalFunctionGlobal(
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName)
+{
+ updateFunctionTable(s_externalFunctions, theNamespace, extensionName, 0);
+}
+
+
+
+void
+XPathEnvSupportDefault::installExternalFunctionLocal(
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName,
+ const Function& function)
+{
+ updateFunctionTable(m_externalFunctions, theNamespace, extensionName, &function);
+}
+
+
+
+void
+XPathEnvSupportDefault::uninstallExternalFunctionLocal(
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName)
+{
+ updateFunctionTable(m_externalFunctions, theNamespace, extensionName, 0);
+}
+
+
+
+void
XPathEnvSupportDefault::reset()
{
m_sourceDocs.clear();
@@ -212,22 +323,118 @@
bool
XPathEnvSupportDefault::functionAvailable(
- const XalanDOMString& /* theNamespace */,
- const XalanDOMString& /* extensionName */) const
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName) const
{
- return false;
+ bool theResult = false;
+
+ // See if there's a table for that namespace...
+ const NamespaceFunctionTablesType::iterator i =
+ m_externalFunctions.find(theNamespace);
+
+ if (i != m_externalFunctions.end())
+ {
+ // There is a table for the namespace,
+ // so look for the function...
+ const FunctionTableType::iterator j =
+ i->second.find(extensionName);
+
+ if (j != i->second.end())
+ {
+ theResult = true;
+ }
+ }
+
+ return theResult;
+}
+
+
+
+Function*
+XPathEnvSupportDefault::findFunction(
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName) const
+{
+ // First, look locally...
+ Function* theFunction = findFunction(
+ m_externalFunctions,
+ theNamespace,
+ extensionName);
+
+ if (theFunction == 0)
+ {
+ // Not found, so look in the global space...
+ theFunction = findFunction(
+ s_externalFunctions,
+ theNamespace,
+ extensionName);
+ }
+
+ return theFunction;
}
+Function*
+XPathEnvSupportDefault::findFunction(
+ const NamespaceFunctionTablesType& theTable,
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName) const
+{
+ Function* theFunction = 0;
+
+ // See if there's a table for that namespace...
+ const NamespaceFunctionTablesType::iterator i =
+ theTable.find(theNamespace);
+
+ if (i != theTable.end())
+ {
+ // There is a table for the namespace,
+ // so look for the function...
+ const FunctionTableType::iterator j =
+ i->second.find(extensionName);
+
+ if (j != i->second.end())
+ {
+ // Found the function...
+ assert(j->second != 0);
+
+ theFunction = j->second;
+ }
+ }
+
+ return theFunction;
+}
+
+
+
XObject*
XPathEnvSupportDefault::extFunction(
XPathExecutionContext& executionContext,
- const XalanDOMString& /* theNamespace */,
- const XalanDOMString& /* extensionName */,
- const XObjectArgVectorType& /* argVec */) const
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName,
+ XalanNode* context,
+ const XObjectArgVectorType& argVec) const
{
- return executionContext.getXObjectFactory().createNull();
+ XObject* theResult = 0;
+
+ Function* const theFunction = findFunction(theNamespace, extensionName);
+
+ if (theFunction != 0)
+ {
+ theResult = theFunction->execute(
+ executionContext,
+ context,
+ 0,
+ argVec);
+ }
+
+ if (theResult == 0)
+ {
+ theResult = executionContext.getXObjectFactory().createNull();
+ }
+
+ return theResult;
}
1.8 +118 -6 xml-xalan/c/src/XPath/XPathEnvSupportDefault.hpp
Index: XPathEnvSupportDefault.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathEnvSupportDefault.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XPathEnvSupportDefault.hpp 2000/04/14 21:08:52 1.7
+++ XPathEnvSupportDefault.hpp 2000/05/01 15:11:42 1.8
@@ -53,6 +53,8 @@
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
+ *
+ * @author <a href="mailto:david_n_bertoni@lotus.com">David N. Bertoni</a>
*/
#if !defined(XPATHENVSUPPORTDEFAULT_HEADER_GUARD_1357924680)
#define XPATHENVSUPPORTDEFAULT_HEADER_GUARD_1357924680
@@ -85,6 +87,62 @@
virtual
~XPathEnvSupportDefault();
+
+ // Interfaces to install and uninstall external functions globally.
+ // These calls are not thread-safe, and should happen during
+ // processing.
+
+ /**
+ * Install an external function in the global space.
+ *
+ * @param theNamespace The namespace for the functionl
+ * @param extensionName The name of the function.
+ * @param function The function to install.
+ */
+ static void
+ installExternalFunctionGlobal(
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName,
+ const Function& function);
+
+ /**
+ * Uninstall an external function from the global space.
+ *
+ * @param theNamespace The namespace for the functionl
+ * @param extensionName The name of the function.
+ */
+ static void
+ uninstallExternalFunctionGlobal(
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName);
+
+ // Interfaces to install and uninstall external functions in this instance.
+
+ /**
+ * Install an external function in the local space.
+ *
+ * @param theNamespace The namespace for the functionl
+ * @param extensionName The name of the function.
+ * @param function The function to install.
+ */
+ virtual void
+ installExternalFunctionLocal(
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName,
+ const Function& function);
+
+ /**
+ * Uninstall an external function from the local space.
+ *
+ * @param theNamespace The namespace for the functionl
+ * @param extensionName The name of the function.
+ */
+ virtual void
+ uninstallExternalFunctionLocal(
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName);
+
+
// These interfaces are inherited from XPathEnvSupport...
virtual const NodeRefListBase*
@@ -134,6 +192,7 @@
XPathExecutionContext& executionContext,
const XalanDOMString& theNamespace,
const XalanDOMString& extensionName,
+ XalanNode* context,
const XObjectArgVectorType& argVec) const;
virtual XLocator*
@@ -172,6 +231,20 @@
virtual void
reset();
+protected:
+
+ /**
+ * Find an external function.
+ *
+ * @param theNamespace The namespace for the function.
+ * @param extensionName The name of the function.
+ * @return a pointer to the function if found, or 0 if not found.
+ */
+ virtual Function*
+ findFunction(
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName) const;
+
private:
// These are not implemented...
@@ -183,18 +256,57 @@
bool
operator==(const XPathEnvSupportDefault&) const;
- // Data members...
-
- // Table for storing source tree documents, which are keyed by
- // URL.
-
#if defined(XALAN_NO_NAMESPACES)
typedef map<XalanDOMString, XalanDocument*> SourceDocsTableType;
+ typedef map<XalanDOMString, Function*> FunctionTableType;
+ typedef map<XalanDOMString, FunctionTableType> NamespaceFunctionTablesType;
#else
typedef std::map<XalanDOMString, XalanDocument*> SourceDocsTableType;
+ typedef std::map<XalanDOMString, Function*> FunctionTableType;
+ typedef std::map<XalanDOMString, FunctionTableType> NamespaceFunctionTablesType;
#endif
+
+ /**
+ * Update the supplied function table. If the parameter
+ * function is 0, and a function with the supplied
+ * namespace and name exists in the table, it will be
+ * removed. If function is not 0, and a function with
+ * the supplied namespace and name exists in the table,
+ * it will be replaced with the new function. Otherwise,
+ * the function will be added.
+ *
+ * @param theNamespace The namespace for the functionl
+ * @param extensionName The name of the function.
+ * @param function The function to install.
+ */
+ static void
+ updateFunctionTable(
+ NamespaceFunctionTablesType& theTable,
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName,
+ const Function* function);
+
+ /**
+ * Find an external function in the supplied table.
+ *
+ * @param theTable The table to search.
+ * @param theNamespace The namespace for the function.
+ * @param extensionName The name of the function.
+ * @return a pointer to the function if found, or 0 if not found.
+ */
+ Function*
+ findFunction(
+ const NamespaceFunctionTablesType& theTable,
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName) const;
+
+ // Data members...
+
+ SourceDocsTableType m_sourceDocs;
+
+ NamespaceFunctionTablesType m_externalFunctions;
- SourceDocsTableType m_sourceDocs;
+ static NamespaceFunctionTablesType s_externalFunctions;
};
1.10 +16 -1 xml-xalan/c/src/XPath/XPathExecutionContext.hpp
Index: XPathExecutionContext.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExecutionContext.hpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XPathExecutionContext.hpp 2000/04/27 15:11:25 1.9
+++ XPathExecutionContext.hpp 2000/05/01 15:11:42 1.10
@@ -53,6 +53,8 @@
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
+ *
+ * @author <a href="mailto:david_n_bertoni@lotus.com">David N. Bertoni</a>
*/
#if !defined(XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680)
#define XPATHEXECUTIONCONTEXT_HEADER_GUARD_1357924680
@@ -188,6 +190,18 @@
getParentOfNode(const XalanNode& n) const = 0;
/**
+ * Determine if a node is after another node, in document order.
+ *
+ * @param node1 The first node
+ * @param node2 The second node
+ * @return true if node1 one is after node2, or false if it is not.
+ */
+ virtual bool
+ isNodeAfter(
+ const XalanNode& node1,
+ const XalanNode& node2) const = 0;
+
+ /**
* Get node data recursively.
* (Note whitespace issues.)
*
@@ -300,7 +314,8 @@
virtual XObject*
extFunction(
const XalanDOMString& theNamespace,
- const XalanDOMString& extensionName,
+ const XalanDOMString& extensionName,
+ XalanNode* context,
const XObjectArgVectorType& argVec) = 0;
/**
1.6 +18 -5 xml-xalan/c/src/XPath/XPathExecutionContextDefault.cpp
Index: XPathExecutionContextDefault.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExecutionContextDefault.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XPathExecutionContextDefault.cpp 2000/04/20 16:32:14 1.5
+++ XPathExecutionContextDefault.cpp 2000/05/01 15:11:42 1.6
@@ -53,6 +53,8 @@
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
+ *
+ * @author <a href="mailto:david_n_bertoni@lotus.com">David N. Bertoni</a>
*/
// Class header file...
@@ -142,6 +144,16 @@
+bool
+XPathExecutionContextDefault::isNodeAfter(
+ const XalanNode& node1,
+ const XalanNode& node2) const
+{
+ return m_xpathSupport.isNodeAfter(node1, node2);
+}
+
+
+
XalanDOMString
XPathExecutionContextDefault::getNodeData(const XalanNode& n) const
{
@@ -238,11 +250,12 @@
XObject*
XPathExecutionContextDefault::extFunction(
- const XalanDOMString& theNamespace,
- const XalanDOMString& extensionName,
- const Function::XObjectArgVectorType& argVec)
+ const XalanDOMString& theNamespace,
+ const XalanDOMString& extensionName,
+ XalanNode* context,
+ const XObjectArgVectorType& argVec)
{
- return m_xpathEnvSupport.extFunction(*this, theNamespace, extensionName, argVec);
+ return m_xpathEnvSupport.extFunction(*this, theNamespace, extensionName, context, argVec);
}
@@ -549,7 +562,7 @@
const DecimalFormatSymbols*
-XPathExecutionContextDefault::getDecimalFormatSymbols(const XalanDOMString& name)
+XPathExecutionContextDefault::getDecimalFormatSymbols(const XalanDOMString& /* name */)
{
return 0;
}
1.8 +18 -10 xml-xalan/c/src/XPath/XPathExecutionContextDefault.hpp
Index: XPathExecutionContextDefault.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExecutionContextDefault.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XPathExecutionContextDefault.hpp 2000/04/20 16:32:14 1.7
+++ XPathExecutionContextDefault.hpp 2000/05/01 15:11:42 1.8
@@ -56,6 +56,8 @@
*
* $ Id: $
*
+ *
+ * @author <a href="mailto:david_n_bertoni@lotus.com">David N. Bertoni</a>
*/
#if !defined(XPATHEXECUTIONCONTEXTDEFAULT_HEADER_GUARD_1357924680)
#define XPATHEXECUTIONCONTEXTDEFAULT_HEADER_GUARD_1357924680
@@ -128,6 +130,11 @@
virtual XalanNode*
getParentOfNode(const XalanNode& n) const;
+ virtual bool
+ isNodeAfter(
+ const XalanNode& node1,
+ const XalanNode& node2) const;
+
virtual XalanDOMString
getNodeData(const XalanNode& n) const;
@@ -168,7 +175,8 @@
virtual XObject*
extFunction(
const XalanDOMString& theNamespace,
- const XalanDOMString& extensionName,
+ const XalanDOMString& extensionName,
+ XalanNode* context,
const XObjectArgVectorType& argVec);
virtual XLocator*
@@ -278,23 +286,23 @@
const XalanNode* sourceNode = 0,
const XalanNode* styleNode = 0) const;
-private:
+protected:
- XPathEnvSupport& m_xpathEnvSupport;
+ XPathEnvSupport& m_xpathEnvSupport;
- XPathSupport& m_xpathSupport;
+ XPathSupport& m_xpathSupport;
- XObjectFactory& m_xobjectFactory;
+ XObjectFactory& m_xobjectFactory;
- XalanNode* m_currentNode;
+ XalanNode* m_currentNode;
- MutableNodeRefList m_contextNodeList;
+ MutableNodeRefList m_contextNodeList;
- const PrefixResolver* m_prefixResolver;
+ const PrefixResolver* m_prefixResolver;
- bool m_throwFoundIndex;
+ bool m_throwFoundIndex;
- XalanDOMString m_currentPattern;
+ XalanDOMString m_currentPattern;
};
1.8 +5 -2 xml-xalan/c/src/XPath/XPathProcessorImpl.cpp
Index: XPathProcessorImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathProcessorImpl.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XPathProcessorImpl.cpp 2000/04/24 22:04:05 1.7
+++ XPathProcessorImpl.cpp 2000/05/01 15:11:42 1.8
@@ -53,7 +53,10 @@
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
+ *
+ * @author <a href="mailto:david_n_bertoni@lotus.com">David N. Bertoni</a>
*/
+
// Class header file...
#include "XPathProcessorImpl.hpp"
@@ -1600,13 +1603,13 @@
XPathExpression::OpCodeMapValueVectorType theArgs(2);
- theArgs[0] = m_expression->getTokenPosition();
+ theArgs[0] = m_expression->getTokenPosition() - 1;
nextToken();
consumeExpected(':');
- theArgs[1] = m_expression->getTokenPosition();
+ theArgs[1] = m_expression->getTokenPosition() - 1;
nextToken();