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 [2/3] - in
/webservices/axis2/branches/c/xpath_integration/axiom: ./ include/ src/
src/om/ src/xpath/ test/xpath/
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_iterators.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_iterators.c?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_iterators.c (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_iterators.c Sun Oct 5 16:32:41 2008
@@ -0,0 +1,607 @@
+
+/*
+ * 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"
+
+
+/* child */
+int axiom_xpath_child_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes_tot = 0;
+ int n_nodes;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_node_t *cur = NULL;
+ axiom_node_t *context_node = NULL;
+ /* For streaming */
+ axiom_node_t *prev = NULL;
+ axiom_xpath_operation_t * next_operation = NULL;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+ cur = axiom_node_get_first_child(context->node, context->env);
+
+ while (cur != NULL)
+ {
+ n_nodes = 0;
+ context->node = cur;
+ prev = cur;
+ cur = axiom_node_get_next_sibling(cur, context->env);
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes =
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ n_nodes_tot += n_nodes;
+ }
+
+ if (context->streaming)
+ {
+ if (n_nodes)
+ {
+ next_operation = AXIOM_XPATH_OPR_GET(op_next);
+ }
+
+ if (!n_nodes
+ || next_operation->opr != AXIOM_XPATH_OPERATION_RESULT)
+ {
+ axiom_node_detach(prev, context->env);
+ axiom_node_free_tree(prev, context->env);
+ }
+ }
+ }
+
+ /* Change the context node back to what it was */
+ context->node = context_node;
+
+ return n_nodes_tot;
+}
+
+/* descendant */
+int axiom_xpath_descendant_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_node_t *child = NULL;
+ axiom_node_t *context_node = NULL;
+ axutil_stack_t *stack;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+
+ /* Setting up the stack */
+ stack = axutil_stack_create(context->env);
+
+ child = axiom_node_get_first_child(context->node, context->env);
+ while (child)
+ {
+ axutil_stack_push(stack, context->env, child);
+ child = axiom_node_get_first_child(child, context->env);
+ }
+
+ /* Processing nodes */
+ while (axutil_stack_size(stack, context->env) > 0)
+ {
+ child = (axiom_node_t *)axutil_stack_pop(stack, context->env);
+
+ context->node = child;
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+
+ child = axiom_node_get_next_sibling(child, context->env);
+ while (child)
+ {
+ axutil_stack_push(stack, context->env, child);
+ child = axiom_node_get_first_child(child, context->env);
+ }
+ }
+
+ context->node = context_node;
+
+ return n_nodes;
+}
+
+/* parent */
+int axiom_xpath_parent_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_node_t *parent = NULL;
+ axiom_node_t *context_node = NULL;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+
+ parent = axiom_node_get_parent(context->node, context->env);
+
+ if (parent != NULL)
+ {
+ context->node = parent;
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes =
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+ }
+
+ /* Change the context node back to what it was */
+ context->node = context_node;
+
+ return n_nodes;
+}
+
+/* ancestor axis */
+int axiom_xpath_ancestor_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_node_t *cur = NULL;
+ axiom_node_t *context_node = NULL;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+ cur = axiom_node_get_parent(context->node, context->env);
+
+ while (cur != NULL)
+ {
+ context->node = cur;
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+
+ cur = axiom_node_get_parent(cur, context->env);
+ }
+
+ /* Change the context node back to what it was */
+ context->node = context_node;
+
+ return n_nodes;
+}
+
+/* following-sibling axis */
+int axiom_xpath_following_sibling_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_node_t *cur = NULL;
+ axiom_node_t *context_node = NULL;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+ cur = axiom_node_get_next_sibling(context->node, context->env);
+
+ while (cur != NULL)
+ {
+ context->node = cur;
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+
+ cur = axiom_node_get_next_sibling(cur, context->env);
+ }
+
+ /* Change the context node back to what it was */
+ context->node = context_node;
+
+ return n_nodes;
+}
+
+/* preceding-sibling axis */
+int axiom_xpath_preceding_sibling_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_node_t *cur = NULL;
+ axiom_node_t *context_node = NULL;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+ cur = axiom_node_get_previous_sibling(context->node, context->env);
+
+ while (cur != NULL)
+ {
+ context->node = cur;
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+
+ cur = axiom_node_get_previous_sibling(cur, context->env);
+ }
+
+ /* Change the context node back to what it was */
+ context->node = context_node;
+
+ return n_nodes;
+}
+
+/* following */
+int axiom_xpath_following_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_node_t *child = NULL, *parent = NULL;
+ axiom_node_t *context_node = NULL;
+ axutil_stack_t *stack;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+
+ /* Setting up the stack */
+ stack = axutil_stack_create(context->env);
+ axutil_stack_push(stack, context->env, context->node);
+
+ parent = context->node;
+
+ while (parent)
+ {
+ axutil_stack_push(stack, context->env, parent);
+
+ while (axutil_stack_size(stack, context->env) > 0)
+ {
+ child = (axiom_node_t *)axutil_stack_pop(stack, context->env);
+
+ child = axiom_node_get_next_sibling(child, context->env);
+
+ while (child)
+ {
+ context->node = child;
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+
+ axutil_stack_push(stack, context->env, child);
+ child = axiom_node_get_first_child(child, context->env);
+ }
+ }
+ parent = axiom_node_get_parent(parent, context->env);
+ }
+
+ /* Change the context node back to what it was */
+ context->node = context_node;
+
+ return n_nodes;
+}
+
+/* preceding */
+int axiom_xpath_preceding_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_node_t *child = NULL, *parent = NULL;
+ axiom_node_t *context_node = NULL;
+ axutil_stack_t *stack;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+
+ /* Setting up the stack */
+ stack = axutil_stack_create(context->env);
+
+ parent = context->node;
+
+ while (parent)
+ {
+ axutil_stack_push(stack, context->env, parent);
+
+ while (axutil_stack_size(stack, context->env) > 0)
+ {
+ child = (axiom_node_t *)axutil_stack_pop(stack, context->env);
+
+ child = axiom_node_get_previous_sibling(child, context->env);
+
+ while (child)
+ {
+ context->node = child;
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+
+ axutil_stack_push(stack, context->env, child);
+
+ child = axiom_node_get_last_child(child, context->env);
+ }
+ }
+ parent = axiom_node_get_parent(parent, context->env);
+ }
+
+ /* Change the context node back to what it was */
+ context->node = context_node;
+
+ return n_nodes;
+}
+
+/* attribute axis */
+int axiom_xpath_attribute_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_types_t type;
+ axiom_node_t *context_node = NULL;
+ axiom_element_t *element;
+ axutil_hash_t *ht;
+ axutil_hash_index_t *hi;
+ void *key;
+ axis2_ssize_t klen;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+
+ type = axiom_node_get_node_type(context_node, context->env);
+
+ if (type != AXIOM_ELEMENT)
+ {
+ return 0;
+ }
+
+ element = axiom_node_get_data_element(context_node, context->env);
+
+ context->node = NULL;
+
+ ht = axiom_element_get_all_attributes(element, context->env);
+
+ if (ht)
+ {
+ for (hi = axutil_hash_first(ht, context->env);
+ hi;
+ hi = axutil_hash_next(context->env, hi))
+ {
+ axutil_hash_this(hi, &key, &klen, (void **)&context->attribute);
+
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+ }
+ }
+
+ context->node = context_node;
+ context->attribute = NULL;
+
+ return n_nodes;
+}
+
+/* namespace axis */
+int axiom_xpath_namespace_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_types_t type;
+ axiom_node_t *context_node = NULL;
+ axiom_element_t *element;
+ axutil_hash_t *ht;
+ axutil_hash_index_t *hi;
+ void *key;
+ axis2_ssize_t klen;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+
+ type = axiom_node_get_node_type(context_node, context->env);
+
+ if (type != AXIOM_ELEMENT)
+ {
+ return 0;
+ }
+
+ element = axiom_node_get_data_element(context_node, context->env);
+
+ context->node = NULL;
+
+ ht = axiom_element_get_namespaces(element, context->env);
+
+ if (ht)
+ {
+ for (hi = axutil_hash_first(ht, context->env);
+ hi;
+ hi = axutil_hash_next(context->env, hi))
+ {
+ axutil_hash_this(hi, &key, &klen, (void **)&context->ns);
+
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+ }
+ }
+
+ context->node = context_node;
+ context->ns = NULL;
+
+ return n_nodes;
+}
+
+/* self axis */
+int axiom_xpath_self_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_node_t *context_node = NULL;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+
+ context->node = context_node;
+
+ return n_nodes;
+}
+
+/* descendant-or-self axis */
+int axiom_xpath_descendant_self_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_node_t *child = NULL;
+ axiom_node_t *context_node = NULL;
+ axutil_stack_t *stack;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+
+ /* Setting up the stack */
+ stack = axutil_stack_create(context->env);
+
+ child = axiom_node_get_first_child(context->node, context->env);
+ while (child)
+ {
+ axutil_stack_push(stack, context->env, child);
+ child = axiom_node_get_first_child(child, context->env);
+ }
+
+ /* Processing nodes */
+ while (axutil_stack_size(stack, context->env) > 0)
+ {
+ child = (axiom_node_t *)axutil_stack_pop(stack, context->env);
+
+ context->node = child;
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+
+ child = axiom_node_get_next_sibling(child, context->env);
+ while (child)
+ {
+ axutil_stack_push(stack, context->env, child);
+ child = axiom_node_get_first_child(child, context->env);
+ }
+ }
+
+ /* Change the context node back to what it was */
+ context->node = context_node;
+
+ return n_nodes;
+}
+
+/* ancestor-or-self axis */
+int axiom_xpath_ancestor_self_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate)
+{
+ int n_nodes = 0;
+ axiom_xpath_operation_t * node_test_op;
+ axiom_node_t *parent = NULL;
+ axiom_node_t *context_node = NULL;
+
+ AXIOM_XPATH_ITERATOR_INITIALIZE;
+
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+
+ parent = axiom_node_get_parent(context->node, context->env);
+
+ while (parent != NULL)
+ {
+ context->node = parent;
+ if (axiom_xpath_node_test_match(
+ context, (axiom_xpath_node_test_t *)node_test_op->par1))
+ {
+ n_nodes +=
+ axiom_xpath_evaluate_predicate(context, op_next, op_predicate);
+ }
+
+ parent = axiom_node_get_parent(parent, context->env);
+ }
+
+ /* Change the context node back to what it was */
+ context->node = context_node;
+
+ return n_nodes;
+}
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_iterators.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_iterators.h?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_iterators.h (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_iterators.h Sun Oct 5 16:32:41 2008
@@ -0,0 +1,298 @@
+
+/*
+ * 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_ITERATORS_H
+#define XPATH_INTERNALS_ITERATORS_H
+
+#include "xpath.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @defgroup axiom_xpath_iterators iterators
+ * @ingroup axiom_xpath
+ * @{
+ */
+
+
+#ifdef AXIOM_XPATH_DEBUG
+#define AXIOM_XPATH_ITERATOR_INITIALIZE { \
+ if(!context->node) { \
+ printf("Context node NULL; cannot evaluate self or descendent axis.\n"); \
+ return AXIOM_XPATH_EVALUATION_ERROR; } \
+ node_test_op = AXIOM_XPATH_OPR_GET(op_node_test); \
+ if(!node_test_op) { \
+ printf("Node test not present.\n"); \
+ return AXIOM_XPATH_EVALUATION_ERROR; } \
+ context_node = context->node; \
+}
+#else
+#define AXIOM_XPATH_ITERATOR_INITIALIZE { \
+ if(!context->node) { \
+ return AXIOM_XPATH_EVALUATION_ERROR; } \
+ node_test_op = AXIOM_XPATH_OPR_GET(op_node_test); \
+ if(!node_test_op) { \
+ return AXIOM_XPATH_EVALUATION_ERROR; } \
+ context_node = context->node; \
+}
+#endif
+
+ /**
+ * Iterate through children
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_child_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through descendents
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_descendant_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through parent node. (Only one node)
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_parent_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through ancestors
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_ancestor_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through siblings following the context node
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_following_sibling_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through sibling preceding the context node
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_preceding_sibling_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through all nodes following the context node
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_following_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through all nodes preceding the context node
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_preceding_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through attributes
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_attribute_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through namespaces defined in the context node
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_namespace_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through self node (Only one node)
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_self_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through descendents and context node
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_descendant_self_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /**
+ * Iterate through ancestors and context node
+ *
+ * @param context XPath context
+ * @param op_node_test Reference to the node test operation
+ * in the parsed expression
+ * @param op_next Reference to the next step in the location path,
+ * in the parsed expression
+ * @param op_predicate Reference to the first predicate in the
+ * parsed expression
+ * @return Number of nodes added to the stack
+ */
+ int axiom_xpath_ancestor_self_iterator(
+ axiom_xpath_context_t *context,
+ int op_node_test,
+ int op_next,
+ int op_predicate);
+
+ /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_parser.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_parser.c?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_parser.c (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_parser.c Sun Oct 5 16:32:41 2008
@@ -0,0 +1,1143 @@
+
+/*
+ * 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"
+
+/* Compile an XPath expression */
+int axiom_xpath_compile(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ if (!expr || !expr->expr_str)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf("Expression in NULL.\n");
+#endif
+
+ return AXIS2_FAILURE;
+ }
+
+ expr->expr_len = (int)axutil_strlen(expr->expr_str);
+
+ expr->operations = axutil_array_list_create(env, 0);
+
+ expr->expr_ptr = 0;
+
+ expr->start = axiom_xpath_compile_orexpr(env, expr);
+
+ if (expr->start == AXIOM_XPATH_PARSE_ERROR)
+ {
+ axutil_array_list_free(expr->operations, env);
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+ else
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf("Expression successfully parsed\n");
+#endif
+
+ return AXIOM_XPATH_PARSE_SUCCESS;
+ }
+}
+
+/* Parse Or Expression : Stub*/
+int axiom_xpath_compile_orexpr(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ return axiom_xpath_compile_equalexpr(env, expr);
+}
+
+/* Parse Equality Expression */
+int axiom_xpath_compile_equalexpr(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ int op1, op2;
+
+ if (!AXIOM_XPATH_HAS_MORE)
+ {
+ return AXIOM_XPATH_PARSE_END;
+ }
+
+ op1 = axiom_xpath_compile_union(env, expr);
+
+ if (op1 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: UnionExpr expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ while (AXIOM_XPATH_CURRENT == '=')
+ {
+ AXIOM_XPATH_SKIP_WHITESPACES;
+ AXIOM_XPATH_READ(1);
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ op2 = axiom_xpath_compile_union(env, expr);
+
+ if (op2 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: UnionExpr expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ op1 = AXIOM_XPATH_PUSH(AXIOM_XPATH_OPERATION_EQUAL_EXPR, op1, op2);
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+ }
+
+ return op1;
+}
+
+/* Parse Union */
+int axiom_xpath_compile_union(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ int op1, op2;
+
+ if (!AXIOM_XPATH_HAS_MORE)
+ {
+ return AXIOM_XPATH_PARSE_END;
+ }
+
+ op1 = axiom_xpath_compile_path_expression(env, expr);
+
+ if (op1 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: PathExpr expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ if (AXIOM_XPATH_CURRENT == '|')
+ {
+ AXIOM_XPATH_READ(1);
+ AXIOM_XPATH_SKIP_WHITESPACES;
+ op2 = axiom_xpath_compile_union(env, expr);
+
+ if (op2 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: UnionExpr expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ return AXIOM_XPATH_PUSH(AXIOM_XPATH_OPERATION_UNION, op1, op2);
+ }
+
+ /* Just a location path */
+ return op1;
+}
+
+/* Compile Filter expression */
+int axiom_xpath_compile_filter(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ int op = AXIOM_XPATH_PARSE_END;
+
+ if (AXIOM_XPATH_CURRENT == '(')
+ {
+ AXIOM_XPATH_READ(1);
+ op = axiom_xpath_compile_orexpr(env, expr);
+ AXIOM_XPATH_SKIP_WHITESPACES;
+ if (AXIOM_XPATH_CURRENT == ')')
+ {
+ AXIOM_XPATH_READ(1);
+ return op;
+ }
+ else
+ {
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+ }
+ else if (AXIOM_XPATH_CURRENT == '\'' || AXIOM_XPATH_CURRENT == '\"')
+ {
+ return AXIOM_XPATH_PUSH_PAR(
+ AXIOM_XPATH_OPERATION_LITERAL,
+ axiom_xpath_compile_literal(env, expr),
+ NULL, AXIOM_XPATH_PARSE_END);
+ }
+ else if (isdigit(AXIOM_XPATH_CURRENT)
+ || (AXIOM_XPATH_CURRENT == '.' && isdigit(AXIOM_XPATH_NEXT(1))))
+ {
+ return AXIOM_XPATH_PUSH_PAR(
+ AXIOM_XPATH_OPERATION_NUMBER,
+ axiom_xpath_compile_number(env, expr),
+ NULL, AXIOM_XPATH_PARSE_END);
+ }
+ else if (AXIOM_XPATH_CURRENT == '$')
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: Variables are not supported, yet - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+ }
+ else
+ {
+ return axiom_xpath_compile_function_call(env, expr);
+ }
+
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: Invalid Filter expression - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ /* TODO: functions and variables */
+}
+
+/* Parse Path expression (not a location path) */
+int axiom_xpath_path_compile_path_expression_filter(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ int op_filter, op_next;
+
+ op_filter = axiom_xpath_compile_filter(env, expr);
+
+ if (op_filter == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: FilterExpr expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ if (AXIOM_XPATH_NEXT(0) == '/' && AXIOM_XPATH_NEXT(1) == '/')
+ {
+ AXIOM_XPATH_READ(2);
+
+ op_next = axiom_xpath_compile_relative_location(env, expr);
+
+ if (op_next == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: RelativeLocation expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ op_next = AXIOM_XPATH_WRAP_SELF_DESCENDANT(op_next);
+ }
+ else if (AXIOM_XPATH_NEXT(0) == '/')
+ {
+ AXIOM_XPATH_READ(1);
+
+ op_next = axiom_xpath_compile_relative_location(env, expr);
+
+ if (op_next == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: RelativeLocation expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+ }
+ else
+ {
+ op_next = AXIOM_XPATH_PARSE_END;
+ }
+
+ return AXIOM_XPATH_PUSH(
+ AXIOM_XPATH_OPERATION_PATH_EXPRESSION,
+ op_filter, op_next);
+}
+
+/* Parse Path expression */
+int axiom_xpath_compile_path_expression(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ int temp_ptr = expr->expr_ptr;
+ axis2_char_t *name;
+ axis2_char_t *node_types[] =
+ {"comment", "node", "processing-instruction", "text"};
+ axis2_char_t filter_start[] = {'$', '\'', '\"', '('};
+ int i;
+
+ /* if | FilterExpr
+ | FilterExpr '/' RelativeLocationPath
+ | FilterExpr '//' RelativeLocationPath */
+ for (i = 0; i < 4; i++)
+ {
+ if (AXIOM_XPATH_CURRENT == filter_start[i])
+ {
+ return axiom_xpath_path_compile_path_expression_filter(env, expr);
+ }
+ }
+
+ if (isdigit(AXIOM_XPATH_CURRENT)
+ || (AXIOM_XPATH_CURRENT == '.' && isdigit(AXIOM_XPATH_NEXT(1))))
+ {
+ return axiom_xpath_path_compile_path_expression_filter(env, expr);
+ }
+
+ /* Funciton calls */
+ name = axiom_xpath_compile_ncname(env, expr);
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ if (name != NULL && AXIOM_XPATH_CURRENT == '(')
+ {
+ expr->expr_ptr = temp_ptr;
+ for (i = 0; i < 4; i++)
+ {
+ /* If node type */
+ if (axutil_strcmp(name, node_types[i]) == 0)
+ {
+ return axiom_xpath_compile_location_path(env, expr);
+ }
+ }
+
+ return axiom_xpath_path_compile_path_expression_filter(env, expr);
+ }
+
+ expr->expr_ptr = temp_ptr;
+
+ return axiom_xpath_compile_location_path(env, expr);
+}
+
+/* Parses Location Path */
+int axiom_xpath_compile_location_path(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ int op1;
+ axiom_xpath_operation_type_t opr;
+
+ if (!AXIOM_XPATH_HAS_MORE)
+ {
+ return AXIOM_XPATH_PARSE_END;
+ }
+
+ if (AXIOM_XPATH_CURRENT == '/')
+ {
+ /* Descendent */
+ if (AXIOM_XPATH_NEXT(1) == '/')
+ {
+ opr = AXIOM_XPATH_OPERATION_CONTEXT_NODE;
+ AXIOM_XPATH_READ(2);
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ op1 = axiom_xpath_compile_relative_location(env, expr);
+
+ if (op1 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: RelativeLocation expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ op1 = AXIOM_XPATH_WRAP_SELF_DESCENDANT(op1);
+ }
+ else
+ {
+ opr = AXIOM_XPATH_OPERATION_ROOT_NODE;
+ AXIOM_XPATH_READ(1);
+
+ op1 = axiom_xpath_compile_relative_location(env, expr);
+
+ if (op1 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: RelativeLocation expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+ }
+ }
+ else
+ {
+ opr = AXIOM_XPATH_OPERATION_CONTEXT_NODE;
+
+ op1 = axiom_xpath_compile_relative_location(env, expr);
+
+ if (op1 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: RelativeLocation expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+ }
+
+ if (op1 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: RelativeLocation expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ return AXIOM_XPATH_PUSH(opr, op1, AXIOM_XPATH_PARSE_END);
+}
+
+/* Parses Relative Location Path */
+int axiom_xpath_compile_relative_location(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ int op_step, op_next;
+
+ if (!AXIOM_XPATH_HAS_MORE)
+ {
+ return AXIOM_XPATH_PARSE_END;
+ }
+
+ op_step = axiom_xpath_compile_step(env, expr);
+ op_next = AXIOM_XPATH_PARSE_END; /* Will change if there are more steps */
+
+ if (op_step == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: Step expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ if (AXIOM_XPATH_NEXT(0) == '/' && AXIOM_XPATH_NEXT(1) == '/')
+ {
+ AXIOM_XPATH_READ(2);
+
+ op_next = axiom_xpath_compile_relative_location(env, expr);
+
+ if (op_next == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: RelativeLocation expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ op_next = AXIOM_XPATH_WRAP_SELF_DESCENDANT(op_next);
+ }
+ else if (AXIOM_XPATH_NEXT(0) == '/')
+ {
+ AXIOM_XPATH_READ(1);
+
+ op_next = axiom_xpath_compile_relative_location(env, expr);
+
+ if (op_next == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: RelativeLocation expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+ }
+
+ /* End of the location path */
+ if (op_next == AXIOM_XPATH_PARSE_END)
+ {
+ op_next = AXIOM_XPATH_PUSH(
+ AXIOM_XPATH_OPERATION_RESULT,
+ AXIOM_XPATH_PARSE_END,
+ AXIOM_XPATH_PARSE_END);
+ }
+
+ return AXIOM_XPATH_PUSH(AXIOM_XPATH_OPERATION_STEP, op_step, op_next);
+}
+
+/* Parses Step */
+int axiom_xpath_compile_step(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ int op_predicate = AXIOM_XPATH_PARSE_END;
+ axiom_xpath_node_test_t *node_test;
+ int temp_ptr;
+ axis2_char_t *name = NULL;
+ axiom_xpath_axis_t axis = AXIOM_XPATH_AXIS_NONE;
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ /* . and .. */
+ if (AXIOM_XPATH_CURRENT == '.')
+ {
+ if (AXIOM_XPATH_NEXT(1) == '.')
+ {
+ AXIOM_XPATH_READ(2);
+ axis = AXIOM_XPATH_AXIS_PARENT;
+ }
+ else
+ {
+ AXIOM_XPATH_READ(1);
+ axis = AXIOM_XPATH_AXIS_SELF;
+ }
+
+ return AXIOM_XPATH_PUSH_PAR(
+ AXIOM_XPATH_OPERATION_NODE_TEST,
+ axiom_xpath_create_node_test_node(env),
+ axiom_xpath_create_axis(env, axis), op_predicate);
+ }
+ else if (AXIOM_XPATH_CURRENT == '@')
+ {
+ axis = AXIOM_XPATH_AXIS_ATTRIBUTE;
+
+ AXIOM_XPATH_READ(1);
+ AXIOM_XPATH_SKIP_WHITESPACES;
+ }
+ else
+ {
+ temp_ptr = expr->expr_ptr;
+
+ name = axiom_xpath_compile_ncname(env, expr);
+
+ if (name)
+ {
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ /* An axis */
+ if (AXIOM_XPATH_CURRENT == ':' && AXIOM_XPATH_NEXT(1) == ':')
+ {
+ axis = axiom_xpath_get_axis(env, name);
+
+ if (axis == AXIOM_XPATH_AXIS_NONE)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf("Parse error: Invalid axis - %s\n", name);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ AXIOM_XPATH_READ(2);
+ AXIOM_XPATH_SKIP_WHITESPACES;
+ }
+ else
+ {
+ axis = AXIOM_XPATH_AXIS_CHILD;
+
+ expr->expr_ptr = temp_ptr;
+ }
+ }
+ else
+ {
+ axis = AXIOM_XPATH_AXIS_CHILD;
+
+ expr->expr_ptr = temp_ptr;
+ }
+ }
+
+ node_test = axiom_xpath_compile_node_test(env, expr);
+
+ if (!node_test)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: NodeTest expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ op_predicate = axiom_xpath_compile_predicate(env, expr);
+
+ if (op_predicate == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: Predicate expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ return AXIOM_XPATH_PUSH_PAR(
+ AXIOM_XPATH_OPERATION_NODE_TEST,
+ node_test, axiom_xpath_create_axis(env, axis),
+ op_predicate);
+}
+
+axiom_xpath_node_test_t* axiom_xpath_compile_node_test(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ axis2_char_t* name;
+ axiom_xpath_node_test_t *node_test;
+
+ node_test = AXIS2_MALLOC(env->allocator, sizeof(axiom_xpath_node_test_t));
+ node_test->type = AXIOM_XPATH_NODE_TEST_NONE;
+ node_test->prefix = NULL;
+ node_test->name = NULL;
+ node_test->lit = NULL;
+
+ if (AXIOM_XPATH_CURRENT == '*')
+ {
+ AXIOM_XPATH_READ(1);
+
+ node_test->type = AXIOM_XPATH_NODE_TEST_ALL;
+
+ return node_test;
+ }
+
+ name = axiom_xpath_compile_ncname(env, expr);
+
+ if (!name)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: NCName expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ AXIS2_FREE(env->allocator, node_test);
+
+ return NULL;
+ }
+
+ /* Node type */
+
+ if (AXIOM_XPATH_CURRENT == '(')
+ {
+ AXIOM_XPATH_READ(1);
+
+ if (axutil_strcmp(name, "comment") == 0)
+ {
+ node_test->type = AXIOM_XPATH_NODE_TYPE_COMMENT;
+ }
+ if (axutil_strcmp(name, "node") == 0)
+ {
+ node_test->type = AXIOM_XPATH_NODE_TYPE_NODE;
+ }
+ if (axutil_strcmp(name, "processing-instruction") == 0)
+ {
+ node_test->type = AXIOM_XPATH_NODE_TYPE_PI;
+
+ node_test->lit = axiom_xpath_compile_literal(env, expr);
+ }
+ if (axutil_strcmp(name, "text") == 0)
+ {
+ node_test->type = AXIOM_XPATH_NODE_TYPE_TEXT;
+ }
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ if (node_test->type == AXIOM_XPATH_NODE_TEST_NONE
+ || AXIOM_XPATH_CURRENT != ')')
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf("Parse error: Invalid node type - %s\n", name);
+#endif
+
+ AXIS2_FREE(env->allocator, node_test);
+
+ return NULL;
+ }
+
+ AXIOM_XPATH_READ(1);
+ }
+ else
+ {
+ node_test->type = AXIOM_XPATH_NODE_TEST_STANDARD;
+
+ if (AXIOM_XPATH_CURRENT == ':')
+ {
+ AXIOM_XPATH_READ(1);
+
+ node_test->prefix = name;
+
+ if (AXIOM_XPATH_CURRENT == '*')
+ {
+ AXIOM_XPATH_READ(1);
+
+ node_test->type = AXIOM_XPATH_NODE_TEST_ALL;
+
+ return node_test;
+ }
+
+ node_test->name = axiom_xpath_compile_ncname(env, expr);
+
+ if (!node_test->name)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: NCName expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ AXIS2_FREE(env->allocator, node_test);
+
+ return NULL;
+ }
+ }
+ else
+ {
+ node_test->name = name;
+ }
+ }
+
+ return node_test;
+}
+
+int axiom_xpath_compile_function_call(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ axis2_char_t *name;
+ int op1 = AXIOM_XPATH_PARSE_END;
+
+ name = axiom_xpath_compile_ncname(env, expr);
+
+ if (!name)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: NCName expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ if (AXIOM_XPATH_CURRENT != '(')
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: '(' expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ AXIOM_XPATH_READ(1);
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ if (AXIOM_XPATH_CURRENT != ')')
+ {
+ op1 = axiom_xpath_compile_argument(env, expr);
+ }
+
+ if (AXIOM_XPATH_CURRENT != ')')
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: ')' expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ AXIOM_XPATH_READ(1);
+
+ return AXIOM_XPATH_PUSH_PAR(
+ AXIOM_XPATH_OPERATION_FUNCTION_CALL,
+ name, NULL, op1);
+}
+
+int axiom_xpath_compile_argument(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ int op1 = AXIOM_XPATH_PARSE_END;
+ int op2 = AXIOM_XPATH_PARSE_END;
+
+ op1 = axiom_xpath_compile_orexpr(env, expr);
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ if (AXIOM_XPATH_CURRENT == ',')
+ {
+ op2 = axiom_xpath_compile_argument(env, expr);
+ }
+
+ return AXIOM_XPATH_PUSH(AXIOM_XPATH_OPERATION_ARGUMENT, op1, op2);
+}
+
+axiom_xpath_node_test_t* axiom_xpath_create_node_test_all(
+ const axutil_env_t *env)
+{
+ axiom_xpath_node_test_t *node_test;
+
+ node_test = AXIS2_MALLOC(env->allocator, sizeof(axiom_xpath_node_test_t));
+ node_test->type = AXIOM_XPATH_NODE_TEST_ALL;
+ node_test->prefix = NULL;
+ node_test->name = NULL;
+ node_test->lit = NULL;
+
+ return node_test;
+}
+
+axiom_xpath_node_test_t* axiom_xpath_create_node_test_node(
+ const axutil_env_t *env)
+{
+ axiom_xpath_node_test_t *node_test;
+
+ node_test = AXIS2_MALLOC(env->allocator, sizeof(axiom_xpath_node_test_t));
+ node_test->type = AXIOM_XPATH_NODE_TYPE_NODE;
+ node_test->prefix = NULL;
+ node_test->name = NULL;
+ node_test->lit = NULL;
+
+ return node_test;
+}
+
+double* axiom_xpath_compile_number(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ double *ret = AXIS2_MALLOC(env->allocator, sizeof(double));
+ double res = 0, dec = 0.1;
+ axis2_bool_t dot = AXIS2_FALSE;
+
+ *ret = 0;
+
+ while (1)
+ {
+ if (isdigit(AXIOM_XPATH_CURRENT))
+ {
+ if (!dot)
+ {
+ res = res * 10 + (AXIOM_XPATH_CURRENT - '0');
+ }
+ else
+ {
+ res += dec * (AXIOM_XPATH_CURRENT - '0');
+ dec /= 10;
+ }
+ }
+ else if (AXIOM_XPATH_CURRENT == '.')
+ {
+ if (dot)
+ {
+ return ret;
+ }
+ else
+ {
+ dot = AXIS2_TRUE;
+ dec = 0.1;
+ }
+ }
+ else
+ {
+ break;
+ }
+
+ AXIOM_XPATH_READ(1);
+ }
+
+ *ret = res;
+ return ret;
+}
+
+axis2_char_t* axiom_xpath_compile_literal(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ axis2_char_t lit[255];
+ int i = 0;
+ axis2_char_t del;
+
+ if (AXIOM_XPATH_CURRENT == '\"')
+ {
+ del = '\"';
+ }
+ else if (AXIOM_XPATH_CURRENT == '\'')
+ {
+ del = '\'';
+ }
+ else
+ return NULL;
+
+ AXIOM_XPATH_READ(1);
+
+ while (AXIOM_XPATH_HAS_MORE && AXIOM_XPATH_CURRENT != del)
+ {
+ lit[i] = AXIOM_XPATH_CURRENT;
+ AXIOM_XPATH_READ(1);
+ ++i;
+ }
+
+ if (AXIOM_XPATH_HAS_MORE)
+ {
+ AXIOM_XPATH_READ(1);
+ }
+
+ lit[i] = '\0';
+
+ return axutil_strdup(env, lit);
+
+}
+
+/* Get axis for name */
+axiom_xpath_axis_t axiom_xpath_get_axis(
+ const axutil_env_t *env,
+ axis2_char_t* name)
+{
+ if (axutil_strcmp(name, "child") == 0)
+ {
+ return AXIOM_XPATH_AXIS_CHILD;
+ }
+ else if (axutil_strcmp(name, "descendant") == 0)
+ {
+ return AXIOM_XPATH_AXIS_DESCENDANT;
+ }
+ else if (axutil_strcmp(name, "parent") == 0)
+ {
+ return AXIOM_XPATH_AXIS_PARENT;
+ }
+ else if (axutil_strcmp(name, "ancestor") == 0)
+ {
+ return AXIOM_XPATH_AXIS_ANCESTOR;
+ }
+ else if (axutil_strcmp(name, "following-sibling") == 0)
+ {
+ return AXIOM_XPATH_AXIS_FOLLOWING_SIBLING;
+ }
+ else if (axutil_strcmp(name, "preceding-sibling") == 0)
+ {
+ return AXIOM_XPATH_AXIS_PRECEDING_SIBLING;
+ }
+ else if (axutil_strcmp(name, "following") == 0)
+ {
+ return AXIOM_XPATH_AXIS_FOLLOWING;
+ }
+ else if (axutil_strcmp(name, "preceding") == 0)
+ {
+ return AXIOM_XPATH_AXIS_PRECEDING;
+ }
+ else if (axutil_strcmp(name, "attribute") == 0)
+ {
+ return AXIOM_XPATH_AXIS_ATTRIBUTE;
+ }
+ else if (axutil_strcmp(name, "namespace") == 0)
+ {
+ return AXIOM_XPATH_AXIS_NAMESPACE;
+ }
+ else if (axutil_strcmp(name, "self") == 0)
+ {
+ return AXIOM_XPATH_AXIS_SELF;
+ }
+ else if (axutil_strcmp(name, "descendant-or-self") == 0)
+ {
+ return AXIOM_XPATH_AXIS_DESCENDANT_OR_SELF;
+ }
+ else if (axutil_strcmp(name, "ancestor-or-self") == 0)
+ {
+ return AXIOM_XPATH_AXIS_ANCESTOR_OR_SELF;
+ }
+ else
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf("Unidentified axis name.\n");
+#endif
+
+ return AXIOM_XPATH_AXIS_NONE;
+ }
+}
+
+/* Parse Predicate */
+int axiom_xpath_compile_predicate(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ int op1, op_next_predicate;
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ if (!AXIOM_XPATH_HAS_MORE || AXIOM_XPATH_CURRENT != '[')
+ {
+ return AXIOM_XPATH_PARSE_END;
+ }
+
+ AXIOM_XPATH_READ(1);
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ /* 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. */
+
+ op1 = axiom_xpath_compile_orexpr(env, expr);
+
+ if (op1 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: EqualExpr expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ if (AXIOM_XPATH_CURRENT != ']')
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: ] expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ AXIOM_XPATH_READ(1);
+
+ op_next_predicate = axiom_xpath_compile_predicate(env, expr);
+
+ if (op_next_predicate == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: Predicate expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ return AXIOM_XPATH_PUSH(
+ AXIOM_XPATH_OPERATION_PREDICATE,
+ op1, op_next_predicate);
+}
+
+/* Parse Node Test */
+axis2_char_t * axiom_xpath_compile_ncname(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr)
+{
+ axis2_char_t name[255];
+ int i = 0;
+
+ if (!isalpha(AXIOM_XPATH_CURRENT) && AXIOM_XPATH_CURRENT != '_')
+ {
+ return NULL;
+ }
+
+ /* TODO: Add CombiningChar and Extender
+ * Link http://www.w3.org/TR/REC-xml/#NT-NameChar */
+ while (AXIOM_XPATH_HAS_MORE
+ && (isalnum(AXIOM_XPATH_CURRENT)
+ || AXIOM_XPATH_CURRENT == '_'
+ || AXIOM_XPATH_CURRENT == '.'
+ || AXIOM_XPATH_CURRENT == '-'))
+ {
+ name[i] = AXIOM_XPATH_CURRENT;
+ AXIOM_XPATH_READ(1);
+ ++i;
+ }
+
+ name[i] = '\0';
+
+ return axutil_strdup(env, name);
+}
+
+/* Supporting functions */
+int axiom_xpath_add_operation(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr,
+ axiom_xpath_operation_type_t op_type,
+ int op1, int op2, void *par1, void *par2)
+{
+ axiom_xpath_operation_t *op;
+
+ op = AXIS2_MALLOC(env->allocator, sizeof(axiom_xpath_operation_t));
+ op->opr = op_type;
+ op->op1 = op1;
+ op->op2 = op2;
+
+ op->pos = 0;
+
+ op->par1 = par1;
+ op->par2 = par2;
+
+ axutil_array_list_add(expr->operations, env, op);
+
+ return axutil_array_list_size(expr->operations, env) - 1;
+}
+
+axiom_xpath_axis_t *axiom_xpath_create_axis(
+ const axutil_env_t *env,
+ axiom_xpath_axis_t axis)
+{
+ axiom_xpath_axis_t *axis_p =
+ AXIS2_MALLOC(env->allocator, sizeof(axiom_xpath_axis_t));
+
+ *axis_p = axis;
+ return axis_p;
+}
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_parser.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_parser.h?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_parser.h (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_internals_parser.h Sun Oct 5 16:32:41 2008
@@ -0,0 +1,405 @@
+
+/*
+ * 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_PARSER_H
+#define XPATH_INTERNALS_PARSER_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @defgroup axiom_xpath_parser parser
+ * @ingroup axiom_xpath
+ * @{
+ */
+
+
+ /* Macros */
+
+ /** Get the current character in the expression */
+#define AXIOM_XPATH_CURRENT (expr->expr_ptr < expr->expr_len ? \
+ expr->expr_str[expr->expr_ptr] : -1)
+
+ /** Get a character after the current */
+#define AXIOM_XPATH_NEXT(ind) (expr->expr_ptr + ind < expr->expr_len ? \
+ expr->expr_str[expr->expr_ptr + ind] : -1)
+
+ /** Increment the pointer to the expression */
+#define AXIOM_XPATH_READ(n) (expr->expr_ptr += n)
+
+ /** Check if expression has finished parsing */
+#define AXIOM_XPATH_HAS_MORE (expr->expr_ptr < expr->expr_len)
+
+ /** Skip white spaces */
+#define AXIOM_XPATH_SKIP_WHITESPACES \
+ { while(AXIOM_XPATH_CURRENT == ' ') \
+ AXIOM_XPATH_READ(1); \
+ }
+
+ /** Wrape an operation in a self_or_descendent step; used to handle '//' */
+#define AXIOM_XPATH_WRAP_SELF_DESCENDANT(_op2) \
+ axiom_xpath_add_operation(env, expr, AXIOM_XPATH_OPERATION_STEP, \
+ axiom_xpath_add_operation(env, expr, AXIOM_XPATH_OPERATION_NODE_TEST, \
+ AXIOM_XPATH_PARSE_END, AXIOM_XPATH_PARSE_END, \
+ axiom_xpath_create_node_test_node(env), \
+ axiom_xpath_create_axis(env, AXIOM_XPATH_AXIS_DESCENDANT_OR_SELF)), \
+ _op2, NULL, NULL)
+
+ /** Adds an operation */
+#define AXIOM_XPATH_PUSH(_opr, _op1, _op2) axiom_xpath_add_operation( \
+ env, expr, _opr, _op1, _op2, NULL, NULL)
+
+ /** Adds an operation with parameters */
+#define AXIOM_XPATH_PUSH_PAR(_opr, _par1, _par2, _op1) axiom_xpath_add_operation( \
+ env, expr, _opr, _op1, AXIOM_XPATH_PARSE_END, (void *)_par1, (void *)_par2)
+
+ /* Functions */
+
+ /**
+ * Add an operation to the operations array
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @param op_type Type of the operation
+ * @param op1 First operand
+ * @param op2 Second operand
+ * @param par1 First parameter
+ * @param par2 Second parameter
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_add_operation(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr,
+ axiom_xpath_operation_type_t op_type,
+ int op1,
+ int op2,
+ void *par1,
+ void *par2);
+
+ /**
+ * Compile a XPath expression
+ *
+ * [14] Expr ::= OrExpr
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the main operation in the array
+ */
+ int axiom_xpath_compile(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile an equals expression
+ *
+ * ***Not completed***
+ * [23] EqualityExpr ::= UnionExpr '=' UnionExpr
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_compile_equalexpr(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile an union
+ *
+ * [18] UnionExpr ::= PathExpr
+ * | UnionExpr '|' PathExpr
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_compile_union(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile a path expression
+ *
+ * [19] PathExpr ::= LocationPath
+ * | FilterExpr
+ * | FilterExpr '/' RelativeLocationPath
+ * | FilterExpr '//' RelativeLocationPath
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_compile_path_expression(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile a path expression with a filter
+ *
+ * [19] PathExpr ::= FilterExpr
+ * | FilterExpr '/' RelativeLocationPath
+ * | FilterExpr '//' RelativeLocationPath
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_path_compile_path_expression_filter(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile a filter expression
+ *
+ * 20] FilterExpr ::= PrimaryExpr
+ * | FilterExpr Predicate
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_compile_filter(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile a location path
+ *
+ * [1] LocationPath ::= RelativeLocationPath
+ * | AbsoluteLocationPath
+ * [2] AbsoluteLocationPath ::= '/' RelativeLocationPath?
+ * | AbbreviatedAbsoluteLocationPath
+ *
+ * [10] AbbreviatedAbsoluteLocationPath ::= '//' RelativeLocationPath
+ * [11] AbbreviatedRelativeLocationPath ::= RelativeLocationPath '//' Step
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_compile_location_path(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile a relative location
+ *
+ * [3] RelativeLocationPath ::= Step
+ * | RelativeLocationPath '/' Step
+ * | AbbreviatedRelativeLocationPath
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_compile_relative_location(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile a step
+ *
+ * [4] Step ::= AxisSpecifier NodeTest Predicate*
+ * | AbbreviatedStep
+ * [5] AxisSpecifier ::= AxisName '::'
+ * | AbbreviatedAxisSpecifier
+ *
+ * [12] AbbreviatedStep ::= '.' | '..'
+ * [13] AbbreviatedAxisSpecifier ::= '@'?
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_compile_step(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compiles an OrExpr. This function is not complete.
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_compile_orexpr(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compiles a FunctionCall
+ *
+ * [16] FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument )* )? ')'
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_compile_function_call(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compiles an Argument.
+ *
+ * [17] Argument ::= Expr
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_compile_argument(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile a node test
+ *
+ * [7] NodeTest ::= NameTest
+ * | NodeType '(' ')'
+ * | 'processing-instruction' '(' Literal ')'
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ axiom_xpath_node_test_t* axiom_xpath_compile_node_test(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile a predicate(s)
+ *
+ * [8] Predicate ::= '[' PredicateExpr ']'
+ * [9] PredicateExpr ::= Expr
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return Index of the operation in the array
+ */
+ int axiom_xpath_compile_predicate(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+
+
+ /**
+ * Compile a literal
+ *
+ * [29] Literal ::= '"' [^"]* '"'
+ * | "'" [^']* "'"
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return The literal parsed
+ */
+ axis2_char_t* axiom_xpath_compile_literal(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile a number
+ *
+ * [30] Number ::= Digits ('.' Digits?)?
+ * | '.' Digits
+ * [31] Digits ::= [0-9]+
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return The number parsed
+ */
+ double* axiom_xpath_compile_number(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+ /**
+ * Compile a ncname
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @return The ncname parsed
+ */
+ axis2_char_t* axiom_xpath_compile_ncname(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+
+
+ /**
+ * Get the XPath axis by axis name
+ *
+ * [6] AxisName ::= 'ancestor'
+ * | 'ancestor-or-self'
+ * | 'attribute'
+ * | 'child'
+ * | 'descendant'
+ * | 'descendant-or-self'
+ * | 'following'
+ * | 'following-sibling'
+ * | 'namespace'
+ * | 'parent'
+ * | 'preceding'
+ * | 'preceding-sibling'
+ * | 'self'
+ *
+ * @param env Environment must not be null
+ * @param name Name of the axis
+ * @return XPath axis; returns AXIOM_XPATH_AXIS_NONE if invalid name
+ */
+ axiom_xpath_axis_t axiom_xpath_get_axis(
+ const axutil_env_t *env,
+ axis2_char_t* name);
+
+ /**
+ * Create a node test which matches all nodes (*)
+ *
+ * @param env Environment must not be null
+ * @return Node test
+ */
+ axiom_xpath_node_test_t* axiom_xpath_create_node_test_all(
+ const axutil_env_t *env);
+
+ /**
+ * Create a node test which matches all nodes (nodes())
+ *
+ * @param env Environment must not be null
+ * @return Node test
+ */
+ axiom_xpath_node_test_t* axiom_xpath_create_node_test_node(
+ const axutil_env_t *env);
+
+ /**
+ * Create a pointer to an axis; allocate memory using the allocator
+ *
+ * @param env Environment must not be null
+ * @param axis XPath axis
+ * @return Pointer to the axis created
+ */
+ axiom_xpath_axis_t *axiom_xpath_create_axis(
+ const axutil_env_t *env,
+ axiom_xpath_axis_t axis);
+
+ /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_streaming.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_streaming.c?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_streaming.c (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_streaming.c Sun Oct 5 16:32:41 2008
@@ -0,0 +1,225 @@
+
+/*
+ * 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_streaming.h"
+#include "xpath_internals.h"
+#include "xpath_internals_engine.h"
+
+axiom_xpath_streaming_t axiom_xpath_streaming_check_operation(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr,
+ int op_p)
+{
+ axiom_xpath_operation_t *op;
+
+ if (op_p == AXIOM_XPATH_PARSE_END)
+ {
+ return AXIOM_XPATH_STREAMING_CONSTANT;
+ }
+
+ op = AXIOM_XPATH_OPR_EXPR_GET(op_p);
+
+ switch (op->opr)
+ {
+ case AXIOM_XPATH_OPERATION_CONTEXT_NODE:
+ case AXIOM_XPATH_OPERATION_ROOT_NODE:
+ return axiom_xpath_streaming_combine_dependent(
+ AXIOM_XPATH_CHECK(op->op1),
+ AXIOM_XPATH_STREAMING_CONSTANT);
+
+ case AXIOM_XPATH_OPERATION_STEP:
+ return axiom_xpath_streaming_combine_dependent(
+ AXIOM_XPATH_CHECK(op->op1),
+ AXIOM_XPATH_CHECK(op->op2));
+
+ case AXIOM_XPATH_OPERATION_RESULT:
+ return AXIOM_XPATH_STREAMING_CONSTANT;
+
+ case AXIOM_XPATH_OPERATION_UNION:
+ return axiom_xpath_streaming_combine_independent(
+ AXIOM_XPATH_CHECK(op->op1),
+ AXIOM_XPATH_CHECK(op->op2));
+
+ case AXIOM_XPATH_OPERATION_EQUAL_EXPR:
+ return axiom_xpath_streaming_combine_independent(
+ AXIOM_XPATH_CHECK(op->op1),
+ AXIOM_XPATH_CHECK(op->op2));
+
+ case AXIOM_XPATH_OPERATION_LITERAL:
+ return AXIOM_XPATH_STREAMING_CONSTANT;
+
+ case AXIOM_XPATH_OPERATION_NUMBER:
+ return AXIOM_XPATH_STREAMING_CONSTANT;
+
+ case AXIOM_XPATH_OPERATION_PATH_EXPRESSION:
+ return axiom_xpath_streaming_combine_dependent(
+ AXIOM_XPATH_CHECK(op->op1),
+ AXIOM_XPATH_CHECK(op->op2));
+
+ case AXIOM_XPATH_OPERATION_NODE_TEST:
+ return axiom_xpath_streaming_check_node_test(env, expr, op);
+
+ case AXIOM_XPATH_OPERATION_PREDICATE:
+ return axiom_xpath_streaming_check_predicate(env, expr, op_p);
+
+ default:
+#ifdef AXIOM_XPATH_DEBUG
+ printf("Unidentified operation.\n");
+#endif
+
+ return AXIOM_XPATH_STREAMING_NOT_SUPPORTED;
+ }
+}
+
+axiom_xpath_streaming_t axiom_xpath_streaming_check_predicate(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr,
+ int op_p)
+{
+ axiom_xpath_operation_t *op;
+
+ if (op_p == AXIOM_XPATH_PARSE_END)
+ {
+ return AXIOM_XPATH_STREAMING_CONSTANT;
+ }
+
+ op = AXIOM_XPATH_OPR_EXPR_GET(op_p);
+
+ return axiom_xpath_streaming_combine_dependent(
+ AXIOM_XPATH_CHECK(op->op1),
+ AXIOM_XPATH_CHECK(op->op2));
+}
+
+axiom_xpath_streaming_t axiom_xpath_streaming_check_node_test(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr,
+ axiom_xpath_operation_t *op)
+{
+ axiom_xpath_axis_t axis = AXIOM_XPATH_AXIS_NONE;
+ axiom_xpath_streaming_t r;
+
+ if (!op->par2)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf("axis is NULL in the step operator\n");
+#endif
+ return AXIOM_XPATH_STREAMING_NOT_SUPPORTED;
+ }
+
+ axis = *((axiom_xpath_axis_t *)op->par2);
+
+ switch (axis)
+ {
+ case AXIOM_XPATH_AXIS_ATTRIBUTE:
+ case AXIOM_XPATH_AXIS_CHILD:
+ break;
+
+ default:
+ return AXIOM_XPATH_STREAMING_NOT_SUPPORTED;
+ }
+
+ r = axiom_xpath_streaming_check_predicate(env, expr, op->op1);
+
+ if (r != AXIOM_XPATH_STREAMING_ATTRIBUTE
+ && r != AXIOM_XPATH_STREAMING_CONSTANT)
+ {
+ return AXIOM_XPATH_STREAMING_NOT_SUPPORTED;
+ }
+
+ if (axis == AXIOM_XPATH_AXIS_ATTRIBUTE)
+ {
+ return AXIOM_XPATH_STREAMING_ATTRIBUTE;
+ }
+ else
+ {
+ return AXIOM_XPATH_STREAMING_SUPPORTED;
+ }
+}
+
+axiom_xpath_streaming_t axiom_xpath_streaming_combine_dependent(
+ axiom_xpath_streaming_t r1,
+ axiom_xpath_streaming_t r2)
+{
+ if (r1 == AXIOM_XPATH_STREAMING_NOT_SUPPORTED
+ || r2 == AXIOM_XPATH_STREAMING_NOT_SUPPORTED)
+ {
+ return AXIOM_XPATH_STREAMING_NOT_SUPPORTED;
+ }
+ else if (r1 == AXIOM_XPATH_STREAMING_SUPPORTED
+ || r2 == AXIOM_XPATH_STREAMING_SUPPORTED)
+ {
+ return AXIOM_XPATH_STREAMING_SUPPORTED;
+ }
+ else if (r1 == AXIOM_XPATH_STREAMING_ATTRIBUTE
+ || r2 == AXIOM_XPATH_STREAMING_ATTRIBUTE)
+ {
+ return AXIOM_XPATH_STREAMING_ATTRIBUTE;
+ }
+ else
+ {
+ return AXIOM_XPATH_STREAMING_CONSTANT;
+ }
+}
+
+axiom_xpath_streaming_t axiom_xpath_streaming_combine_independent(
+ axiom_xpath_streaming_t r1,
+ axiom_xpath_streaming_t r2)
+{
+ if (r1 == AXIOM_XPATH_STREAMING_NOT_SUPPORTED
+ || r2 == AXIOM_XPATH_STREAMING_NOT_SUPPORTED)
+ {
+ return AXIOM_XPATH_STREAMING_NOT_SUPPORTED;
+ }
+ else if (r1 == AXIOM_XPATH_STREAMING_CONSTANT
+ || r2 == AXIOM_XPATH_STREAMING_CONSTANT)
+ {
+ if (r1 == AXIOM_XPATH_STREAMING_SUPPORTED
+ || r2 == AXIOM_XPATH_STREAMING_SUPPORTED)
+ {
+ return AXIOM_XPATH_STREAMING_SUPPORTED;
+ }
+ else if (r1 == AXIOM_XPATH_STREAMING_ATTRIBUTE
+ || r2 == AXIOM_XPATH_STREAMING_ATTRIBUTE)
+ {
+ return AXIOM_XPATH_STREAMING_ATTRIBUTE;
+ }
+ else
+ {
+ return AXIOM_XPATH_STREAMING_CONSTANT;
+ }
+ }
+ else if (r1 == AXIOM_XPATH_STREAMING_ATTRIBUTE
+ || r2 == AXIOM_XPATH_STREAMING_ATTRIBUTE)
+ {
+ if (r1 == AXIOM_XPATH_STREAMING_SUPPORTED
+ || r2 == AXIOM_XPATH_STREAMING_SUPPORTED)
+ {
+ return AXIOM_XPATH_STREAMING_SUPPORTED;
+ }
+ else
+ {
+ return AXIOM_XPATH_STREAMING_ATTRIBUTE;
+ }
+ }
+ else
+ {
+ return AXIOM_XPATH_STREAMING_NOT_SUPPORTED;
+ }
+}
+
Added: webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_streaming.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_streaming.h?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_streaming.h (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/src/xpath/xpath_streaming.h Sun Oct 5 16:32:41 2008
@@ -0,0 +1,126 @@
+
+/*
+ * 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_STREAMING_H
+#define XPATH_STREAMING_H
+
+#include "xpath_internals.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @defgroup axiom_xpath_streaming streaming
+ * @ingroup axiom_xpath
+ * @{
+ */
+
+
+ /**
+ * XPath streaming support
+ */
+ typedef enum axiom_xpath_streaming_t
+ {
+ AXIOM_XPATH_STREAMING_NOT_SUPPORTED = 0,
+ AXIOM_XPATH_STREAMING_SUPPORTED,
+ AXIOM_XPATH_STREAMING_CONSTANT,
+ AXIOM_XPATH_STREAMING_ATTRIBUTE
+ } axiom_xpath_streaming_t;
+
+ /** Check whether the given expression is supported on streaming XML */
+#define AXIOM_XPATH_CHECK(op) axiom_xpath_streaming_check_operation(env, expr, op)
+
+ /** Get an operation from the list of operations */
+#define AXIOM_XPATH_OPR_EXPR_GET(ind) (axiom_xpath_operation_t *) \
+ axutil_array_list_get(expr->operations, env, ind)
+
+ /**
+ * Checks whether the given expression is supported on streaming XML
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @param op_p Index of the operation in the list of operations
+ * @return Whether the given operation can be evaluated on streaming XML
+ */
+ axiom_xpath_streaming_t axiom_xpath_streaming_check_operation(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr,
+ int op_p);
+
+ /**
+ * Checks whether the predicate is supported on streaming XML.
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @param op_p Index of the operation in the list of operations
+ * @return Whether the given operation can be evaluated on streaming XML
+ */
+ axiom_xpath_streaming_t axiom_xpath_streaming_check_predicate(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr,
+ int op_p);
+
+ /**
+ * Checks whether the predicate is supported on streaming XML.
+ *
+ * @param env Environment must not be null
+ * @param expr A pointer to the XPath expression
+ * @param op Index of the operation in the list of operations
+ * @return Whether the given operation can be evaluated on streaming XML
+ */
+ axiom_xpath_streaming_t axiom_xpath_streaming_check_node_test(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr,
+ axiom_xpath_operation_t* op);
+
+
+ /**
+ * Checks whether the two operations can be evaluated on streaming XML
+ * sequencially (one after the other), where the result of the first
+ * operation is the context of the next
+ *
+ * @param r1 Type of first operation
+ * @param r2 Type of second operation
+ * @return Whether the given operations can be evaluated on streaming XML
+ */
+ axiom_xpath_streaming_t axiom_xpath_streaming_combine_dependent(
+ axiom_xpath_streaming_t r1,
+ axiom_xpath_streaming_t r2);
+
+
+ /**
+ * Checks whether the two operations can be evaluated on streaming XML
+ * simultaneousy
+ *
+ * @param r1 Type of first operation
+ * @param r2 Type of second operation
+ * @return Whether the given operations can be evaluated on streaming XML
+ */
+ axiom_xpath_streaming_t axiom_xpath_streaming_combine_independent(
+ axiom_xpath_streaming_t r1,
+ axiom_xpath_streaming_t r2);
+
+ /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.bat
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.bat?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.bat (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.bat Sun Oct 5 16:32:41 2008
@@ -0,0 +1,13 @@
+@echo off
+cls
+
+echo "Compiling..."
+cl.exe /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /I %AXIS2C_HOME%\include /I ..\include /I ..\src /c test_windows.c ../src/*.c
+
+echo "Linking..."
+link.exe /LIBPATH:%AXIS2C_HOME%\lib axutil.lib axiom.lib axis2_parser.lib axis2_engine.lib /OUT:test.exe *.obj
+
+del *.obj
+
+echo "Running..."
+test.exe
\ No newline at end of file
Added: webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.ns
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.ns?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.ns (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.ns Sun Oct 5 16:32:41 2008
@@ -0,0 +1,2 @@
+test
+http://xpath/test
Added: webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.sh
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.sh?rev=701901&view=auto
==============================================================================
--- webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.sh (added)
+++ webservices/axis2/branches/c/xpath_integration/axiom/test/xpath/test.sh Sun Oct 5 16:32:41 2008
@@ -0,0 +1,11 @@
+clear
+
+export AXIS2C_HOME="/usr/local/axis2c"
+
+echo 'Compiling...'
+
+gcc -o test -I$AXIS2C_HOME/include/axis2-1.5.0/ -L$AXIS2C_HOME/lib -I../include -I../src -laxutil -laxis2_axiom -laxis2_parser -laxis2_engine -lpthread -laxis2_http_sender -laxis2_http_receiver test_linux.c ../src/*.c -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib
+
+echo 'Running...'
+
+./test