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 sa...@apache.org on 2005/10/14 12:07:54 UTC
svn commit: r321065 - in /webservices/axis2/trunk/c: include/axis2_om_node.h
modules/xml/om/src/axis2_om_node.c
Author: samisa
Date: Fri Oct 14 03:07:45 2005
New Revision: 321065
URL: http://svn.apache.org/viewcvs?rev=321065&view=rev
Log:
axis2_om_node changed and patch applied .
Modified:
webservices/axis2/trunk/c/include/axis2_om_node.h
webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_node.c
Modified: webservices/axis2/trunk/c/include/axis2_om_node.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_om_node.h?rev=321065&r1=321064&r2=321065&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_om_node.h (original)
+++ webservices/axis2/trunk/c/include/axis2_om_node.h Fri Oct 14 03:07:45 2005
@@ -19,16 +19,21 @@
/**
* @file axis2_om_node.h
- * @brief defines node data structure, used for constructing the om tree and its
- * manipulation functions
+ * @brief defines axis2_om_node_t struct and its operations
*/
+#include <axis2_environment.h>
+#include <axis2_om_output.h>
+struct axis2_om_node;
+struct axis2_om_node_ops;
+//struct axis2_om_output;
+//typedef struct axis2_om_output axis2_om_output_t;
-#include <axis2.h>
-typedef struct axis2_stax_om_builder_s axis2_stax_om_builder_t;
-typedef struct axis2_om_output_s axis2_om_output_t;
-typedef struct axis2_om_element_s axis2_om_element_t;
+/**
+ * Types used in OM
+ */
+
typedef enum axis2_om_types_t {
AXIS2_OM_INVALID = -1,
@@ -42,6 +47,92 @@
AXIS2_OM_TEXT = 80
} axis2_om_types_t;
+
+/**
+ * Encapsulator struct of axis2_om_node operations
+ */
+
+typedef struct axis2_om_node_ops
+{
+ /**
+ * Free an om node and its all children
+ * @return status code
+ */
+ axis2_status_t (*axis2_om_node_ops_free)(axis2_environment_t *environment,
+ struct axis2_om_node *om_node);
+ /**
+ * Add child node as child to parent
+ * @param parent
+ * @param child
+ * @return status code
+ */
+ axis2_status_t (*axis2_om_node_ops_add_child)(axis2_environment_t *environment,
+ struct axis2_om_node *parent,struct axis2_om_node *child);
+
+ /**
+ * detach this node from the node and reset the links
+ * @return a pointer to detached node
+ */
+ struct axis2_om_node *(*axis2_om_node_ops_detach)(axis2_environment_t *environment,
+ struct axis2_om_node *om_node);
+
+ /**
+ * Inserts a sibling node after the current node
+ * @param current_node
+ * @param node_to_insert the node that will be inserted
+ * @return return status code
+ */
+ axis2_status_t (*axis2_om_node_ops_insert_sibling_after)(axis2_environment_t *environment,
+ struct axis2_om_node *current_node,struct axis2_om_node *node_to_insert);
+
+ /**
+ * Inserts a sibling node after the current node
+ * @param current_node
+ * @param node_to_insert the node that will be inserted
+ * @return status code
+ */
+
+ axis2_status_t (*axis2_om_node_ops_insert_sibling_before)(axis2_environment_t *environment,
+ struct axis2_om_node *current_node,struct axis2_om_node *node_to_insert);
+
+ /**
+ * set a parent node to a given node
+ * @param child_node
+ * @param parent the node that will be set as parent
+ * @return status code
+ */
+
+ axis2_status_t (*axis2_om_node_ops_set_parent)(axis2_environment_t *environment,
+ struct axis2_om_node *child_node,struct axis2_om_node *parent_node);
+
+ /** get the first child of a node
+ * returns the first child node of this node
+ * @param
+ * @return returns a pointer to first child if there is no child returns null
+ */
+ struct axis2_om_node *(*axis2_om_node_ops_get_first_child)(axis2_environment_t *environment,
+ struct axis2_om_node *parent_node);
+ /**
+ * get the next child of this node
+ * This function should only be called after a call to get_first_child function
+ * @param parent_node
+ * @return pointer to next child , if there isn't next child returns null
+ */
+ struct axis2_om_node *(*axis2_om_node_ops_get_next_child)(axis2_environment_t *environment,
+ struct axis2_om_node *parent_node);
+
+ /**
+ * serialize operation of node
+ * @returns status code
+ */
+
+ axis2_status_t (*axis2_om_node_ops_serialize)(axis2_environment_t *environment,
+ struct axis2_om_node *om_node, axis2_om_output_t * om_output);
+
+
+}axis2_om_node_ops_t;
+
+
/**
* This is the structure that defines a node in om tree
* @param parent - parent node if one is available
@@ -53,77 +144,48 @@
* we keep pointers parent , previous sibling , next sibling ,
* first child and last child for constructing and navigating the tree
*
-*/
-
+*/
-typedef struct axis2_om_node_t {
- struct axis2_om_node_t *parent;
- struct axis2_om_node_t *prev_sibling;
- struct axis2_om_node_t *next_sibling;
- struct axis2_om_node_t *first_child;
- struct axis2_om_node_t *current_child;
- struct axis2_om_node_t *last_child;
- axis2_stax_om_builder_t *builder;
- axis2_om_types_t element_type;
+typedef struct axis2_om_node{
+ /** operations of this struct */
+ axis2_om_node_ops_t *ops;
+ /** links that maintain the tree */
+ struct axis2_om_node *parent;
+ struct axis2_om_node *prev_sibling;
+ struct axis2_om_node *next_sibling;
+ struct axis2_om_node *first_child;
+ struct axis2_om_node *current_child;
+ struct axis2_om_node *last_child;
+
+ /** indicate the type stored in data_element */
+ axis2_om_types_t node_type;
+ /** done true means that this node is completely built , false otherwise */
int done;
+
+ /** instances of om struct types will be stored here */
void* data_element;
} axis2_om_node_t;
/**
* Create a node struct.
- * @return a node or NULL if there isn't enough memory
- */
-
-axis2_om_node_t *axis2_om_node_create();
-
-/**
- * destroy the node .
- * @param node to free
- */
-void axis2_om_node_free(axis2_om_node_t *node);
-
-/**
- * adds a child node to this node .
- * @param parent parent node
- * @param child child node
+ * @return a pointer to node struct instance null otherwise
*/
+axis2_om_node_t *axis2_om_node_create(axis2_environment_t *environment);
-void axis2_om_node_add_child(axis2_om_node_t *parent,axis2_om_node_t *child);
-
-/**
- * detach a node from the tree and resets the links
- * @param node_to_detach the node to be detached
- *
- */
-
-axis2_om_node_t *axis2_om_node_detach(axis2_om_node_t *node_to_detach);
-
-/**
- * inserts a sibling node after the current node
- * @param current_node the node in consideration
- * @param node_to_insert the node that will be inserted
- */
-
-void axis2_om_node_insert_sibling_after(axis2_om_node_t *current_nodee,axis2_om_node_t *node_to_insert);
-
-void axis2_om_node_insert_sibling_before(axis2_om_node_t *current_ele,axis2_om_node_t *nodeto_insert);
-
-
-/*int axis2_om_node_build(axis2_om_node_t *node);*/
-
-/**
- * set a parent node to a given node
- * @param node
- * @param parent the node that will be set as parent
- */
-
-void axis2_om_node_set_parent(axis2_om_node_t *node,axis2_om_node_t *parent);
+#define axis2_om_node_free(environment,om_node) ((om_node)->ops->axis2_om_node_ops_free(environment,om_node))
+#define axis2_om_node_add_child(environment,parent,child) ((parent)->ops->axis2_om_node_ops_add_child(environment,parent,child))
+#define axis2_om_node_detach(environment,om_node) ((om_node)->ops->axis2_om_node_ops_detach(environment,om_node))
+#define axis2_om_node_insert_sibling_after(environment,current_node,node_to_insert) \
+ ((current_node)->ops->axis2_om_node_ops_insert_sibling_after(environment,current_node,node_to_insert))
+
+#define axis2_om_node_insert_sibling_before(environment,current_node,node_to_insert) ((current_node)->ops->axis2_om_node_ops_insert_sibling_before(environment,current_node,node_to_insert))
+#define axis2_om_node_set_parent(environment,child_node,parent_node) ((child_node)->ops->axis2_om_node_ops_set_parent(environment,child_node,parent_node))
+#define axis2_om_node_get_first_child(environment,om_node) ((om_node)->ops->axis2_om_node_get_ops_first_child(environment,om_node))
+#define axis2_om_node_get_next_child(environment,om_node) ((om_node)->ops->axis2_om_node_get_ops_next_child(environemt,om_node))
+#define axis2_om_node_serialize(environment,om_node,om_output) ((om_node)->ops->axis2_om_node_ops_serialize(environment,om_node,om_output))
-axis2_om_node_t *axis2_om_node_get_first_child(axis2_om_node_t *parent_node);
-axis2_om_node_t *axis2_om_node_get_next_child(axis2_om_node_t *parent_node);
-int *axis2_om_node_serialize(axis2_om_node_t *om_node, axis2_om_output_t * om_output);
#endif /* AXIS2_OM_NODE_H */
Modified: webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_node.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_node.c?rev=321065&r1=321064&r2=321065&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_node.c (original)
+++ webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_node.c Fri Oct 14 03:07:45 2005
@@ -15,42 +15,111 @@
*/
#include <axis2_om_node.h>
-#include <axis2_om_text.h>
-axis2_om_node_t *axis2_om_node_create()
+axis2_status_t axis2_om_node_impl_free(axis2_environment_t *environment,axis2_om_node_t * node);
+axis2_status_t axis2_om_node_impl_add_child(axis2_environment_t *environment,axis2_om_node_t * parent, axis2_om_node_t * child);
+axis2_om_node_t *axis2_om_node_impl_detach(axis2_environment_t *environment,axis2_om_node_t *node_to_detach);
+axis2_status_t axis2_om_node_impl_set_parent(axis2_environment_t *environment,axis2_om_node_t * node,axis2_om_node_t *parent);
+axis2_status_t axis2_om_node_impl_insert_sibling_after(axis2_environment_t *environment,axis2_om_node_t *node,axis2_om_node_t *node_to_insert);
+axis2_status_t axis2_om_node_impl_insert_sibling_before(axis2_environment_t *environment ,axis2_om_node_t *node,axis2_om_node_t *node_to_insert);
+axis2_om_node_t *axis2_om_node_impl_get_first_child(axis2_environment_t *environment,axis2_om_node_t *parent_node);
+axis2_om_node_t *axis2_om_node_impl_get_next_child(axis2_environment_t *environment,axis2_om_node_t *parent_node);
+axis2_status_t *axis2_om_node_impl_serialize(axis2_environment_t *environment,axis2_om_node_t *om_node, axis2_om_output_t * om_output);
+
+
+axis2_om_node_t *axis2_om_node_create(axis2_environment_t *environment)
{
- axis2_om_node_t *node = (axis2_om_node_t *) malloc(sizeof(axis2_om_node_t));
-
- if (!node)
+ axis2_om_node_t *node = (axis2_om_node_t *)axis2_malloc(environment->allocator,sizeof(axis2_om_node_t));
+ if (!node)
{
+ environment->error->errorno = AXIS2_ERROR_NO_MEMORY;
return NULL;
}
-
+ node->ops = (axis2_om_node_ops_t *)axis2_malloc(environment->allocator,sizeof(axis2_om_node_ops_t));
+ if(!(node->ops))
+ {
+ axis2_free(environment->allocator,node);
+ environment->error->errorno = AXIS2_ERROR_NO_MEMORY;
+ return NULL;
+ }
+ /* assign fucn pointers */
+ node->ops->axis2_om_node_ops_add_child = axis2_om_node_impl_add_child;
+ node->ops->axis2_om_node_ops_free = axis2_om_node_impl_free;
+ node->ops->axis2_om_node_ops_detach = axis2_om_node_impl_detach;
+ node->ops->axis2_om_node_ops_get_first_child = axis2_om_node_impl_get_first_child;
+ node->ops->axis2_om_node_ops_insert_sibling_after = axis2_om_node_impl_insert_sibling_after;
+ node->ops->axis2_om_node_ops_insert_sibling_before = axis2_om_node_impl_insert_sibling_before;
+ node->ops->axis2_om_node_ops_set_parent = axis2_om_node_impl_set_parent;
+ node->ops->axis2_om_node_ops_serialize = axis2_om_node_impl_serialize;
+ node->ops->axis2_om_node_ops_get_next_child = axis2_om_node_impl_get_next_child;
+
node->first_child = NULL;
node->last_child = NULL;
node->next_sibling = NULL;
node->prev_sibling = NULL;
node->parent = NULL;
- node->element_type = AXIS2_OM_INVALID;
+ node->node_type = AXIS2_OM_INVALID;
node->done = AXIS2_FALSE;
- node->builder = NULL;
node->data_element = NULL;
node->current_child = NULL;
return node;
}
-
-void axis2_om_node_free(axis2_om_node_t * node)
+/**
+ * This free fucntion will free an om_element and all the children contained in it
+ * before calling this function first free
+ */
+axis2_status_t axis2_om_node_impl_free(axis2_environment_t *environment,axis2_om_node_t * node)
{
- if (!node)
- return;
+
+ if(!node)
+ {
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
+ return AXIS2_FAILURE;
+ }
+ if(node->first_child)
+ {
+ while(!(node->first_child))
+ {
+ axis2_om_node_t *node = NULL;
+ node = axis2_om_node_detach(environment,node->first_child);
+ axis2_om_node_free(environment,node);
+ }
+ }
+ switch(node->node_type)
+ {
+ case AXIS2_OM_ELEMENT:
+ /*axis2_om_element_free(environment,(axis2_om_element_t*)node->data_element) */
+ break;
+
+ case AXIS2_OM_COMMENT:
+ /* axis2_om_comment_free(environment,(axis2_om_comment_t*)node->data_element) */
+ break;
+ case AXIS2_OM_DOCTYPE:
+ /* axis2_om_doctype_free(environment,(axis2_om_doctype_t*)node->data_element) */
+ break;
+ case AXIS2_OM_PROCESSING_INSTRUCTION:
+ /* axis2_om_prcessing_instruction_free(environment,(axis2_om_processing_instruction)node->data_element) */
+ break;
+ case AXIS2_OM_TEXT:
+ /* axis2_om_text_free(environment,(axis2_om_text_t*)node->data_element); */
+ break;
+
+ default:
+ break;
+ }
+
+ axis2_free(environment->allocator,node->ops);
+ return AXIS2_SUCCESS;
}
-void axis2_om_node_add_child(axis2_om_node_t * parent, axis2_om_node_t * child)
+axis2_status_t axis2_om_node_impl_add_child(axis2_environment_t *environment,
+ axis2_om_node_t * parent, axis2_om_node_t * child)
{
if (!parent || !child)
{
- return;
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
+ return AXIS2_FAILURE;
}
if (parent->first_child == NULL)
{
@@ -64,26 +133,22 @@
child->parent = parent;
parent->last_child = child;
-
+ return AXIS2_SUCCESS;
}
-axis2_om_node_t *axis2_om_node_detach(axis2_om_node_t * node_to_detach)
+axis2_om_node_t *axis2_om_node_impl_detach(axis2_environment_t *environment,axis2_om_node_t *node_to_detach)
{
axis2_om_node_t *parent = NULL;
- if (!node_to_detach)
+ if (!node_to_detach || !(node_to_detach->parent))
{
+ /* nodes that do not have a parent can't be detached */
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
return NULL;
}
- if (!(node_to_detach->parent))
- {
- /* nodes that do not have a parent can't be detached */
- return NULL;
- }
-
parent = node_to_detach->parent;
if ((node_to_detach->prev_sibling) == NULL)
@@ -102,29 +167,31 @@
}
node_to_detach->parent = NULL;
-
return node_to_detach;
}
-void axis2_om_node_set_parent(axis2_om_node_t * node,axis2_om_node_t *parent)
+axis2_status_t axis2_om_node_impl_set_parent(axis2_environment_t *environment,axis2_om_node_t * node,axis2_om_node_t *parent)
{
if(!parent || !node)
{
- return ;
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
+ return AXIS2_FAILURE;
}
-
if(parent == node->parent )
{/* same parent already exist */
- return ;
+ return AXIS2_SUCCESS;
}
- /* if a new parent is assigned in place of existing */
- /* one first the node should be detached */
+ /* if a new parent is assigned in place of existing
+ * one first the node should be detached
+ */
if(!(node->parent))
{
- axis2_om_node_detach(node);
+ axis2_om_node_detach(environment,node);
+
}
node->parent = parent;
+ return AXIS2_SUCCESS;
}
/**
@@ -133,12 +200,13 @@
* @param nodeto_insert the node that will be inserted
*/
-void axis2_om_node_insert_sibling_after(axis2_om_node_t *node,
+axis2_status_t axis2_om_node_impl_insert_sibling_after(axis2_environment_t *environment,axis2_om_node_t *node,
axis2_om_node_t *node_to_insert)
{
if(!node || !node_to_insert )
{
- return ;
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
+ return AXIS2_FAILURE;
}
node_to_insert->parent = node->parent;
node_to_insert->prev_sibling = node;
@@ -147,18 +215,19 @@
{
node->next_sibling->prev_sibling = node_to_insert;
}
-
node_to_insert->next_sibling = node->next_sibling;
node->next_sibling = node_to_insert;
+ return AXIS2_SUCCESS;
}
-void axis2_om_node_insert_sibling_before(axis2_om_node_t *node,
- axis2_om_node_t *node_to_insert)
+axis2_status_t axis2_om_node_impl_insert_sibling_before(axis2_environment_t *environment
+ ,axis2_om_node_t *node, axis2_om_node_t *node_to_insert)
{
if(!node || !node_to_insert )
- {
- return;
+ {
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
+ return AXIS2_FAILURE;
}
node_to_insert->parent = node->parent;
@@ -173,16 +242,18 @@
else
{
node->prev_sibling->next_sibling = node_to_insert;
-
}
node->prev_sibling = node_to_insert;
+ return AXIS2_SUCCESS;
}
-axis2_om_node_t *axis2_om_node_get_first_child(axis2_om_node_t *parent_node)
+axis2_om_node_t *axis2_om_node_impl_get_first_child(axis2_environment_t *environment
+ ,axis2_om_node_t *parent_node)
{
/** */
if(!parent_node)
{
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
return NULL;
}
if(parent_node->first_child)
@@ -190,21 +261,23 @@
parent_node->current_child = parent_node->first_child;
return parent_node->first_child;
}
+
return NULL;
}
-axis2_om_node_t *axis2_om_node_get_next_child(axis2_om_node_t *parent_node)
+axis2_om_node_t *axis2_om_node_impl_get_next_child(axis2_environment_t *environment
+ ,axis2_om_node_t *parent_node)
{
axis2_om_node_t *node=NULL;
if(parent_node && !(parent_node->first_child))
{
- /*fprintf(stderr,"Error ");*/
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
return NULL;
}
if(parent_node && parent_node->first_child && !(parent_node->current_child))
{
- /*fprintf(stderr,"Error first call get_first_child");*/
+ environment->error->errorno = AXIS2_ERROR_INVALID_OPERATION;
return NULL;
}
if(parent_node->current_child->next_sibling)
@@ -216,14 +289,17 @@
return NULL;
}
-int *axis2_om_node_serialize(axis2_om_node_t *om_node, axis2_om_output_t * om_output)
+axis2_status_t *axis2_om_node_impl_serialize(axis2_environment_t *environment,axis2_om_node_t *om_node, axis2_om_output_t * om_output)
{
+/* axis2_om_node_t *child_node = NULL;
+ int status = AXIS2_SUCCESS;
+
if (!om_node || !om_output)
- return AXIS2_ERROR_INVALID_POINTER_PARAMATERS;
+ return AXIS2_ERROR_INVALID_NULL_PARAMETER;
- int status = AXIS2_SUCCESS;
- switch (om_node->element_type)
+
+ switch (om_node->node_type)
{
case AXIS2_OM_ELEMENT:
status = axis2_om_element_serialize_start_part( (axis2_om_element_t*)om_node->data_element, om_output );
@@ -236,8 +312,8 @@
break;
}
- /* handle children*/
- axis2_om_node_t *child_node = axis2_om_node_get_first_child(om_node);
+
+ child_node = axis2_om_node_get_first_child(environment,om_node);
while (child_node)
{
@@ -257,5 +333,8 @@
}
return status;
-
+*/
+return AXIS2_SUCCESS;
}
+
+