You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by du...@apache.org on 2009/04/11 17:58:27 UTC
svn commit: r764212 - in /webservices/axis2/trunk/c/axiom/src/xpath: xpath.c
xpath_internals.h xpath_internals_engine.c xpath_internals_engine.h
xpath_internals_iterators.c xpath_internals_parser.c xpath_internals_parser.h
Author: dumindu
Date: Sat Apr 11 15:58:27 2009
New Revision: 764212
URL: http://svn.apache.org/viewvc?rev=764212&view=rev
Log:
Applying the patch Varuna sent for jira AXIS2C-1347.
Modified:
webservices/axis2/trunk/c/axiom/src/xpath/xpath.c
webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals.h
webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_engine.c
webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_engine.h
webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_iterators.c
webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_parser.c
webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_parser.h
Modified: webservices/axis2/trunk/c/axiom/src/xpath/xpath.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/xpath/xpath.c?rev=764212&r1=764211&r2=764212&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/xpath/xpath.c (original)
+++ webservices/axis2/trunk/c/axiom/src/xpath/xpath.c Sat Apr 11 15:58:27 2009
@@ -141,7 +141,7 @@
{
axiom_xpath_function_t func = NULL;
- if(context->functions)
+ if (context->functions)
{
func = axutil_hash_get(context->functions, name, AXIS2_HASH_KEY_STRING);
}
@@ -175,7 +175,7 @@
{
axiom_namespace_t *ns = NULL;
- if(context->namespaces)
+ if (context->namespaces)
{
ns = axutil_hash_get(context->namespaces, prefix, AXIS2_HASH_KEY_STRING);
}
@@ -250,7 +250,7 @@
}
else
{
- return 1.0;
+ return 0.0;
}
}
else if (node->type == AXIOM_XPATH_TYPE_NUMBER)
@@ -263,7 +263,7 @@
}
else
{
- return 1.0;
+ return 0.0;
}
}
@@ -293,8 +293,8 @@
}
else if (node->type == AXIOM_XPATH_TYPE_NUMBER)
{
- /* Allocate 20 bytes */
- res = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 20);
+ /* Allocate 50 bytes */
+ res = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 50);
sprintf(res, "%lf", *(double *)(node->value));
Modified: webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals.h?rev=764212&r1=764211&r2=764212&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals.h (original)
+++ webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals.h Sat Apr 11 15:58:27 2009
@@ -104,6 +104,8 @@
AXIOM_XPATH_OPERATION_RESULT,
AXIOM_XPATH_OPERATION_UNION,
AXIOM_XPATH_OPERATION_EQUAL_EXPR,
+ AXIOM_XPATH_OPERATION_AND_EXPR,
+ AXIOM_XPATH_OPERATION_OR_EXPR,
AXIOM_XPATH_OPERATION_PREDICATE,
AXIOM_XPATH_OPERATION_LITERAL,
AXIOM_XPATH_OPERATION_NUMBER,
Modified: webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_engine.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_engine.c?rev=764212&r1=764211&r2=764212&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_engine.c (original)
+++ webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_engine.c Sat Apr 11 15:58:27 2009
@@ -60,8 +60,9 @@
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));
+ axis2_bool_t v = axiom_xpath_cast_node_to_boolean(context->env, node);
+
+ AXIOM_XPATH_CAST_SET_VALUE(axis2_bool_t, v);
node->type = AXIOM_XPATH_TYPE_BOOLEAN;
}
@@ -70,8 +71,9 @@
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));
+ double v = axiom_xpath_cast_node_to_number(context->env, node);
+
+ AXIOM_XPATH_CAST_SET_VALUE(double, v);
node->type = AXIOM_XPATH_TYPE_NUMBER;
}
@@ -86,7 +88,10 @@
}
/* Evaluate whether two results are equal
- TODO: Comment */
+
+ If either node is a boolean other is casted to a boolean;
+ Otherwise, if either node is a number other is casted to a number;
+ Otherwise, both nodes are casted to strings.*/
axis2_bool_t axiom_xpath_compare_equal(
axiom_xpath_result_node_t *node1,
axiom_xpath_result_node_t *node2,
@@ -139,6 +144,28 @@
}
}
+/* Convert a node set to boolean */
+axis2_bool_t axiom_xpath_convert_to_boolean(
+ axutil_array_list_t *node_set,
+ axiom_xpath_context_t *context)
+{
+ if (axutil_array_list_size(node_set, context->env) == 0)
+ {
+ return AXIS2_FALSE;
+ }
+ else if (axutil_array_list_size(node_set, context->env) >= 2)
+ {
+ return AXIS2_TRUE;
+ }
+ else
+ {
+ axiom_xpath_result_node_t *node = axutil_array_list_get(node_set, context->env, 0);
+ axiom_xpath_cast_boolean(node, context);
+
+ return *(axis2_bool_t *)node->value;
+ }
+}
+
/* Operators */
/* Literal */
@@ -248,6 +275,140 @@
return n_nodes;
}
+/* Or Expression */
+int axiom_xpath_orexpr_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 */
+ if (axiom_xpath_convert_to_boolean(arr[0], context) || axiom_xpath_convert_to_boolean(arr[1], context))
+ {
+ AXIOM_XPATH_CAST_SET_VALUE(axis2_bool_t, AXIS2_TRUE);
+
+ axutil_stack_push(context->stack, context->env, node);
+ }
+ else
+ {
+ AXIOM_XPATH_CAST_SET_VALUE(axis2_bool_t, AXIS2_FALSE);
+
+ axutil_stack_push(context->stack, context->env, node);
+ }
+
+ axutil_array_list_free(arr[0], context->env);
+ axutil_array_list_free(arr[1], context->env);
+
+ return 1;
+}
+
+/* And Expression */
+int axiom_xpath_andexpr_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 */
+ if (axiom_xpath_convert_to_boolean(arr[0], context) && axiom_xpath_convert_to_boolean(arr[1], context))
+ {
+ AXIOM_XPATH_CAST_SET_VALUE(axis2_bool_t, AXIS2_TRUE);
+
+ axutil_stack_push(context->stack, context->env, node);
+ }
+ else
+ {
+ AXIOM_XPATH_CAST_SET_VALUE(axis2_bool_t, AXIS2_FALSE);
+
+ axutil_stack_push(context->stack, context->env, node);
+ }
+
+ axutil_array_list_free(arr[0], context->env);
+ axutil_array_list_free(arr[1], context->env);
+
+ return 1;
+}
+
/* Equal Expression */
int axiom_xpath_equalexpr_operator(
axiom_xpath_context_t *context,
@@ -309,14 +470,25 @@
axutil_stack_push(context->stack, context->env, node);
- return 1;
+ break;
}
}
+
+ if (j < n_nodes[1])
+ {
+ break;
+ }
}
- AXIOM_XPATH_CAST_SET_VALUE(axis2_bool_t, AXIS2_FALSE);
+ if (!node->value)
+ {
+ AXIOM_XPATH_CAST_SET_VALUE(axis2_bool_t, AXIS2_FALSE);
- axutil_stack_push(context->stack, context->env, node);
+ axutil_stack_push(context->stack, context->env, node);
+ }
+
+ axutil_array_list_free(arr[0], context->env);
+ axutil_array_list_free(arr[1], context->env);
return 1;
}
@@ -914,6 +1086,12 @@
case AXIOM_XPATH_OPERATION_UNION:
return axiom_xpath_union_operator;
+ case AXIOM_XPATH_OPERATION_OR_EXPR:
+ return axiom_xpath_orexpr_operator;
+
+ case AXIOM_XPATH_OPERATION_AND_EXPR:
+ return axiom_xpath_andexpr_operator;
+
case AXIOM_XPATH_OPERATION_EQUAL_EXPR:
return axiom_xpath_equalexpr_operator;
Modified: webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_engine.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_engine.h?rev=764212&r1=764211&r2=764212&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_engine.h (original)
+++ webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_engine.h Sat Apr 11 15:58:27 2009
@@ -36,10 +36,14 @@
/* 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)); \
+#define AXIOM_XPATH_CAST_SET_VALUE(_type, _value) { \
+ _type * _var; \
+ if(node->value \
+ && node->type != AXIOM_XPATH_TYPE_NODE \
+ && node->type != AXIOM_XPATH_TYPE_ATTRIBUTE \
+ && node->type != AXIOM_XPATH_TYPE_NAMESPACE) \
+ { AXIS2_FREE(context->env->allocator, node->value); } \
+ _var = AXIS2_MALLOC(context->env->allocator, sizeof(_type)); \
*_var = _value; \
node->value = (void *) _var; \
}
@@ -100,6 +104,24 @@
int axiom_xpath_union_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
/**
+ * Perform or operation
+ *
+ * @param context XPath context
+ * @param op XPath operation
+ * @return Number of nodes added to the stack; which is one
+ */
+ int axiom_xpath_orexpr_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
+
+ /**
+ * Perform and operation
+ *
+ * @param context XPath context
+ * @param op XPath operation
+ * @return Number of nodes added to the stack; which is one
+ */
+ int axiom_xpath_andexpr_operator(axiom_xpath_context_t *context, axiom_xpath_operation_t * op);
+
+ /**
* Perform equality test operation
*
* @param context XPath context
@@ -178,6 +200,15 @@
*/
void axiom_xpath_cast_string(axiom_xpath_result_node_t *node, axiom_xpath_context_t *context);
+ /* Convert a node set to boolean */
+ /**
+ * Convert a XPath node set to boolean
+ *
+ * @param node_set Node set
+ * @return AXIS2_TRUE if true; AXIS2_FALSE otherwise
+ */
+ axis2_bool_t axiom_xpath_convert_to_boolean(axutil_array_list_t *node_set, axiom_xpath_context_t *context);
+
/**
* Test if two result nodes are equal
*
Modified: webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_iterators.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_iterators.c?rev=764212&r1=764211&r2=764212&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_iterators.c (original)
+++ webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_iterators.c Sat Apr 11 15:58:27 2009
@@ -386,9 +386,9 @@
axutil_hash_t *ht;
axutil_hash_index_t *hi;
-/* void *key;
- * axis2_ssize_t klen;
- */
+ /* void *key;
+ * axis2_ssize_t klen;
+ */
void *attr;
AXIOM_XPATH_ITERATOR_INITIALIZE;
@@ -445,10 +445,10 @@
axutil_hash_t *ht;
axutil_hash_index_t *hi;
-/* void *key;
- * axis2_ssize_t klen;
- */
-
+ /* void *key;
+ * axis2_ssize_t klen;
+ */
+
void *ns;
AXIOM_XPATH_ITERATOR_INITIALIZE;
Modified: webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_parser.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_parser.c?rev=764212&r1=764211&r2=764212&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_parser.c (original)
+++ webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_parser.c Sat Apr 11 15:58:27 2009
@@ -59,12 +59,110 @@
}
}
-/* Parse Or Expression : Stub*/
+/* Parse Or Expression */
int axiom_xpath_compile_orexpr(
const axutil_env_t *env,
axiom_xpath_expression_t* expr)
{
- return axiom_xpath_compile_equalexpr(env, expr);
+ int op1, op2;
+
+ if (!AXIOM_XPATH_HAS_MORE)
+ {
+ return AXIOM_XPATH_PARSE_END;
+ }
+
+ op1 = axiom_xpath_compile_andexpr(env, expr);
+
+ if (op1 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: AndEpxr expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ while (AXIOM_XPATH_CURRENT == 'o' && AXIOM_XPATH_NEXT(1) == 'r')
+ {
+ AXIOM_XPATH_READ(2);
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ op2 = axiom_xpath_compile_andexpr(env, expr);
+
+ if (op2 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: AndEpxr expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ op1 = AXIOM_XPATH_PUSH(AXIOM_XPATH_OPERATION_OR_EXPR, op1, op2);
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+ }
+
+ return op1;
+}
+
+/* Parse And Expression */
+int axiom_xpath_compile_andexpr(
+ 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_equalexpr(env, expr);
+
+ if (op1 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: EqualityExpr expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ while (AXIOM_XPATH_CURRENT == 'a' && AXIOM_XPATH_NEXT(1) == 'n' && AXIOM_XPATH_NEXT(1) == 'd')
+ {
+ AXIOM_XPATH_READ(2);
+ AXIOM_XPATH_SKIP_WHITESPACES;
+
+ op2 = axiom_xpath_compile_equalexpr(env, expr);
+
+ if (op2 == AXIOM_XPATH_PARSE_ERROR)
+ {
+#ifdef AXIOM_XPATH_DEBUG
+ printf(
+ "Parse error: EqualityExpr expected - %s\n",
+ expr->expr_str + expr->expr_ptr);
+#endif
+
+ return AXIOM_XPATH_PARSE_ERROR;
+ }
+
+ op1 = AXIOM_XPATH_PUSH(AXIOM_XPATH_OPERATION_AND_EXPR, op1, op2);
+
+ AXIOM_XPATH_SKIP_WHITESPACES;
+ }
+
+ return op1;
}
/* Parse Equality Expression */
@@ -1090,13 +1188,13 @@
return NULL;
}
- /* TODO: Add CombiningChar and Extender
- * Link http://www.w3.org/TR/REC-xml/#NT-NameChar */
+ /* 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 == '-'))
+ || AXIOM_XPATH_CURRENT == '-'))
{
name[i] = AXIOM_XPATH_CURRENT;
AXIOM_XPATH_READ(1);
Modified: webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_parser.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_parser.h?rev=764212&r1=764211&r2=764212&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_parser.h (original)
+++ webservices/axis2/trunk/c/axiom/src/xpath/xpath_internals_parser.h Sat Apr 11 15:58:27 2009
@@ -233,8 +233,10 @@
axiom_xpath_expression_t* expr);
/**
- * Compiles an OrExpr. This function is not complete.
+ * Compiles an OrExpr.
*
+ * [21] OrExpr ::= AndExpr
+ * | OrExpr 'or' AndExpr
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
@@ -244,6 +246,20 @@
axiom_xpath_expression_t* expr);
/**
+ * Compiles an AndExpr.
+ *
+ * [22] AndExpr ::= EqualityExpr
+ * | AndExpr 'and' EqualityExpr
+ * @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_andexpr(
+ const axutil_env_t *env,
+ axiom_xpath_expression_t* expr);
+
+
+ /**
* Compiles a FunctionCall
*
* [16] FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument )* )? ')'