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 sa...@apache.org on 2007/03/28 08:11:26 UTC

svn commit: r523189 - in /webservices/axis2/trunk/c/axiom: include/axiom_node.h src/om/om_node.c test/om/test_om.c test/resources/xml/om/test.xml

Author: samisa
Date: Tue Mar 27 23:11:25 2007
New Revision: 523189

URL: http://svn.apache.org/viewvc?view=rev&rev=523189
Log:
Fixed serialize logic and also added a serialize sub tree method to deal with the bug of not serializing the namespaces properly in case of serializing a sub tree

Modified:
    webservices/axis2/trunk/c/axiom/include/axiom_node.h
    webservices/axis2/trunk/c/axiom/src/om/om_node.c
    webservices/axis2/trunk/c/axiom/test/om/test_om.c
    webservices/axis2/trunk/c/axiom/test/resources/xml/om/test.xml

Modified: webservices/axis2/trunk/c/axiom/include/axiom_node.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/include/axiom_node.h?view=diff&rev=523189&r1=523188&r2=523189
==============================================================================
--- webservices/axis2/trunk/c/axiom/include/axiom_node.h (original)
+++ webservices/axis2/trunk/c/axiom/include/axiom_node.h Tue Mar 27 23:11:25 2007
@@ -269,6 +269,10 @@
     axiom_node_to_string(axiom_node_t *om_node,
             const axis2_env_t *env);
 
+    AXIS2_EXTERN axis2_status_t AXIS2_CALL
+    axiom_node_serialize_sub_tree(axiom_node_t *om_node,
+        const axis2_env_t *env,
+        struct axiom_output *om_output);
 
 #define AXIOM_NODE_FREE_TREE(om_node,env) \
         axiom_node_free(om_node,env)

Modified: webservices/axis2/trunk/c/axiom/src/om/om_node.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/om/om_node.c?view=diff&rev=523189&r1=523188&r2=523189
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/om/om_node.c (original)
+++ webservices/axis2/trunk/c/axiom/src/om/om_node.c Tue Mar 27 23:11:25 2007
@@ -341,6 +341,8 @@
 
     int status = AXIS2_SUCCESS;
     axiom_node_t *temp_node = NULL;
+    axiom_node_t *nodes[256];
+    int count = 0;
 
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
 
@@ -349,109 +351,359 @@
         return AXIS2_SUCCESS;
     }
 
+    nodes[count++] = om_node;
+
     AXIS2_PARAM_CHECK(env->error, om_output, AXIS2_FAILURE);
 
