You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by du...@apache.org on 2008/10/06 01:32:42 UTC
svn commit: r701901 [1/3] - in
/webservices/axis2/branches/c/xpath_integration/axiom: ./ include/ src/
src/om/ src/xpath/ test/xpath/
Author: dumindu
Date: Sun Oct 5 16:32:41 2008
New Revision: 701901
URL: http://svn.apache.org/viewvc?rev=701901&view=rev
Log:
added xpath implementation and build files
Added:
webservices/axis2/branches/c/xpath_integration/axiom/include/xpath.h
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/Makefile.am
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath.c
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_functions.c
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_functions.h
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals.c
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals.h
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_engine.c
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_engine.h
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_iterators.c
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_iterators.h
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_parser.c
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_parser.h
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_streaming.c
webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_streaming.h
webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/
webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.bat
webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.ns
webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.sh
webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.xml
webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.xpath
webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test_linux.c
webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test_windows.c
Modified:
webservices/axis2/branches/c/xpath_integration/axiom/configure.ac
webservices/axis2/branches/c/xpath_integration/axiom/src/Makefile.am
webservices/axis2/branches/c/xpath_integration/axiom/src/om/Makefile.am
Modified: webservices/axis2/branches/c/xpath_integration/axiom/configure.ac
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/configure.ac?rev=701901&r1=701900&r2=701901&view=diff
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/configure.ac (original)
+++ webservices/axis2/branches/c/xpath_integration/axiom/configure.ac Sun Oct 5 16:32:41 2008
@@ -152,6 +152,7 @@
src/om/Makefile \
src/util/Makefile \
src/attachments/Makefile \
+ src/xpath/Makefile \
test/Makefile \
test/om/Makefile \
test/soap/Makefile \
Added: webservices/axis2/branches/c/xpath_integration/axiom/include/xpath.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/include/xpath.h?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/include/xpath.h (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/include/xpath.h Sun Oct 5 16:32:41 2008
@@ -0,0 +1,406 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+
+#ifndef XPATH_H
+#define XPATH_H
+
+#include <axiom.h>
+#include <axis2_util.h>
+#include <axiom_soap.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @defgroup axiom_xpath_api api
+ * @ingroup axiom_xpath
+ * @{
+ */
+
+
+ /**
+ * Enable tracing
+ */
+
+#define AXIOM_XPATH_DEBUG
+
+ /**
+ * An error occured while evaluating the xpath expression
+ */
+#define AXIOM_XPATH_EVALUATION_ERROR 0
+
+#define AXIOM_XPATH_ERROR_STREAMING_NOT_SUPPORTED 10
+
+ /* Typedefs */
+
+ /**
+ * XPath expression
+ * It includes the expression as a string and parsed data.
+ */
+ typedef struct axiom_xpath_expression axiom_xpath_expression_t;
+
+ /**
+ * The XPath context
+ * Keeps a reference to the context node or attribute,
+ * XPath expression, environment and result set.
+ */
+ typedef struct axiom_xpath_context axiom_xpath_context_t;
+
+ /**
+ * XPath result set
+ * Contains the result set and other information such as
+ * whether the expression was evaluated successfully.
+ */
+ typedef struct axiom_xpath_result axiom_xpath_result_t;
+
+ /**
+ * XPath result
+ * Stores type and value of the result.
+ */
+ typedef struct axiom_xpath_result_node axiom_xpath_result_node_t;
+
+ /**
+ * XPath result types
+ */
+ typedef enum axiom_xpath_result_type_t
+ {
+ AXIOM_XPATH_TYPE_NODE = 0,
+ AXIOM_XPATH_TYPE_ATTRIBUTE,
+ AXIOM_XPATH_TYPE_NAMESPACE,
+ AXIOM_XPATH_TYPE_TEXT,
+ AXIOM_XPATH_TYPE_NUMBER,
+ AXIOM_XPATH_TYPE_BOOLEAN
+ } axiom_xpath_result_type_t;
+
+ typedef int (*axiom_xpath_function_t)(axiom_xpath_context_t *context,
+ int np);
+
+ /**
+ * XPath expression
+ */
+ struct axiom_xpath_expression
+ {
+ /** XPath expression as a string */
+ axis2_char_t* expr_str;
+
+ /** Length of the expression */
+ int expr_len;
+
+ /** A cursor pointing to the position currently being parsed */
+ int expr_ptr;
+
+ /** Parsed expression in an array list*/
+ axutil_array_list_t *operations;
+
+ /** A pointer to the start operation in operations */
+ int start;
+ };
+
+ /**
+ * XPath context
+ */
+ struct axiom_xpath_context
+ {
+ /** Environment */
+ axutil_env_t *env;
+
+ /** List of namespaces */
+ axutil_hash_t *namespaces;
+
+ /** Set of functions */
+ axutil_hash_t *functions;
+
+ /** Root node */
+ axiom_node_t *root_node;
+
+ /** Context node */
+ axiom_node_t *node;
+
+ /** Context attribute */
+ axiom_attribute_t *attribute;
+
+ /** Context attribute */
+ axiom_namespace_t *ns;
+
+ /** Context position */
+ int position;
+
+ /** Context size
+ * *Does not work location paths due to optimizations */
+ int size;
+
+ /** XPath expression */
+ axiom_xpath_expression_t *expr;
+
+ /** Streaming */
+ axis2_bool_t streaming;
+
+ /** Stack of processed items */
+ axutil_stack_t *stack;
+
+ /* TODO:
+ functions
+ variables
+ etc */
+ };
+
+ /**
+ * XPath result set
+ */
+ struct axiom_xpath_result
+ {
+ /** A flag indicating whether errors occured while evaluting XPath
+ * expression */
+ int flag;
+
+ /** An array list containing the set of results */
+ axutil_array_list_t * nodes;
+ };
+
+ /**
+ * XPath result
+ */
+ struct axiom_xpath_result_node
+ {
+ /** Type of result */
+ axiom_xpath_result_type_t type;
+
+ /** Value */
+ void * value;
+ };
+
+ /**
+ * Compile an XPath expression
+ *
+ * @param env Environment must not be null
+ * @param xpath_expr A pointer to the XPath expression
+ * @return The parsed XPath expression. Returns NULL if an error occured
+ * while parsing.
+ */
+ axiom_xpath_expression_t * AXIS2_CALL axiom_xpath_compile_expression(
+ const axutil_env_t *env,
+ const axis2_char_t* xpath_expr);
+
+ /**
+ * Create an empty XPath context
+ *
+ * @param env Environment must not be null
+ * @param root_node A pointer to the root of the tree
+ * @return The initialized XPath context.
+ */
+ axiom_xpath_context_t * AXIS2_CALL axiom_xpath_context_create(
+ axutil_env_t *env,
+ axiom_node_t * root_node);
+
+ /**
+ * Evaluate an parsed XPath expression. Different expressions could
+ * be evaluated on the same context, and same expression could be
+ * evaluated on multiple trees without recompiling.
+ *
+ * @param context XPath context must not be null
+ * @param xpath_expr XPath expression to be evaluated
+ * @return The set of results.
+ */
+ axiom_xpath_result_t * AXIS2_CALL axiom_xpath_evaluate(
+ axiom_xpath_context_t *context,
+ axiom_xpath_expression_t *xpath_expr);
+
+
+ /**
+ * Convert an XPath result to a boolean.
+ * If the result is a boolean the value of it is returned.
+ * If the result is a number, AXIS2_TRUE is
+ * returned if the value is not equal to 0 and AXIS2_FALSE otherwise.
+ * Otherwise AXIS2_TRUE is returned if the result is not NULL and AXIS2_FALSE otherwise.
+ *
+ * @param env Environment must not be null
+ * @param node A pointer to the XPath result
+ * @return The boolean value.
+ */
+ axis2_bool_t AXIS2_CALL axiom_xpath_cast_node_to_boolean(
+ const axutil_env_t *env,
+ axiom_xpath_result_node_t * node);
+
+ /**
+ * Convert an XPath result to a number.
+ * If the result is a boolean, 1 is returned if it's true and 0 otherwise.
+ * If the result is a number the value of it is returned.
+ * Otherwise AXIS2_TRUE is returned if the result is not NULL and AXIS2_FALSE otherwise.
+ *
+ * @param env Environment must not be null
+ * @param node A pointer to the XPath result
+ * @return The numerical value.
+ */
+ double AXIS2_CALL axiom_xpath_cast_node_to_number(
+ const axutil_env_t *env,
+ axiom_xpath_result_node_t * node);
+
+ /**
+ * Convert an XPath result to text.
+ * If the result is a boolean, "true" is returned if it's true and "false" otherwise.
+ * If the result is a number the text representation of it is returned.
+ * If the result is a text the value of it is returned.
+ * If the result is an axiom node, the text value of it is returned
+ * If the result is an axiom attribue, the text value of it is returned
+ *
+ * @param env Environment must not be null
+ * @param node A pointer to the XPath result
+ * @return The text value.
+ */
+ axis2_char_t * AXIS2_CALL axiom_xpath_cast_node_to_string(
+ const axutil_env_t *env,
+ axiom_xpath_result_node_t * node);
+
+ /**
+ * Convert an XPath result to an axiom node.
+ * If the result is an axiom node it is returned and NULL otherwise.
+ *
+ * @param env Environment must not be null
+ * @param node A pointer to the XPath result
+ * @return The axiom node.
+ */
+ axiom_node_t * AXIS2_CALL axiom_xpath_cast_node_to_axiom_node(
+ const axutil_env_t *env,
+ axiom_xpath_result_node_t * node);
+
+
+ /**
+ * Free XPath context
+ *
+ * @param env Environment must not be null
+ * @param context XPath context must not be null
+ */
+ void AXIS2_CALL axiom_xpath_free_context(
+ const axutil_env_t *env,
+ axiom_xpath_context_t *context);
+
+ /**
+ * Free XPath expression
+ *
+ * @param env Environment must not be null
+ * @param xpath_expr XPath expression must not be null
+ */
+ void AXIS2_CALL axiom_xpath_free_expression(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t * xpath_expr);
+
+ /**
+ * Free XPath result set
+ *
+ * @param env Environment must not be null
+ * @param result XPath result set must not be null
+ */
+ void AXIS2_CALL axiom_xpath_free_result(
+ const axutil_env_t *env,
+ axiom_xpath_result_t* result);
+
+ /**
+ * Registers a XPath namespace
+ *
+ * @param context XPath Context, must not be null
+ * @param ns AXIOM namespace, must not be null
+ */
+ void AXIS2_CALL axiom_xpath_register_namespace(
+ axiom_xpath_context_t *context,
+ axiom_namespace_t *ns);
+
+ /**
+ * Get a registered namespace by the prefix.
+ * If there is no namespace registered by the given prefix NULL will be returned
+ *
+ * @param context XPath Context, must not be null
+ * @param prefix Prefix of the namespace, must not be null
+ * @return The namespace corresponding to the prefix.
+ */
+ axiom_namespace_t * AXIS2_CALL axiom_xpath_get_namespace(
+ axiom_xpath_context_t *context,
+ axis2_char_t *prefix);
+
+ /**
+ * Clears all registered XPath namespaces
+ *
+ * @param context XPath Context, must not be null
+ */
+ void AXIS2_CALL axiom_xpath_clear_namespaces(
+ axiom_xpath_context_t *context);
+
+ /**
+ * Evaluates an XPath expression on streaming XML.
+ * Not all expressions can be evaluated on streaming XML.
+ * If the expression cannot be evaluated on streaming XML NULL will be returned.
+ *
+ * @param context XPath Context, must not be null
+ * @param xpath_expr XPath expression to be evaluated
+ */
+ axiom_xpath_result_t * AXIS2_CALL axiom_xpath_evaluate_streaming(
+ axiom_xpath_context_t *context,
+ axiom_xpath_expression_t *xpath_expr);
+
+ /**
+ * Checks whether the given expression can be evaluated on streaming XML.
+ * If it is possible AXIS2_TRUE will be retuned; AXIS2_FALSE otherwise.
+ *
+ * @param env Axis2 environment, must not be null
+ * @param expr Complied XPath expression, must not be null
+ * @return A boolean indicating whether the expression can be evaluated on streaming XML.
+ */
+ axis2_bool_t AXIS2_CALL axiom_xpath_streaming_check(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Setup the XPath core function library
+ *
+ * @param context XPath Context, must not be null
+ */
+ void AXIS2_CALL axiom_xpath_register_default_functions_set(
+ axiom_xpath_context_t *context);
+
+ /**
+ * Registers a custom XPath function http://www.w3.org/TR/xpath#corelib
+ *
+ * @param context XPath Context, must not be null
+ * @param name Name of the function, must not be null
+ * @param func Pointer to the function, must not be null
+ */
+ void AXIS2_CALL axiom_xpath_register_function(
+ axiom_xpath_context_t *context,
+ axis2_char_t *name,
+ axiom_xpath_function_t func);
+
+ /**
+ * Retrive a pointer to a registered funciton by the function name.
+ * If there is no function registered by the given name, NULL will be returned.
+ *
+ * @param context XPath Context, must not be null
+ * @param name Name of the function, must not be null
+ * @return The corresponding function.
+ */
+ axiom_xpath_function_t AXIS2_CALL axiom_xpath_get_function(
+ axiom_xpath_context_t *context,
+ axis2_char_t *name);
+
+ /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Modified: webservices/axis2/branches/c/xpath_integration/axiom/src/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/Makefile.am?rev=701901&r1=701900&r2=701901&view=diff
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/Makefile.am (original)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/Makefile.am Sun Oct 5 16:32:41 2008
@@ -1,2 +1 @@
-SUBDIRS = parser attachments soap util om
-
+SUBDIRS = parser attachments soap util om xpath
Modified: webservices/axis2/branches/c/xpath_integration/axiom/src/om/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/om/Makefile.am?rev=701901&r1=701900&r2=701901&view=diff
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/om/Makefile.am (original)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/om/Makefile.am Sun Oct 5 16:32:41 2008
@@ -18,6 +18,7 @@
om_navigator.c
libaxis2_axiom_la_LIBADD = $(top_builddir)/src/soap/libaxis2_soap.la \
+ $(top_builddir)/src/xpath/libaxis2_xpath.la \
$(top_builddir)/src/attachments/libaxis2_attachments.la \
$(top_builddir)/src/util/libaxis2_axiom_util.la \
../parser/${WRAPPER_DIR}/libaxis2_parser.la \
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/Makefile.am?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/Makefile.am (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/Makefile.am Sun Oct 5 16:32:41 2008
@@ -0,0 +1,20 @@
+noinst_LTLIBRARIES = libaxis2_xpath.la
+libaxis2_xpath_la_SOURCES = xpath.c \
+ xpath_functions.c \
+ xpath_internals.c \
+ xpath_internals_engine.c \
+ xpath_internals_iterators.c \
+ xpath_internals_parser.c \
+ xpath_streaming.c
+
+libaxis2_xpath_la_LIBADD =
+INCLUDES = -I$(top_builddir)/include \
+ -I$(top_builddir)/src/parser \
+ -I$(top_builddir)/src/om \
+ -I ../../../util/include \
+ -I ../../../include
+
+EXTRA_DIST = xpath_functions.h xpath_internals_engine.h \
+ xpath_internals.h xpath_internals_iterators.h \
+ xpath_internals_parser.h xpath_streaming.h
+
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath.c?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath.c (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath.c Sun Oct 5 16:32:41 2008
@@ -0,0 +1,414 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+
+#include "xpath.h"
+#include "xpath_internals.h"
+#include "xpath_internals_parser.h"
+#include "xpath_internals_engine.h"
+#include "xpath_functions.h"
+#include "xpath_streaming.h"
+
+/* Create XPath context */
+axiom_xpath_context_t * AXIS2_CALL axiom_xpath_context_create(
+ axutil_env_t *env,
+ axiom_node_t * root_node)
+{
+ axiom_xpath_context_t* context;
+
+ context = AXIS2_MALLOC(env->allocator,
+ sizeof(axiom_xpath_context_t));
+
+ context->env = env;
+ context->root_node = root_node;
+ context->node = root_node;
+ context->expr = NULL;
+ context->attribute = NULL;
+ context->namespaces = NULL;
+ context->functions = NULL;
+
+ axiom_xpath_register_default_functions_set(context);
+
+ return context;
+}
+
+/* Compile XPath expression */
+axiom_xpath_expression_t * AXIS2_CALL axiom_xpath_compile_expression(
+ const axutil_env_t *env,
+ const axis2_char_t* xpath_expr)
+{
+ axiom_xpath_expression_t* expr;
+
+ expr = AXIS2_MALLOC(env->allocator,
+ sizeof(axiom_xpath_expression_t));
+
+ expr->expr_str = axutil_strdup(env, xpath_expr);
+
+ if (axiom_xpath_compile(env, expr) == AXIOM_XPATH_PARSE_ERROR)
+ {
+ AXIS2_FREE(env->allocator, expr->expr_str);
+ AXIS2_FREE(env->allocator, expr);
+
+ return NULL;
+ }
+ else
+ return expr;
+}
+
+/* Evaluate compiled XPath expression */
+axiom_xpath_result_t * AXIS2_CALL axiom_xpath_evaluate(
+ axiom_xpath_context_t *context,
+ axiom_xpath_expression_t *xpath_expr)
+{
+ axiom_xpath_expression_copy(context, xpath_expr);
+
+ context->streaming = AXIS2_FALSE;
+
+ return axiom_xpath_run(context);
+}
+
+axiom_xpath_result_t * AXIS2_CALL axiom_xpath_evaluate_streaming(
+ axiom_xpath_context_t *context,
+ axiom_xpath_expression_t *xpath_expr)
+{
+ axiom_xpath_result_t *res;
+
+ axiom_xpath_expression_copy(context, xpath_expr);
+
+ if (axiom_xpath_streaming_check(context->env, xpath_expr))
+ {
+ context->streaming = AXIS2_TRUE;
+ return axiom_xpath_run(context);
+ }
+ else
+ {
+ res = AXIS2_MALLOC(
+ context->env->allocator, sizeof(axiom_xpath_result_t));
+ res->nodes = NULL;
+ res->flag = AXIOM_XPATH_ERROR_STREAMING_NOT_SUPPORTED;
+
+ return res;
+ }
+}
+
+void AXIS2_CALL axiom_xpath_register_default_functions_set(
+ axiom_xpath_context_t *context)
+{
+ axiom_xpath_register_function(
+ context, "count", axiom_xpath_function_count);
+}
+
+
+void AXIS2_CALL axiom_xpath_register_function(
+ axiom_xpath_context_t *context,
+ axis2_char_t *name,
+ axiom_xpath_function_t func)
+{
+ if (name && func)
+ {
+ if (!context->functions)
+ {
+ context->functions = axutil_hash_make(context->env);
+ }
+
+ axutil_hash_set(context->functions, name, AXIS2_HASH_KEY_STRING, func);
+ }
+}
+
+axiom_xpath_function_t AXIS2_CALL axiom_xpath_get_function(
+ axiom_xpath_context_t *context,
+ axis2_char_t *name)
+{
+ axiom_xpath_function_t func = NULL;
+
+ if(context->functions)
+ {
+ func = axutil_hash_get(context->functions, name, AXIS2_HASH_KEY_STRING);
+ }
+
+ return func;
+}
+
+void AXIS2_CALL axiom_xpath_register_namespace(
+ axiom_xpath_context_t *context,
+ axiom_namespace_t *ns)
+{
+ axis2_char_t *prefix = NULL;
+
+ if (!context->namespaces)
+ {
+ context->namespaces = axutil_hash_make(context->env);
+ }
+
+ prefix = axiom_namespace_get_prefix(ns, context->env);
+
+ if (prefix)
+ {
+ axutil_hash_set(
+ context->namespaces, prefix, AXIS2_HASH_KEY_STRING, ns);
+ }
+}
+
+axiom_namespace_t * AXIS2_CALL axiom_xpath_get_namespace(
+ axiom_xpath_context_t *context,
+ axis2_char_t *prefix)
+{
+ axiom_namespace_t *ns = NULL;
+
+ if(context->namespaces)
+ {
+ ns = axutil_hash_get(context->namespaces, prefix, AXIS2_HASH_KEY_STRING);
+ }
+
+ return ns;
+}
+
+void AXIS2_CALL axiom_xpath_clear_namespaces(axiom_xpath_context_t *context)
+{
+ axutil_hash_index_t *hi;
+ void *val;
+
+ if (context->namespaces)
+ {
+ for (hi = axutil_hash_first(context->namespaces, context->env);
+ hi;
+ hi = axutil_hash_next(context->env, hi))
+ {
+ axutil_hash_this(hi, NULL, NULL, &val);
+ axiom_namespace_free((axiom_namespace_t *)val, context->env);
+ }
+
+ axutil_hash_free(context->namespaces, context->env);
+ }
+
+ context->namespaces = NULL;
+}
+
+/* Cast to boolean */
+axis2_bool_t AXIS2_CALL axiom_xpath_cast_node_to_boolean(
+ const axutil_env_t *env,
+ axiom_xpath_result_node_t * node)
+{
+ if (node->type == AXIOM_XPATH_TYPE_BOOLEAN)
+ {
+ return *(axis2_bool_t *)node->value;
+ }
+ else if (node->type == AXIOM_XPATH_TYPE_NUMBER)
+ {
+ /* Cannot evaluate as *(double *)(node->value) == 1e-12
+ since there might be an precision error */
+ if (*(double *)(node->value) > 1e-12
+ || *(double *)(node->value) < -1e-12)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+ }
+ else if (node->value)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+}
+
+/* Cast to double */
+double AXIS2_CALL axiom_xpath_cast_node_to_number(
+ const axutil_env_t *env,
+ axiom_xpath_result_node_t * node)
+{
+ if (node->type == AXIOM_XPATH_TYPE_BOOLEAN)
+ {
+ if (*(axis2_bool_t *)(node->value) == AXIS2_TRUE)
+ {
+ return 1.0;
+ }
+ else
+ {
+ return 1.0;
+ }
+ }
+ else if (node->type == AXIOM_XPATH_TYPE_NUMBER)
+ {
+ return *(double *)node->value;
+ }
+ else if (node->value)
+ {
+ return 1.0;
+ }
+ else
+ {
+ return 1.0;
+ }
+}
+
+/* Cast to text */
+axis2_char_t * AXIS2_CALL axiom_xpath_cast_node_to_string(
+ const axutil_env_t *env,
+ axiom_xpath_result_node_t * node)
+{
+ axiom_element_t *ele;
+ axis2_char_t *res;
+
+ if (!node->value)
+ {
+ return NULL;
+ }
+
+ if (node->type == AXIOM_XPATH_TYPE_BOOLEAN)
+ {
+ if (*(axis2_bool_t *)(node->value) == AXIS2_TRUE)
+ {
+ return axutil_strdup(env, "true");
+ }
+ else
+ {
+ return axutil_strdup(env, "false");
+ }
+ }
+ else if (node->type == AXIOM_XPATH_TYPE_NUMBER)
+ {
+ /* Allocate 20 bytes */
+ res = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 20);
+
+ sprintf(res, "%lf", *(double *)(node->value));
+
+ return res;
+ }
+ else if (node->type == AXIOM_XPATH_TYPE_TEXT)
+ {
+ return (axis2_char_t *)node->value;
+ }
+ else if (node->type == AXIOM_XPATH_TYPE_NODE)
+ {
+ ele = (axiom_element_t *)axiom_node_get_data_element(
+ (axiom_node_t *)(node->value), env);
+
+ if (ele)
+ {
+ return axiom_element_get_text(
+ ele, env, (axiom_node_t *)(node->value));
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+ else if (node->type == AXIOM_XPATH_TYPE_ATTRIBUTE)
+ {
+ return axiom_attribute_get_value(
+ (axiom_attribute_t *)(node->value), env);
+ }
+ else if (node->type == AXIOM_XPATH_TYPE_NAMESPACE)
+ {
+ return axiom_namespace_get_prefix(
+ (axiom_namespace_t *)(node->value), env);
+ }
+
+ return NULL;
+}
+
+/* Cast to axiom node */
+axiom_node_t * AXIS2_CALL axiom_xpath_cast_node2axiom_node(
+ const axutil_env_t *env,
+ axiom_xpath_result_node_t * node)
+{
+ if (node->type == AXIOM_XPATH_TYPE_NODE && node->value)
+ {
+ return (axiom_node_t *)node->value;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+/* Free context */
+void AXIS2_CALL axiom_xpath_free_context(
+ const axutil_env_t *env,
+ axiom_xpath_context_t *context)
+{
+ if (context)
+ {
+ /* Free the expression if not freed */
+ if (context->expr)
+ {
+ /* axiom_xpath_free_expression(env, context->expr); */
+
+ context->expr = NULL;
+ }
+
+ AXIS2_FREE(env->allocator, context);
+ }
+}
+
+/* Free expression */
+void AXIS2_CALL axiom_xpath_free_expression(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t * xpath_expr)
+{
+ if (xpath_expr)
+ {
+ if (xpath_expr->expr_str)
+ {
+ AXIS2_FREE(env->allocator, xpath_expr->expr_str);
+
+ xpath_expr->expr_str = NULL;
+ }
+
+ AXIS2_FREE(env->allocator, xpath_expr);
+ }
+}
+
+/* Free result set */
+void AXIS2_CALL axiom_xpath_free_result(
+ const axutil_env_t *env,
+ axiom_xpath_result_t* result)
+{
+ if (result)
+ {
+ if (result->nodes)
+ {
+ axutil_array_list_free(result->nodes, env);
+ }
+
+ AXIS2_FREE(env->allocator, result);
+ }
+}
+
+/* Check if the expression can be evaluated on streaming XML */
+axis2_bool_t AXIS2_CALL axiom_xpath_streaming_check(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ axiom_xpath_streaming_t r = AXIOM_XPATH_CHECK(expr->start);
+
+ if (r == AXIOM_XPATH_STREAMING_NOT_SUPPORTED)
+ {
+ return AXIS2_FALSE;
+ }
+ else
+ {
+ return AXIS2_TRUE;
+ }
+}
+
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_functions.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_functions.c?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_functions.c (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_functions.c Sun Oct 5 16:32:41 2008
@@ -0,0 +1,45 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+
+#include "xpath_functions.h"
+#include "xpath.h"
+#include "xpath_internals_engine.h"
+
+int axiom_xpath_function_count(axiom_xpath_context_t *context, int np)
+{
+ axiom_xpath_result_node_t *node;
+ double * v;
+ int i;
+
+ node = AXIS2_MALLOC(
+ context->env->allocator, sizeof(axiom_xpath_result_node_t));
+ v = AXIS2_MALLOC(context->env->allocator, sizeof(double));
+
+ *v = np;
+ node->value = v;
+ node->type = AXIOM_XPATH_TYPE_NUMBER;
+
+ for (i = 0; i < np; i++)
+ {
+ axutil_stack_pop(context->stack, context->env);
+ }
+
+ axutil_stack_push(context->stack, context->env, node);
+
+ return 1;
+}
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_functions.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_functions.h?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_functions.h (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_functions.h Sun Oct 5 16:32:41 2008
@@ -0,0 +1,47 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+
+#ifndef XPATH_FUNCTIONS_H
+#define XPATH_FUNCTIONS_H
+
+#include "xpath.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @defgroup axiom_xpath_functions functions
+ * @ingroup axiom_xpath
+ * @{
+ */
+
+ /**
+ * count(node-set) function
+ * http://www.w3.org/TR/xpath#function-count
+ */
+ int axiom_xpath_function_count(axiom_xpath_context_t *context, int np);
+
+ /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals.c?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals.c (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals.c Sun Oct 5 16:32:41 2008
@@ -0,0 +1,40 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+
+#include "xpath.h"
+#include "xpath_internals.h"
+
+/* Make a copy of the xpath expression */
+void axiom_xpath_expression_copy(
+ axiom_xpath_context_t *context,
+ axiom_xpath_expression_t* expr)
+{
+ int i;
+ axiom_xpath_operation_t *op;
+
+ context->expr = expr;
+
+ /* Set value of pos in every operation to 0 */
+ for (i = 0;
+ i < axutil_array_list_size(expr->operations, context->env);
+ i++)
+ {
+ op = AXIOM_XPATH_OPR_GET(i);
+ op->pos = 0;
+ }
+}
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals.h?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals.h (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals.h Sun Oct 5 16:32:41 2008
@@ -0,0 +1,197 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+
+#ifndef XPATH_INTERNALS_H
+#define XPATH_INTERNALS_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @defgroup axiom_xpath_internals internals
+ * @ingroup axiom_xpath
+ * @{
+ */
+
+
+ /** Get operation at index ind */
+#define AXIOM_XPATH_OPR_GET(ind) (axiom_xpath_operation_t *) \
+ axutil_array_list_get(context->expr->operations, context->env, ind)
+
+ /**
+ * An error has occured while parsing
+ */
+#define AXIOM_XPATH_PARSE_ERROR -2
+
+ /**
+ * XPath expression was successfully compiled
+ */
+#define AXIOM_XPATH_PARSE_SUCCESS 0
+
+ /**
+ * End of expression reached
+ */
+#define AXIOM_XPATH_PARSE_END -1
+
+ /* Types */
+
+ /**
+ * XPath operation
+ * Contains the operands and parameters
+ */
+ typedef struct axiom_xpath_operation axiom_xpath_operation_t;
+
+ /**
+ * XPath node test
+ * Stores the components of a node test
+ */
+ typedef struct axiom_xpath_node_test axiom_xpath_node_test_t;
+
+ /**
+ * Functions to process a XPath operator
+ */
+ typedef int (*axiom_xpath_operator_t)(axiom_xpath_context_t *context,
+ axiom_xpath_operation_t * op);
+
+ /**
+ * Functions to iterate through different XPath axes
+ */
+ typedef int (*axiom_xpath_iterator_t)(axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * XPath node test types
+ */
+ typedef enum axiom_xpath_node_test_type_t
+ {
+ AXIOM_XPATH_NODE_TEST_NONE = 0,
+ AXIOM_XPATH_NODE_TEST_ALL,
+ AXIOM_XPATH_NODE_TYPE_COMMENT,
+ AXIOM_XPATH_NODE_TYPE_NODE,
+ AXIOM_XPATH_NODE_TYPE_PI,
+ AXIOM_XPATH_NODE_TYPE_TEXT,
+ AXIOM_XPATH_NODE_TEST_STANDARD
+ } axiom_xpath_node_test_type_t;
+
+ /**
+ * XPath operations
+ */
+ typedef enum axiom_xpath_operation_type_t
+ {
+ AXIOM_XPATH_OPERATION_ROOT_NODE = 0,
+ AXIOM_XPATH_OPERATION_CONTEXT_NODE,
+ AXIOM_XPATH_OPERATION_NODE_TEST,
+ AXIOM_XPATH_OPERATION_STEP,
+ AXIOM_XPATH_OPERATION_RESULT,
+ AXIOM_XPATH_OPERATION_UNION,
+ AXIOM_XPATH_OPERATION_EQUAL_EXPR,
+ AXIOM_XPATH_OPERATION_PREDICATE,
+ AXIOM_XPATH_OPERATION_LITERAL,
+ AXIOM_XPATH_OPERATION_NUMBER,
+ AXIOM_XPATH_OPERATION_PATH_EXPRESSION,
+ AXIOM_XPATH_OPERATION_FUNCTION_CALL,
+ AXIOM_XPATH_OPERATION_ARGUMENT
+ } axiom_xpath_operation_type_t;
+
+ /**
+ * XPath axes
+ */
+ typedef enum axiom_xpath_axis_t
+ {
+ AXIOM_XPATH_AXIS_NONE = -1,
+ AXIOM_XPATH_AXIS_CHILD,
+ AXIOM_XPATH_AXIS_DESCENDANT,
+ AXIOM_XPATH_AXIS_PARENT,
+ AXIOM_XPATH_AXIS_ANCESTOR,
+ AXIOM_XPATH_AXIS_FOLLOWING_SIBLING,
+ AXIOM_XPATH_AXIS_PRECEDING_SIBLING,
+ AXIOM_XPATH_AXIS_FOLLOWING,
+ AXIOM_XPATH_AXIS_PRECEDING,
+ AXIOM_XPATH_AXIS_ATTRIBUTE,
+ AXIOM_XPATH_AXIS_NAMESPACE,
+ AXIOM_XPATH_AXIS_SELF,
+ AXIOM_XPATH_AXIS_DESCENDANT_OR_SELF,
+ AXIOM_XPATH_AXIS_ANCESTOR_OR_SELF
+ } axiom_xpath_axis_t;
+
+ /**
+ * XPath node test structure
+ */
+ struct axiom_xpath_node_test
+ {
+ /** Node test type */
+ axiom_xpath_node_test_type_t type;
+
+ /** Prefix
+ * NULL if no prefix
+ */
+ axis2_char_t *prefix;
+
+ /** Name */
+ axis2_char_t *name;
+
+ /** Literal for processing instruction (PI) */
+ axis2_char_t *lit;
+ };
+
+ /**
+ * XPath operation structure
+ */
+ struct axiom_xpath_operation
+ {
+ /** Type of operator */
+ axiom_xpath_operation_type_t opr;
+
+ /** Parameters of the operation */
+ void *par1;
+ void *par2;
+
+ /** Position: Used for predicate evaluation
+ */
+ int pos;
+
+ /** Operands pointing to other operations */
+ int op1;
+ int op2;
+ };
+
+ /**
+ * Copies an XPath expression to a context
+ *
+ * No data is duplicated just the reference is assigned.
+ * Some parameters in the expression are reset.
+ * - pos in every operation
+ *
+ * @param context XPath context must not be NULL
+ * @param expr Expression to be copied
+ */
+ void axiom_xpath_expression_copy(
+ axiom_xpath_context_t *context,
+ axiom_xpath_expression_t* expr);
+
+ /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_engine.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_engine.c?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_engine.c (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_engine.c Sun Oct 5 16:32:41 2008
@@ -0,0 +1,1009 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+
+#include "xpath.h"
+#include "xpath_internals.h"
+#include "xpath_internals_engine.h"
+#include "xpath_internals_iterators.h"
+
+/* Evaluates the expath expression */
+axiom_xpath_result_t * axiom_xpath_run(axiom_xpath_context_t *context)
+{
+ axiom_xpath_result_t* res;
+
+ /* Initialize result ret */
+ res = AXIS2_MALLOC(context->env->allocator,
+ sizeof(axiom_xpath_result_t));
+
+ res->flag = 0;
+
+ res->nodes = axutil_array_list_create(context->env, 0);
+
+ context->stack = axutil_stack_create(context->env);
+
+ /* Expression is empty */
+ if (context->expr->start == AXIOM_XPATH_PARSE_END)
+ {
+ return res;
+ }
+
+ axiom_xpath_evaluate_operation(context, context->expr->start);
+
+ /* Add nodes to the result set from the stack */
+ while (axutil_stack_size(context->stack, context->env) > 0)
+ {
+ axutil_array_list_add(
+ res->nodes, context->env,
+ axutil_stack_pop(context->stack, context->env));
+ }
+
+ return res;
+}
+
+/* Casting functions; these make use of the casting functions defined in xpath.h */
+void axiom_xpath_cast_boolean(
+ axiom_xpath_result_node_t *node,
+ axiom_xpath_context_t *context)
+{
+ AXIOM_XPATH_CAST_SET_VALUE(
+ axis2_bool_t, axiom_xpath_cast_node_to_boolean(context->env, node));
+
+ node->type = AXIOM_XPATH_TYPE_BOOLEAN;
+}
+
+void axiom_xpath_cast_number(
+ axiom_xpath_result_node_t *node,
+ axiom_xpath_context_t *context)
+{
+ AXIOM_XPATH_CAST_SET_VALUE(
+ double, axiom_xpath_cast_node_to_number(context->env, node));
+
+ node->type = AXIOM_XPATH_TYPE_NUMBER;
+}
+
+void axiom_xpath_cast_string(
+ axiom_xpath_result_node_t *node,
+ axiom_xpath_context_t *context)
+{
+ node->value = axiom_xpath_cast_node_to_string(context->env, node);
+
+ node->type = AXIOM_XPATH_TYPE_TEXT;
+}
+
+/* Evaluate whether two results are equal
+ TODO: Comment */
+axis2_bool_t axiom_xpath_compare_equal(
+ axiom_xpath_result_node_t *node1,
+ axiom_xpath_result_node_t *node2,
+ axiom_xpath_context_t *context)
+{
+ if (node1->type == AXIOM_XPATH_TYPE_BOOLEAN
+ || node2->type == AXIOM_XPATH_TYPE_BOOLEAN)
+ {
+ axiom_xpath_cast_boolean(node1, context);
+ axiom_xpath_cast_boolean(node2, context);
+
+ if (*(axis2_bool_t*)(node1->value) == *(axis2_bool_t*)(node2->value))
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+ }
+
+ if (node1->type == AXIOM_XPATH_TYPE_NUMBER
+ || node2->type == AXIOM_XPATH_TYPE_NUMBER)
+ {
+ axiom_xpath_cast_number(node1, context);
+ axiom_xpath_cast_number(node2, context);
+
+ if (*(double *)(node1->value) == *(double *)(node2->value))
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+ }
+
+ axiom_xpath_cast_string(node1, context);
+ axiom_xpath_cast_string(node2, context);
+
+ if (axutil_strcmp(
+ (axis2_char_t *)(node1->value),
+ (axis2_char_t *)(node2->value)) == 0)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+}
+
+/* Operators */
+
+/* Literal */
+int axiom_xpath_literal_operator(
+ axiom_xpath_context_t *context,
+ axiom_xpath_operation_t * op)
+{
+ axiom_xpath_result_node_t *node;
+
+ node = AXIS2_MALLOC(context->env->allocator,
+ sizeof(axiom_xpath_result_node_t));
+
+ /* Set the context node to NULL */
+ /* This is not required; it gives some problems */
+ /* context->node = NULL;*/
+
+ node->value = op->par1;
+ node->type = AXIOM_XPATH_TYPE_TEXT;
+
+ axutil_stack_push(context->stack, context->env, node);
+
+ return 1;
+}
+
+/* Number */
+int axiom_xpath_number_operator(
+ axiom_xpath_context_t *context,
+ axiom_xpath_operation_t * op)
+{
+ axiom_xpath_result_node_t *node;
+
+ node = AXIS2_MALLOC(context->env->allocator,
+ sizeof(axiom_xpath_result_node_t));
+
+ /* Set the context node to NULL */
+ /* This is not required; it gives some problems */
+ /* context->node = NULL;*/
+
+ node->value = op->par1;
+ node->type = AXIOM_XPATH_TYPE_NUMBER;
+
+ axutil_stack_push(context->stack, context->env, node);
+
+ return 1;
+}
+
+/* Path Expression */
+int axiom_xpath_path_expression_operator(
+ axiom_xpath_context_t *context,
+ axiom_xpath_operation_t * op)
+{
+ int filter_res_n, n_nodes = 0;
+ axiom_xpath_operation_t *rel_loc_op;
+ axiom_xpath_operator_t rel_loc_func;
+ axutil_array_list_t *arr;
+ axiom_xpath_result_node_t *res_node;
+ int i;
+
+ /* Filter operation */
+ if (op->op1 == AXIOM_XPATH_PARSE_END)
+ {
+ return 0;
+ }
+
+ filter_res_n = axiom_xpath_evaluate_operation(context, op->op1);
+
+ /* Relative location path */
+ if (op->op2 == AXIOM_XPATH_PARSE_END)
+ {
+ return filter_res_n;
+ }
+
+ rel_loc_op = AXIOM_XPATH_OPR_GET(op->op2);
+ rel_loc_func = axiom_xpath_get_operator(rel_loc_op);
+
+ /* Array list to add all results from the filter expression */
+ arr = axutil_array_list_create(context->env, 0);
+
+ for (i = 0; i < filter_res_n; i++)
+ {
+ axutil_array_list_add(
+ arr,
+ context->env,
+ axutil_stack_pop(context->stack, context->env));
+ }
+
+ /* Evaluate relative location path for all results from the
+ filter expression */
+ for (i = 0; i < axutil_array_list_size(arr, context->env); i++)
+ {
+ res_node =
+ (axiom_xpath_result_node_t *)axutil_array_list_get(
+ arr, context->env, i);
+
+ if (res_node->type != AXIOM_XPATH_TYPE_NODE)
+ {
+ continue;
+ }
+
+ context->node = (axiom_node_t *)res_node->value;
+ context->position = i + 1;
+ context->size = filter_res_n;
+
+ n_nodes += rel_loc_func(context, rel_loc_op);
+ }
+
+ return n_nodes;
+}
+
+/* Equal Expression */
+int axiom_xpath_equalexpr_operator(
+ axiom_xpath_context_t *context,
+ axiom_xpath_operation_t * op)
+{
+ axiom_xpath_result_node_t *node;
+ int n_nodes[2];
+ int i, j;
+ int op12[2];
+ axutil_array_list_t *arr[2];
+
+ op12[0] = op->op1;
+ op12[1] = op->op2;
+
+ /* Evaluate both operands and get number of results */
+ for (i = 0; i < 2; i++)
+ {
+ if (op12[i] == AXIOM_XPATH_PARSE_END)
+ {
+ continue;
+ }
+
+ n_nodes[i] = axiom_xpath_evaluate_operation(context, op12[i]);
+ }
+
+
+ for (i = 1; i >= 0; i--)
+ {
+ arr[i] = axutil_array_list_create(context->env, 0);
+
+ for (j = 0; j < n_nodes[i]; j++)
+ {
+ axutil_array_list_add(
+ arr[i],
+ context->env,
+ axutil_stack_pop(context->stack, context->env));
+ }
+ }
+
+ node = AXIS2_MALLOC(context->env->allocator,
+ sizeof(axiom_xpath_result_node_t));
+
+ node->type = AXIOM_XPATH_TYPE_BOOLEAN;
+ node->value = NULL;
+
+ /* Checking equality
+ - If any node from the first set is equal to any node from the second set
+ the result is true */
+ for (i = 0; i < n_nodes[0]; i++)
+ {
+ for (j = 0; j < n_nodes[1]; j++)
+ {
+ if (axiom_xpath_compare_equal(
+ axutil_array_list_get(arr[0], context->env, i),
+ axutil_array_list_get(arr[1], context->env, j),
+ context))
+ {
+ AXIOM_XPATH_CAST_SET_VALUE(axis2_bool_t, AXIS2_TRUE);
+
+ axutil_stack_push(context->stack, context->env, node);
+
+ return 1;
+ }
+ }
+ }
+
+ AXIOM_XPATH_CAST_SET_VALUE(axis2_bool_t, AXIS2_FALSE);
+
+ axutil_stack_push(context->stack, context->env, node);
+
+ return 1;
+}
+
+/* Union */
+int axiom_xpath_union_operator(
+ axiom_xpath_context_t *context,
+ axiom_xpath_operation_t * op)
+{
+ int n_nodes = 0;
+ int i;
+ int op12[2];
+
+ op12[0] = op->op1;
+ op12[1] = op->op2;
+
+ for (i = 0; i < 2; i++)
+ {
+ if (op12[i] == AXIOM_XPATH_PARSE_END)
+ {
+ continue;
+ }
+
+ n_nodes += axiom_xpath_evaluate_operation(context, op12[i]);
+ }
+
+ return n_nodes;
+}
+
+/* Set context node depending on whether relative or absolute location path */
+int axiom_xpath_start_node_operator(
+ axiom_xpath_context_t *context,
+ axiom_xpath_operation_t * op)
+{
+ int n_nodes = 0;
+
+ if (op->op1 == AXIOM_XPATH_PARSE_END)
+ {
+ return 0;
+ }
+
+ if (op->opr == AXIOM_XPATH_OPERATION_ROOT_NODE)
+ {
+ context->node = context->root_node;
+ n_nodes += axiom_xpath_evaluate_operation(context, op->op1);
+ }
+ else if (op->opr == AXIOM_XPATH_OPERATION_CONTEXT_NODE)
+ {
+ n_nodes += axiom_xpath_evaluate_operation(context, op->op1);
+ }
+
+ return n_nodes;
+}
+
+/* Step */
+int axiom_xpath_step_operator(
+ axiom_xpath_context_t *context,
+ axiom_xpath_operation_t * op)
+{
+ axiom_xpath_operation_t * node_test_op;
+ axiom_xpath_iterator_t iter;
+ axiom_xpath_axis_t axis;
+
+ if (op->op1 == AXIOM_XPATH_PARSE_END)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf("Node test operator empty\n");
+#endif
+
+ return AXIOM_XPATH_EVALUATION_ERROR;
+ }
+
+ if (op->op2 == AXIOM_XPATH_PARSE_END)
+ {
+ return 0;
+ }
+
+ /* Get the name */
+ node_test_op = AXIOM_XPATH_OPR_GET(op->op1);
+
+ /* Get the axis */
+ if (!node_test_op->par2)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf("axis is NULL in the step operator\n");
+#endif
+ return AXIOM_XPATH_EVALUATION_ERROR;
+ }
+ axis = *((axiom_xpath_axis_t *)node_test_op->par2);
+
+
+ /* Get the iteration for the axis */
+ iter = axiom_xpath_get_iterator(axis);
+
+ return iter(context,
+ op->op1 /* node test */,
+ op->op2 /* next step */,
+ node_test_op->op1 /* predicate */);
+}
+
+/* Predicates */
+axis2_bool_t axiom_xpath_evaluate_predicate_condition(
+ axiom_xpath_context_t *context,
+ int n_nodes)
+{
+ axiom_xpath_result_node_t *res;
+ int i;
+
+ if (n_nodes <= 0)
+ {
+ return AXIS2_FALSE;
+ }
+ else if (n_nodes > 1)
+ {
+ for (i = 0; i < n_nodes; i++)
+ {
+ axutil_stack_pop(context->stack, context->env);
+ }
+
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ res = (axiom_xpath_result_node_t *)axutil_stack_pop(
+ context->stack, context->env);
+
+ if (res->type == AXIOM_XPATH_TYPE_NUMBER)
+ {
+ if (*(double *)(res->value) == context->position)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FAILURE;
+ }
+ }
+ else if (res->type == AXIOM_XPATH_TYPE_BOOLEAN)
+ {
+ return *(axis2_bool_t *)(res->value);
+ }
+ else
+ {
+ return AXIS2_TRUE;
+ }
+ }
+}
+
+/* Predicate */
+int axiom_xpath_evaluate_predicate(
+ axiom_xpath_context_t *context,
+ int op_next,
+ int op_predicate)
+{
+ int n_res;
+ axis2_bool_t res;
+
+ axiom_xpath_operation_t * pred_op;
+ axiom_node_t *context_node = context->node;
+
+ if (op_predicate == AXIOM_XPATH_PARSE_END)
+ {
+ return axiom_xpath_evaluate_operation(context, op_next);
+ }
+ else
+ {
+ pred_op = AXIOM_XPATH_OPR_GET(op_predicate);
+
+ pred_op->pos++;
+
+ /* Evaluate the predicate */
+ if (pred_op->op1 != AXIOM_XPATH_PARSE_END)
+ {
+ n_res = axiom_xpath_evaluate_operation(context, pred_op->op1);
+ context->position = pred_op->pos;
+
+ res = axiom_xpath_evaluate_predicate_condition(context, n_res);
+ }
+ else
+ {
+ res = AXIS2_TRUE;
+ }
+ /* A PredicateExpr is evaluated by evaluating the Expr and
+ converting the result to a boolean. If the result is a number,
+ the result will be converted to true if the number is equal to the
+ context position and will be converted to false otherwise; if the
+ result is not a number, then the result will be converted as if
+ by a call to the boolean function. */
+
+ /* Transform the result to number or boolean ? */
+
+ if (res)
+ {
+ context->node = context_node;
+
+ return axiom_xpath_evaluate_predicate(
+ context, op_next, pred_op->op2);
+ }
+ }
+
+ return 0;
+}
+
+/* Node test match */
+axis2_bool_t axiom_xpath_node_test_match(
+ axiom_xpath_context_t *context,
+ axiom_xpath_node_test_t *node_test)
+{
+ axiom_types_t type;
+ axiom_element_t *element = NULL;
+ axis2_char_t *name = NULL;
+ axiom_namespace_t *ns = NULL, *xpath_ns = NULL;
+
+ if (!context->node && !context->attribute && !context->ns)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf("Both context node and attribute are NULL.");
+ printf(" May be a literal or a number.\n");
+#endif
+ return AXIS2_FALSE;
+ }
+ else if (context->node)
+ {
+ /* Test if the node matches */
+ type = axiom_node_get_node_type(context->node, context->env);
+
+ if (type == AXIOM_ELEMENT)
+ {
+ element = axiom_node_get_data_element(
+ context->node, context->env);
+
+ name = axiom_element_get_localname(
+ element, context->env);
+
+ ns = axiom_element_get_namespace(
+ element, context->env, context->node);
+ }
+
+ if (node_test->type == AXIOM_XPATH_NODE_TEST_NONE)
+ {
+ return AXIS2_FALSE;
+ }
+ else
+ {
+ if (node_test->type == AXIOM_XPATH_NODE_TEST_ALL
+ || node_test->type == AXIOM_XPATH_NODE_TEST_STANDARD)
+ {
+ if (type != AXIOM_ELEMENT)
+ {
+ return AXIS2_FALSE;
+ }
+
+ /* Check namespace */
+ if (node_test->type == AXIOM_XPATH_NODE_TEST_ALL)
+ {
+ if (!ns && node_test->prefix)
+ {
+ return AXIS2_FALSE;
+ }
+ }
+ else
+ {
+ if ((ns && !node_test->prefix)
+ || (!ns && node_test->prefix))
+ {
+ return AXIS2_FALSE;
+ }
+ }
+
+ if (ns && node_test->prefix)
+ {
+ xpath_ns =
+ axiom_xpath_get_namespace(context, node_test->prefix);
+
+ if (!xpath_ns)
+ {
+ return AXIS2_FALSE;
+ }
+
+ if (axutil_strcmp(
+ axiom_namespace_get_uri(ns, context->env),
+ axiom_namespace_get_uri(xpath_ns, context->env)))
+ {
+ return AXIS2_FALSE;
+ }
+ }
+
+ /* Check local name */
+ if (node_test->type == AXIOM_XPATH_NODE_TEST_ALL)
+ {
+ return AXIS2_TRUE;
+ }
+ else if (node_test->type == AXIOM_XPATH_NODE_TEST_STANDARD)
+ {
+ if (name && axutil_strcmp(node_test->name, name) == 0)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+ }
+ }
+ else if (node_test->type == AXIOM_XPATH_NODE_TYPE_COMMENT)
+ {
+ if (type == AXIOM_COMMENT)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+ }
+ else if (node_test->type == AXIOM_XPATH_NODE_TYPE_PI)
+ {
+ if (type == AXIOM_PROCESSING_INSTRUCTION)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+ }
+ else if (node_test->type == AXIOM_XPATH_NODE_TYPE_NODE)
+ {
+ if (type == AXIOM_ELEMENT)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+ }
+ else if (node_test->type == AXIOM_XPATH_NODE_TYPE_TEXT)
+ {
+ if (type == AXIOM_TEXT)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+ }
+ }
+ }
+ /* Attributes */
+ else if (context->attribute)
+ {
+ name = axiom_attribute_get_localname(context->attribute, context->env);
+ ns = axiom_attribute_get_namespace(context->attribute, context->env);
+
+ if (node_test->type == AXIOM_XPATH_NODE_TEST_NONE)
+ {
+ return AXIS2_FALSE;
+ }
+ else
+ {
+ /* Check namespace */
+ if (node_test->type == AXIOM_XPATH_NODE_TEST_ALL)
+ {
+ if (!ns && node_test->prefix)
+ {
+ return AXIS2_FALSE;
+ }
+ }
+ else
+ {
+ if ((ns && !node_test->prefix) || (!ns && node_test->prefix))
+ {
+ return AXIS2_FALSE;
+ }
+ }
+
+ if (ns && node_test->prefix)
+ {
+ xpath_ns =
+ axiom_xpath_get_namespace(context, node_test->prefix);
+
+ if (!xpath_ns)
+ {
+ return AXIS2_FALSE;
+ }
+
+ if (axutil_strcmp(axiom_namespace_get_uri(ns, context->env),
+ axiom_namespace_get_uri(xpath_ns, context->env)))
+ {
+ return AXIS2_FALSE;
+ }
+ }
+
+ /* Check local name */
+ if (node_test->type == AXIOM_XPATH_NODE_TEST_ALL)
+ {
+ return AXIS2_TRUE;
+ }
+ else if (node_test->type == AXIOM_XPATH_NODE_TEST_STANDARD)
+ {
+ if (name && axutil_strcmp(node_test->name, name) == 0)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+ }
+ }
+ }
+
+ /* Namespace */
+ else if (context->ns)
+ {
+ /* Prefix is checked ??? If changed to uri the cast
+ method in xpath.c needs to be changed as well */
+ name = axiom_namespace_get_prefix(context->ns, context->env);
+ ns = NULL;
+
+ if (node_test->type == AXIOM_XPATH_NODE_TEST_NONE)
+ {
+ return AXIS2_FALSE;
+ }
+ else
+ {
+ /* Check namespace */
+ if (node_test->type == AXIOM_XPATH_NODE_TEST_ALL)
+ {
+ if (!ns && node_test->prefix)
+ {
+ return AXIS2_FALSE;
+ }
+ }
+ else
+ {
+ if ((ns && !node_test->prefix) || (!ns && node_test->prefix))
+ {
+ return AXIS2_FALSE;
+ }
+ }
+
+ if (ns && node_test->prefix)
+ {
+ xpath_ns =
+ axiom_xpath_get_namespace(context, node_test->prefix);
+
+ if (!xpath_ns)
+ {
+ return AXIS2_FALSE;
+ }
+
+ if (axutil_strcmp(axiom_namespace_get_uri(ns, context->env),
+ axiom_namespace_get_uri(xpath_ns, context->env)))
+ {
+ return AXIS2_FALSE;
+ }
+ }
+
+ /* Check local name */
+ if (node_test->type == AXIOM_XPATH_NODE_TEST_ALL)
+ {
+ return AXIS2_TRUE;
+ }
+ else if (node_test->type == AXIOM_XPATH_NODE_TEST_STANDARD)
+ {
+ if (name && axutil_strcmp(node_test->name, name) == 0)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ return AXIS2_FALSE;
+ }
+ }
+ }
+ }
+
+ return AXIS2_FALSE;
+}
+
+int axiom_xpath_function_call_operator(
+ axiom_xpath_context_t *context,
+ axiom_xpath_operation_t * op)
+{
+ axiom_xpath_function_t func = axiom_xpath_get_function(context, op->par1);
+ int n_args = 0;
+
+ if (!func)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf("Function %s not found\n", op->par1);
+#endif
+
+ return AXIOM_XPATH_EVALUATION_ERROR;
+ }
+
+ if (op->op1 != AXIOM_XPATH_PARSE_END)
+ {
+ n_args = axiom_xpath_evaluate_operation(context, op->op1);
+ }
+
+ return func(context, n_args);
+}
+
+int axiom_xpath_argument_operator(
+ axiom_xpath_context_t *context,
+ axiom_xpath_operation_t * op)
+{
+ int n_args = 0;
+
+ if (op->op1 != AXIOM_XPATH_PARSE_END)
+ {
+ n_args += axiom_xpath_evaluate_operation(context, op->op1);
+ }
+
+ if (op->op2 != AXIOM_XPATH_PARSE_END)
+ {
+ n_args += axiom_xpath_evaluate_operation(context, op->op1);
+ }
+
+ return n_args;
+}
+
+/* Collect the current node to the results list */
+int axiom_xpath_collect_operator(
+ axiom_xpath_context_t *context,
+ axiom_xpath_operation_t * op)
+{
+ axiom_xpath_result_node_t *node;
+
+ node = AXIS2_MALLOC(context->env->allocator,
+ sizeof(axiom_xpath_result_node_t));
+
+ if (context->node)
+ {
+ if (context->streaming)
+ {
+ node->value = axiom_node_detach(context->node, context->env);
+ }
+ else
+ {
+ node->value = context->node;
+ }
+ node->type = AXIOM_XPATH_TYPE_NODE;
+ }
+ else if (context->attribute)
+ {
+ if (context->streaming)
+ {
+ node->value =
+ axiom_attribute_clone(context->attribute, context->env);
+ }
+ else
+ {
+ node->value = context->attribute;
+ }
+ node->type = AXIOM_XPATH_TYPE_ATTRIBUTE;
+ }
+ else if (context->ns)
+ {
+ if (context->streaming)
+ {
+ node->value = axiom_namespace_clone(context->ns, context->env);
+ }
+ else
+ {
+ node->value = context->ns;
+ }
+ node->type = AXIOM_XPATH_TYPE_NAMESPACE;
+ }
+
+ axutil_stack_push(context->stack, context->env, node);
+
+ return 1;
+}
+
+/* Returns a pointer to the respective processing function */
+axiom_xpath_operator_t axiom_xpath_get_operator(axiom_xpath_operation_t * op)
+{
+ switch (op->opr)
+ {
+ case AXIOM_XPATH_OPERATION_STEP:
+ return axiom_xpath_step_operator;
+
+ case AXIOM_XPATH_OPERATION_ROOT_NODE:
+ case AXIOM_XPATH_OPERATION_CONTEXT_NODE:
+ return axiom_xpath_start_node_operator;
+
+ case AXIOM_XPATH_OPERATION_RESULT:
+ return axiom_xpath_collect_operator;
+
+ case AXIOM_XPATH_OPERATION_UNION:
+ return axiom_xpath_union_operator;
+
+ case AXIOM_XPATH_OPERATION_EQUAL_EXPR:
+ return axiom_xpath_equalexpr_operator;
+
+ case AXIOM_XPATH_OPERATION_LITERAL:
+ return axiom_xpath_literal_operator;
+
+ case AXIOM_XPATH_OPERATION_NUMBER:
+ return axiom_xpath_number_operator;
+
+ case AXIOM_XPATH_OPERATION_PATH_EXPRESSION:
+ return axiom_xpath_path_expression_operator;
+
+ case AXIOM_XPATH_OPERATION_FUNCTION_CALL:
+ return axiom_xpath_function_call_operator;
+
+ case AXIOM_XPATH_OPERATION_ARGUMENT:
+ return axiom_xpath_argument_operator;
+
+ default:
+#ifdef AXIOM_XPATH_DEBUG
+ printf("Unidentified operation.\n");
+#endif
+
+ return NULL;
+ }
+}
+
+/* Returns a pointer to the respective processing function */
+axiom_xpath_iterator_t axiom_xpath_get_iterator(axiom_xpath_axis_t axis)
+{
+ switch (axis)
+ {
+ case AXIOM_XPATH_AXIS_CHILD:
+ return axiom_xpath_child_iterator;
+
+ case AXIOM_XPATH_AXIS_DESCENDANT:
+ return axiom_xpath_descendant_iterator;
+
+ case AXIOM_XPATH_AXIS_PARENT:
+ return axiom_xpath_parent_iterator;
+
+ case AXIOM_XPATH_AXIS_ANCESTOR:
+ return axiom_xpath_ancestor_iterator;
+
+ case AXIOM_XPATH_AXIS_FOLLOWING_SIBLING:
+ return axiom_xpath_following_sibling_iterator;
+
+ case AXIOM_XPATH_AXIS_PRECEDING_SIBLING:
+ return axiom_xpath_preceding_sibling_iterator;
+
+ case AXIOM_XPATH_AXIS_FOLLOWING:
+ return axiom_xpath_following_iterator;
+
+ case AXIOM_XPATH_AXIS_PRECEDING:
+ return axiom_xpath_preceding_iterator;
+
+ case AXIOM_XPATH_AXIS_ATTRIBUTE:
+ return axiom_xpath_attribute_iterator;
+
+ case AXIOM_XPATH_AXIS_NAMESPACE:
+ return axiom_xpath_namespace_iterator;
+
+ case AXIOM_XPATH_AXIS_SELF:
+ return axiom_xpath_self_iterator;
+
+ case AXIOM_XPATH_AXIS_DESCENDANT_OR_SELF:
+ return axiom_xpath_descendant_self_iterator;
+
+ case AXIOM_XPATH_AXIS_ANCESTOR_OR_SELF:
+ return axiom_xpath_ancestor_self_iterator;
+
+ default:
+#ifdef AXIOM_XPATH_DEBUG
+ printf("Unidentified axis.\n");
+#endif
+
+ return NULL;
+ }
+}
+
+int axiom_xpath_evaluate_operation(axiom_xpath_context_t *context, int op)
+{
+ axiom_xpath_operation_t * operation;
+ axiom_xpath_operator_t function;
+
+ /* Get a pointer to the operation */
+ operation = AXIOM_XPATH_OPR_GET(op);
+
+ /* Get the funciton which processes the operations */
+ function = axiom_xpath_get_operator(operation);
+
+ return function(context, operation);
+}
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_engine.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_engine.h?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_engine.h (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_engine.h Sun Oct 5 16:32:41 2008
@@ -0,0 +1,234 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+
+#ifndef XPATH_INTERNALS_ENGINE_H
+#define XPATH_INTERNALS_ENGINE_H
+
+#include "xpath_internals.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @defgroup axiom_xpath_engine engine
+ * @ingroup axiom_xpath
+ * @{
+ */
+
+
+ /* Macros */
+
+ /** Set node->value to _value */
+#define AXIOM_XPATH_CAST_SET_VALUE(type, _value) { \
+ type * _var; \
+ if(node->value) { AXIS2_FREE(context->env->allocator, node->value); } \
+ _var = AXIS2_MALLOC(context->env->allocator, sizeof(type)); \
+ *_var = _value; \
+ node->value = (void *) _var; \
+}
+
+ /* Functions */
+
+ /**
+ * Evaluate an XPath context, which containes a parsed expression
+ *
+ * @param context XPath context
+ * @return Result set
+ */
+ axiom_xpath_result_t* axiom_xpath_run(axiom_xpath_context_t *context);
+
+ /**
+ * Finds the operator function for a given operation
+ *
+ * @param op Operation
+ * @return Pointer to the function which process the given operation
+ */
+ axiom_xpath_operator_t axiom_xpath_get_operator(axiom_xpath_operation_t * op);
+
+ /**
+ * Get the iterotor for give axis
+ *
+ * @param axis XPath axis
+ * @return Pointer to the function which iterater through the given axis
+ */
+ axiom_xpath_iterator_t axiom_xpath_get_iterator(axiom_xpath_axis_t axis);
+
+ /* Operators */
+
+ /**
+ * Select the start node depending on whether it is an absolute or relative location path
+ *
+ * @param context XPath context
+ * @param op XPath operation
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_start_node_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
+
+ /**
+ * Add the context node or attribute to the results stack
+ *
+ * @param context XPath context
+ * @param op XPath operation
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_collect_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
+
+ /**
+ * Process union operator
+ *
+ * @param context XPath context
+ * @param op XPath operation
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_union_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
+
+ /**
+ * Perform equality test operation
+ *
+ * @param context XPath context
+ * @param op XPath operation
+ * @return Number of nodes added to the stack; which is one
+ */
+ int axiom_xpath_equalexpr_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
+
+ /**
+ * Evaluate function call operation
+ *
+ * @param context XPath context
+ * @param op XPath operation
+ * @return Number of nodes added to the stack; which is one
+ */
+ int axiom_xpath_function_call_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
+
+ /**
+ * Evaluate argument operation
+ *
+ * @param context XPath context
+ * @param op XPath operation
+ * @return Number of nodes added to the stack; which is one
+ */
+ int axiom_xpath_argument_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
+
+ /**
+ * Process a path expression
+ *
+ * @param context XPath context
+ * @param op XPath operation
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_path_expression_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
+
+ /**
+ * Process a number; push the value to the stack
+ *
+ * @param context XPath context
+ * @param op XPath operation
+ * @return Number of nodes added to the stack; which is one
+ */
+ int axiom_xpath_number_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
+
+ /**
+ * Process a literal; push the string to the stack
+ *
+ * @param context XPath context
+ * @param op XPath operation
+ * @return Number of nodes added to the stack; which is one
+ */
+ int axiom_xpath_literal_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
+
+
+ /**
+ * Converts an XPath result to a boolean result
+ *
+ * @param node Result
+ * @param context XPath context
+ */
+ void axiom_xpath_cast_boolean(axiom_xpath_result_node_t *node, axiom_xpath_context_t *context);
+
+ /**
+ * Converts an XPath result to a number
+ *
+ * @param node Result
+ * @param context XPath context
+ */
+ void axiom_xpath_cast_number(axiom_xpath_result_node_t *node, axiom_xpath_context_t *context);
+
+ /**
+ * Converts an XPath result to a string
+ *
+ * @param node Result
+ * @param context XPath context
+ */
+ void axiom_xpath_cast_string(axiom_xpath_result_node_t *node, axiom_xpath_context_t *context);
+
+ /**
+ * Test if two result nodes are equal
+ *
+ * @param node1 First node
+ * @param node2 Second node
+ * @param context XPath context
+ * @return AXIS2_TRUE if equal; AXIS2_FALSE otherwise
+ */
+ axis2_bool_t axiom_xpath_compare_equal(axiom_xpath_result_node_t *node1, axiom_xpath_result_node_t *node2, axiom_xpath_context_t *context);
+
+ /**
+ * Test if the axiom node matches node test
+ *
+ * @param context XPath context
+ * @param node_test Node test
+ * @return AXIS2_TRUE if matches; AXIS2_FALSE otherwise
+ */
+ axis2_bool_t axiom_xpath_node_test_match(axiom_xpath_context_t *context, axiom_xpath_node_test_t *node_test);
+
+ /**
+ * Evaluate if the predicate is true
+ *
+ * @param context XPath context
+ * @param n_nodes Number of results after evaluating the expression in the predicate
+ * @return AXIS2_TRUE if matches; AXIS2_FALSE otherwise
+ */
+ axis2_bool_t axiom_xpath_evaluate_predicate_condition(axiom_xpath_context_t *context, int n_nodes);
+
+ /**
+ * Evaluate if the predicate(s) is true using axiom_xpath_evaluate_predicate_condition and executes the operation op_next
+ *
+ * @param context XPath context
+ * @param op_next The operation to be executed if all predicates are true
+ * @param op_predicate Reference to predicate
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_evaluate_predicate(axiom_xpath_context_t *context, int op_next, int op_predicate);
+
+ /**
+ * Evaluate operation pointed by op
+ *
+ * @param context XPath context
+ * @param op The index of the operation in the operations list
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_evaluate_operation(axiom_xpath_context_t *context, int op);
+
+ /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif