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 sh...@apache.org on 2009/08/17 11:31:50 UTC

svn commit: r804907 - in /webservices/axis2/trunk/c/axiom: include/axiom_util.h src/util/om_util.c

Author: shankar
Date: Mon Aug 17 09:31:50 2009
New Revision: 804907

URL: http://svn.apache.org/viewvc?rev=804907&view=rev
Log:
utility methods to create node from string, clone

Modified:
    webservices/axis2/trunk/c/axiom/include/axiom_util.h
    webservices/axis2/trunk/c/axiom/src/util/om_util.c

Modified: webservices/axis2/trunk/c/axiom/include/axiom_util.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/include/axiom_util.h?rev=804907&r1=804906&r2=804907&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/include/axiom_util.h (original)
+++ webservices/axis2/trunk/c/axiom/include/axiom_util.h Mon Aug 17 09:31:50 2009
@@ -379,6 +379,28 @@
         axiom_node_t *node,
         axis2_char_t *local_name);
 
+    /**
+     * Creates a clone of given node
+     * @param env environment, MUST not be NULL
+     * @param node node to be cloned
+     * @return cloned node
+     */
+    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
+    axiom_util_clone_node(
+        const axutil_env_t *env,
+        axiom_node_t *node);
+
+    /**
+     * Creates a node from given string
+     * @param env environment, MUST not be NULL
+     * @param buffer
+     * @return node created from string
+     */
+    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
+    axiom_util_string_to_node(
+        const axutil_env_t *env,
+        axis2_char_t* buffer);
+
 
 #ifdef __cplusplus
  }

Modified: webservices/axis2/trunk/c/axiom/src/util/om_util.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/axiom/src/util/om_util.c?rev=804907&r1=804906&r2=804907&view=diff
==============================================================================
--- webservices/axis2/trunk/c/axiom/src/util/om_util.c (original)
+++ webservices/axis2/trunk/c/axiom/src/util/om_util.c Mon Aug 17 09:31:50 2009
@@ -1201,3 +1201,91 @@
     }
     return NULL;
 }
+
+AXIS2_EXTERN axiom_node_t *AXIS2_CALL
+axiom_util_string_to_node(
+    const axutil_env_t *env,
+    axis2_char_t* buffer)
+{
+    axiom_document_t *doc = NULL;
+    axiom_stax_builder_t *builder = NULL;
+    axiom_xml_reader_t *reader = NULL;
+    axiom_node_t *node = NULL;
+
+    if(!buffer)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Deserialize method called with invalid buffer.");
+        return NULL;
+    }
+    reader = axiom_xml_reader_create_for_memory(
+        env, (void*)buffer, axutil_strlen(buffer), NULL, AXIS2_XML_PARSER_TYPE_BUFFER);
+
+    if(!reader)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Could not be able to create axiom_xml_reader.");
+        return NULL;
+    }
+
+    builder = axiom_stax_builder_create(env, reader);
+    if(!builder)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Could not be able to create axiom_stax_builder.");
+        return NULL;
+    }
+
+    doc = axiom_document_create(env, NULL, builder);
+    if(!doc)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Could not be able to create axiom_document.");
+        return NULL;
+    }
+
+    node = axiom_document_build_all(doc, env);
+    if(!node)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Could not be able to deserialize the node.");
+        axiom_document_free(doc, env);
+        return NULL;
+    }
+
+    /* Free stax builder. The stax builder will free the reader. */
+    axiom_stax_builder_free_self(builder, env);
+    builder = NULL;
+
+    axiom_document_free_self(doc, env);
+    doc = NULL;
+
+    return node;
+}
+
+/**
+ * Creates a clone of given node
+ * @param env environment, MUST not be NULL
+ * @param node node to be cloned
+ * @return cloned node
+ */
+AXIS2_EXTERN axiom_node_t *AXIS2_CALL
+axiom_util_clone_node(
+    const axutil_env_t *env,
+    axiom_node_t *node)
+{
+    axis2_char_t* node_string = NULL;
+    axiom_node_t *clone = NULL;
+
+    if(!node)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+            "Could not be able to clone the node. Given node is not valid.");
+        return NULL;
+    }
+
+    node_string = axiom_node_sub_tree_to_string(node, env);
+    clone = oxs_axiom_deserialize_node(env, node_string);
+
+    if(node_string)
+    {
+        AXIS2_FREE(env->allocator, node_string);
+    }
+
+    return clone;
+}