-    if (om_node->node_type == AXIOM_ELEMENT)
-    {
-        if (om_node->data_element)
-        {
-            status = axiom_element_serialize_start_part((axiom_element_t *)(om_node->data_element),
-                env,
-                om_output,
-                om_node);
-        }
-        if (status != AXIS2_SUCCESS)
-        {
-            return status;
-        }
-    }
-    else if (om_node->node_type == AXIOM_DATA_SOURCE)
-    {
-        if (om_node->data_element)
-        {
-            status = axiom_data_source_serialize((axiom_data_source_t*)(om_node->data_element),
-                env, om_output);
-        }
-        if (status != AXIS2_SUCCESS)
-        {
-            return status;
-        }
-    }
-    else if (om_node->node_type == AXIOM_TEXT)
-    {
-        if (om_node->data_element)
-        {
-            status = axiom_text_serialize((axiom_text_t*)(om_node->data_element),
-                env, om_output);
-        }
-        if (status != AXIS2_SUCCESS)
-        {
-            return status;
-        }
-    }
-    else if (om_node->node_type == AXIOM_COMMENT)
-    {
-        if (om_node->data_element)
-        {
-            status = axiom_comment_serialize((axiom_comment_t*)(om_node->data_element),
-                env, om_output);
-        }
-        if (status != AXIS2_SUCCESS)
-        {
-            return status;
-        }
-    }
-    else if (om_node->node_type == AXIOM_DOCTYPE)
-    {
-        if (om_node->data_element)
-        {
-            status = axiom_doctype_serialize((axiom_doctype_t*)(om_node->data_element),
-                env, om_output);
-        }
-        if (status != AXIS2_SUCCESS)
-        {
-            return status;
-        }
-    }
-    else if (om_node->node_type == AXIOM_PROCESSING_INSTRUCTION)
-    {
-        if (om_node->data_element)
+    do {
+
+        if (om_node->node_type == AXIOM_ELEMENT)
         {
-            status =
-                axiom_processing_instruction_serialize((axiom_processing_instruction_t*)(om_node->data_element),
+            if (om_node->data_element)
+            {
+                status = axiom_element_serialize_start_part((axiom_element_t *)(om_node->data_element),
+                    env,
+                    om_output,
+                    om_node);
+            }
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
+        }
+        else if (om_node->node_type == AXIOM_DATA_SOURCE)
+        {
+            if (om_node->data_element)
+            {
+                status = axiom_data_source_serialize((axiom_data_source_t*)(om_node->data_element),
                     env, om_output);
+            }
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
+        }
+        else if (om_node->node_type == AXIOM_TEXT)
+        {
+            if (om_node->data_element)
+            {
+                status = axiom_text_serialize((axiom_text_t*)(om_node->data_element),
+                    env, om_output);
+            }
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
+        }
+        else if (om_node->node_type == AXIOM_COMMENT)
+        {
+            if (om_node->data_element)
+            {
+                status = axiom_comment_serialize((axiom_comment_t*)(om_node->data_element),
+                    env, om_output);
+            }
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
+        }
+        else if (om_node->node_type == AXIOM_DOCTYPE)
+        {
+            if (om_node->data_element)
+            {
+                status = axiom_doctype_serialize((axiom_doctype_t*)(om_node->data_element),
+                    env, om_output);
+            }
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
+        }
+        else if (om_node->node_type == AXIOM_PROCESSING_INSTRUCTION)
+        {
+            if (om_node->data_element)
+            {
+                status =
+                    axiom_processing_instruction_serialize((axiom_processing_instruction_t*)(om_node->data_element),
+                        env, om_output);
+            }
+
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
         }
 
-        if (status != AXIS2_SUCCESS)
-        {
-            return status;
+
+        temp_node = axiom_node_get_first_child(om_node, env);
+        /* serialize children of this node */
+        if (temp_node)
+        {
+            om_node = temp_node;
+            nodes[count++] = om_node;
+        }
+        else
+        {
+            if (om_node->node_type == AXIOM_ELEMENT)
+            {
+                if (om_node->data_element)
+                {
+                    status = axiom_element_serialize_end_part((axiom_element_t *)(om_node->data_element),
+                        env, om_output);
+                }
+                if (status != AXIS2_SUCCESS)
+                {
+                    return status;
+                }
+            }
+            
+            temp_node = AXIOM_NODE_GET_NEXT_SIBLING(om_node, env);
+            if (temp_node)
+            {
+                om_node = temp_node;
+                nodes[count -1] = om_node;
+            }
+            else
+            {
+                while (count > 1 && !temp_node)
+                {
+                    count--;
+                    om_node = nodes[count -1];
+                    if (om_node->node_type == AXIOM_ELEMENT)
+                    {
+                        if (om_node->data_element)
+                        {
+                            status = axiom_element_serialize_end_part((axiom_element_t *)(om_node->data_element),
+                                env, om_output);
+                        }
+                        if (status != AXIS2_SUCCESS)
+                        {
+                            return status;
+                        }
+                    }
+
+                    temp_node = AXIOM_NODE_GET_NEXT_SIBLING(om_node, env);
+                }
+               
+                if (temp_node && count > 1)
+                {
+                    om_node = temp_node;
+                    nodes[count -1] = om_node;
+                }
+                else
+                {
+                    count--;
+                }
+            }
+           
         }
-    }
+    } while(count > 0);
 
+    return status;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axiom_node_serialize_sub_tree(axiom_node_t *om_node,
+    const axis2_env_t *env,
+    axiom_output_t *om_output)
+{
+
+    int status = AXIS2_SUCCESS;
+    axiom_node_t *temp_node = NULL;
+    axiom_node_t *nodes[256];
+    int count = 0;
+    axis2_hash_t *namespaces = NULL;
 
-    temp_node = axiom_node_get_first_child(om_node, env);
-    /* serialize children of this node */
-    while (temp_node)
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (!om_node)
     {
-        status =  axiom_node_serialize(temp_node, env, om_output);
-        temp_node = AXIOM_NODE_GET_NEXT_SIBLING(temp_node, env);
+        return AXIS2_SUCCESS;
     }
 
-    if (om_node->node_type == AXIOM_ELEMENT)
-    {
-        if (om_node->data_element)
+    namespaces = axis2_hash_make(env);
+    nodes[count++] = om_node;
+
+    AXIS2_PARAM_CHECK(env->error, om_output, AXIS2_FAILURE);
+
+    do {
+
+        if (om_node->node_type == AXIOM_ELEMENT)
         {
-            status = axiom_element_serialize_end_part((axiom_element_t *)(om_node->data_element),
-                env, om_output);
+            if (om_node->data_element)
+            {
+                axis2_hash_t *temp_namespaces = NULL;
+                axiom_namespace_t *namespace = NULL;
+                status = axiom_element_serialize_start_part(
+                    (axiom_element_t *)(om_node->data_element),
+                    env,
+                    om_output,
+                    om_node);
+                temp_namespaces = axiom_element_get_namespaces(
+                    (axiom_element_t *)(om_node->data_element), env);
+                if (temp_namespaces)
+                {
+                    axis2_hash_t *new_hash = NULL;
+                    new_hash = axis2_hash_overlay(temp_namespaces, env, namespaces);
+                    axis2_hash_free(namespaces, env);
+                    namespaces = new_hash;
+                }
+                namespace = axiom_element_get_namespace(
+                    (axiom_element_t *)(om_node->data_element), env, om_node);
+                if (namespace)
+                {
+                    axiom_namespace_t *ns = NULL;
+                    axis2_char_t *prefix = NULL;
+                    prefix = axiom_namespace_get_prefix(namespace, env);
+                    if (prefix)
+                    {
+                        ns = axis2_hash_get(namespaces, prefix, AXIS2_HASH_KEY_STRING);
+                        if (!ns)
+                        {
+                            axiom_namespace_serialize(namespace, env, om_output);
+                            axis2_hash_set(namespaces, prefix, 
+                                AXIS2_HASH_KEY_STRING, namespace);
+                        }
+                    }
+                }
+                
+            }
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
+        }
+        else if (om_node->node_type == AXIOM_DATA_SOURCE)
+        {
+            if (om_node->data_element)
+            {
+                status = axiom_data_source_serialize((axiom_data_source_t*)(om_node->data_element),
+                    env, om_output);
+            }
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
+        }
+        else if (om_node->node_type == AXIOM_TEXT)
+        {
+            if (om_node->data_element)
+            {
+                status = axiom_text_serialize((axiom_text_t*)(om_node->data_element),
+                    env, om_output);
+            }
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
+        }
+        else if (om_node->node_type == AXIOM_COMMENT)
+        {
+            if (om_node->data_element)
+            {
+                status = axiom_comment_serialize((axiom_comment_t*)(om_node->data_element),
+                    env, om_output);
+            }
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
+        }
+        else if (om_node->node_type == AXIOM_DOCTYPE)
+        {
+            if (om_node->data_element)
+            {
+                status = axiom_doctype_serialize((axiom_doctype_t*)(om_node->data_element),
+                    env, om_output);
+            }
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
+        }
+        else if (om_node->node_type == AXIOM_PROCESSING_INSTRUCTION)
+        {
+            if (om_node->data_element)
+            {
+                status =
+                    axiom_processing_instruction_serialize((axiom_processing_instruction_t*)(om_node->data_element),
+                        env, om_output);
+            }
+
+            if (status != AXIS2_SUCCESS)
+            {
+                return status;
+            }
         }
-        if (status != AXIS2_SUCCESS)
-        {
-            return status;
+
+
+        temp_node = axiom_node_get_first_child(om_node, env);
+        /* serialize children of this node */
+        if (temp_node)
+        {
+            om_node = temp_node;
+            nodes[count++] = om_node;
+        }
+        else
+        {
+            if (om_node->node_type == AXIOM_ELEMENT)
+            {
+                if (om_node->data_element)
+                {
+                    status = axiom_element_serialize_end_part((axiom_element_t *)(om_node->data_element),
+                        env, om_output);
+                }
+                if (status != AXIS2_SUCCESS)
+                {
+                    return status;
+                }
+            }
+            
+            temp_node = AXIOM_NODE_GET_NEXT_SIBLING(om_node, env);
+            if (temp_node)
+            {
+                om_node = temp_node;
+                nodes[count -1] = om_node;
+            }
+            else
+            {
+                while (count > 1 && !temp_node)
+                {
+                    count--;
+                    om_node = nodes[count -1];
+                    if (om_node->node_type == AXIOM_ELEMENT)
+                    {
+                        if (om_node->data_element)
+                        {
+                            status = axiom_element_serialize_end_part((axiom_element_t *)(om_node->data_element),
+                                env, om_output);
+                        }
+                        if (status != AXIS2_SUCCESS)
+                        {
+                            return status;
+                        }
+                    }
+
+                    temp_node = AXIOM_NODE_GET_NEXT_SIBLING(om_node, env);
+                }
+               
+                if (temp_node && count > 1)
+                {
+                    om_node = temp_node;
+                    nodes[count -1] = om_node;
+                }
+                else
+                {
+                    count--;
+                }
+            }
+           
         }
-    }
+    } while(count > 0);
 
     return status;
 }
+
 
 AXIS2_EXTERN axiom_node_t *AXIS2_CALL
 axiom_node_get_parent(axiom_node_t *om_node,

Modified: webservices/axis2/trunk/c/axiom/test/om/test_om.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/test/om/test_om.c?view=diff&rev=523189&r1=523188&r2=523189
==============================================================================
--- webservices/axis2/trunk/c/axiom/test/om/test_om.c (original)
+++ webservices/axis2/trunk/c/axiom/test/om/test_om.c Tue Mar 27 23:11:25 2007
@@ -65,6 +65,7 @@
     axiom_text_t *text = NULL;
     axiom_document_t *document = NULL;
     axiom_node_t *node1 = NULL, *node2 = NULL;
+    axiom_node_t *node3 = NULL;
     axiom_output_t *om_output = NULL;
     axiom_namespace_t* ns = NULL;
     axiom_xml_reader_t *reader = NULL;
@@ -150,6 +151,8 @@
                 {
                     printf("\n localname %s\n" , axiom_element_get_localname(ele2, environment));
                 }
+                if (!node3)
+                    node3 = node2;
 
                 break;
             case AXIOM_TEXT:
@@ -174,7 +177,7 @@
             AXIS2_XML_PARSER_TYPE_BUFFER);
     om_output = axiom_output_create(environment, writer);
 
-    AXIOM_NODE_SERIALIZE(node1, environment , om_output);
+    axiom_node_serialize_sub_tree(node3, environment , om_output);
 
     buffer = (axis2_char_t*)AXIOM_XML_WRITER_GET_XML(writer, environment);
 
@@ -299,7 +302,7 @@
 int
 main(int argc, char *argv[])
 {
-    const char *file_name = "./../../resources/xml/om/test.xml";
+    const char *file_name = "../../resources/xml/om/test.xml";
     if (argc > 1)
         file_name = argv[1];
     allocator = axis2_allocator_init(NULL);

Modified: webservices/axis2/trunk/c/axiom/test/resources/xml/om/test.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/test/resources/xml/om/test.xml?view=diff&rev=523189&r1=523188&r2=523189
==============================================================================
--- webservices/axis2/trunk/c/axiom/test/resources/xml/om/test.xml (original)
+++ webservices/axis2/trunk/c/axiom/test/resources/xml/om/test.xml Tue Mar 27 23:11:25 2007
@@ -1,6 +1,6 @@
 <?xml version="1.0" ?>
 <axiomc:book xmlns:axiomc="http://ws.apache.org/axis2/c/om" xmlns:isbn="urn:ISBN:0-395-74341-6">
-	<axiomc:title>Axis2C OM HOWTO</axiomc:title>
+	<axiomc:title><axiomc:a>Axis2C OM HOWTO</axiomc:a><isbn:number>1748491379</isbn:number></axiomc:title>
 	<isbn:number>1748491379</isbn:number>
 	<author title="Mr" name="Axitoc Oman"/>
     <a>   </a>



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org