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 di...@apache.org on 2008/12/04 04:35:21 UTC

svn commit: r723200 - /webservices/axis2/trunk/c/axiom/src/om/om_node.c

Author: dimuthu
Date: Wed Dec  3 19:35:20 2008
New Revision: 723200

URL: http://svn.apache.org/viewvc?rev=723200&view=rev
Log:
Fixing https://issues.apache.org/jira/browse/AXIS2C-1307, serializing sub tree fails when the namespace is from a parent in special occassions

Modified:
    webservices/axis2/trunk/c/axiom/src/om/om_node.c

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?rev=723200&r1=723199&r2=723200&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/om/om_node.c (original)
+++ webservices/axis2/trunk/c/axiom/src/om/om_node.c Wed Dec  3 19:35:20 2008
@@ -626,6 +626,7 @@
     axiom_node_t *nodes[256];
     int count = 0;
     axutil_hash_t *namespaces = NULL;
+    axutil_hash_t *namespaces_from_parents = NULL;
 
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
 
@@ -635,6 +636,21 @@
     }
 
     namespaces = axutil_hash_make(env);
+    if(!namespaces)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+                "hash for namespaces creation failed");
+        return AXIS2_FAILURE;
+    }
+
+    namespaces_from_parents = axutil_hash_make(env);
+    if(!namespaces_from_parents)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+                "hash for namespaces_from_parents creation failed");
+        return AXIS2_FAILURE;
+    }
+
     nodes[count++] = om_node;
 
     AXIS2_PARAM_CHECK(env->error, om_output, AXIS2_FAILURE);
@@ -682,10 +698,15 @@
                                              AXIS2_HASH_KEY_STRING);
                         if (!ns)
                         {
-                            axiom_namespace_serialize(namespace, env,
-                                                      om_output);
-                            axutil_hash_set(namespaces, prefix,
-                                            AXIS2_HASH_KEY_STRING, namespace);
+                            ns = axutil_hash_get(namespaces_from_parents, prefix,
+                                                    AXIS2_HASH_KEY_STRING);
+                            if (!ns)
+                            {
+                                axiom_namespace_serialize(namespace, env,
+                                                          om_output);
+                                axutil_hash_set(namespaces_from_parents, prefix,
+                                                AXIS2_HASH_KEY_STRING, namespace);
+                            }
                         }
                     }
                 }
@@ -719,12 +740,15 @@
                                                          AXIS2_HASH_KEY_STRING);
                                     if (!ns)
                                     {
-                                        axiom_namespace_serialize(namespace,
-                                                                  env,
-                                                                  om_output);
-                                        axutil_hash_set(namespaces, prefix,
-                                                        AXIS2_HASH_KEY_STRING,
-                                                        namespace);
+                                        ns = axutil_hash_get(namespaces_from_parents, prefix,
+                                                                AXIS2_HASH_KEY_STRING);
+                                        if (!ns)
+                                        {
+                                            axiom_namespace_serialize(namespace, env,
+                                                                      om_output);
+                                            axutil_hash_set(namespaces_from_parents, prefix,
+                                                            AXIS2_HASH_KEY_STRING, namespace);
+                                        }
                                     }
                                 }
                             }
@@ -824,6 +848,74 @@
             {
                 if (om_node->data_element)
                 {
+
+                    axutil_hash_t *temp_attributes = NULL;
+                    axiom_namespace_t *namespace = NULL;
+                    /* at the writing of end part all the namespaces declared
+                       specially to that element should be cancelled */
+
+                    /* first checking the element namespace */
+                    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 = axutil_hash_get(namespaces_from_parents, prefix,
+                                                 AXIS2_HASH_KEY_STRING);
+                            if (ns)
+                            {
+                                axutil_hash_set(namespaces_from_parents, prefix,
+                                                    AXIS2_HASH_KEY_STRING, NULL);
+                            }
+                        }
+                    }
+                    
+                    /* then checking the attribute namespaces */
+
+                    temp_attributes = axiom_element_get_all_attributes((axiom_element_t *) (om_node->data_element), env);
+                    if (temp_attributes)
+                    {
+                        axutil_hash_index_t *hi;
+                        void *val;
+                        for (hi = axutil_hash_first(temp_attributes, env); hi;
+                             hi = axutil_hash_next(env, hi))
+                        {
+                            axutil_hash_this(hi, NULL, NULL, &val);
+
+                            if (val)
+                            {
+                                axiom_namespace_t *ns = NULL;
+                                axis2_char_t *prefix = NULL;
+
+                                namespace =
+                                    axiom_attribute_get_namespace((axiom_attribute_t
+                                                                   *) val, env);
+
+                                if (namespace)
+                                {
+                                    prefix =
+                                        axiom_namespace_get_prefix(namespace, env);
+                                    if (prefix)
+                                    {
+                                        ns = axutil_hash_get(namespaces_from_parents, prefix,
+                                                             AXIS2_HASH_KEY_STRING);
+                                        if (ns)
+                                        {
+                                            axutil_hash_set(namespaces_from_parents, prefix,
+                                                        AXIS2_HASH_KEY_STRING, NULL);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+
                     status =
                         axiom_element_serialize_end_part((axiom_element_t
                                                           *) (om_node->
@@ -855,6 +947,73 @@
                     {
                         if (om_node->data_element)
                         {
+                            axutil_hash_t *temp_attributes = NULL;
+                            axiom_namespace_t *namespace = NULL;
+
+                            /* similar to the earlier time, whenever the ending is happend
+                             * namespaces declared specially to that element should be cancelled */
+                         
+                            /* first checking the element namespace */
+                            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 = axutil_hash_get(namespaces_from_parents, prefix,
+                                                         AXIS2_HASH_KEY_STRING);
+                                    if (ns)
+                                    {
+                                        axutil_hash_set(namespaces_from_parents, prefix,
+                                                            AXIS2_HASH_KEY_STRING, NULL);
+                                    }
+                                }
+                            }
+                            
+                            /* then checking the attribute namespaces */
+                         
+                            temp_attributes = axiom_element_get_all_attributes((axiom_element_t *) (om_node->data_element), env);
+                            if (temp_attributes)
+                            {
+                                axutil_hash_index_t *hi;
+                                void *val;
+                                for (hi = axutil_hash_first(temp_attributes, env); hi;
+                                     hi = axutil_hash_next(env, hi))
+                                {
+                                    axutil_hash_this(hi, NULL, NULL, &val);
+                         
+                                    if (val)
+                                    {
+                                        axiom_namespace_t *ns = NULL;
+                                        axis2_char_t *prefix = NULL;
+                         
+                                        namespace =
+                                            axiom_attribute_get_namespace((axiom_attribute_t
+                                                                           *) val, env);
+                         
+                                        if (namespace)
+                                        {
+                                            prefix =
+                                                axiom_namespace_get_prefix(namespace, env);
+                                            if (prefix)
+                                            {
+                                                ns = axutil_hash_get(namespaces_from_parents, prefix,
+                                                                     AXIS2_HASH_KEY_STRING);
+                                                if (ns)
+                                                {
+                                                    axutil_hash_set(namespaces_from_parents, prefix,
+                                                                AXIS2_HASH_KEY_STRING, NULL);
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
+                            }
                             status =
                                 axiom_element_serialize_end_part((axiom_element_t *) (om_node->data_element), env, om_output);
                         }
@@ -877,11 +1036,12 @@
                     count--;
                 }
             }
-
         }
     }
     while (count > 0);
 
+    axutil_hash_free(namespaces_from_parents, env);
+
     return status;
 }