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 da...@apache.org on 2006/05/17 06:13:59 UTC

svn commit: r407146 - in /webservices/axis2/trunk/c: include/axis2_generic_obj.h include/axis2_om_attribute.h modules/core/deployment/desc_builder.c modules/util/Makefile.am modules/util/generic_obj.c modules/util/param.c modules/xml/om/om_attribute.c

Author: damitha
Date: Tue May 16 21:13:58 2006
New Revision: 407146

URL: http://svn.apache.org/viewcvs?rev=407146&view=rev
Log:
Added new class called axis2_generic_obj. This is intended to be used
in places where we have to set a void pointer but the receiving end
don't know how to free this. So instead of setting a void pointer directly
it is set as the value of generic_obj. The free function of this value is
also set. So when the generic object is freed from the receiving end,
its value is also freed using the set free function.

Added:
    webservices/axis2/trunk/c/include/axis2_generic_obj.h
    webservices/axis2/trunk/c/modules/util/generic_obj.c
Modified:
    webservices/axis2/trunk/c/include/axis2_om_attribute.h
    webservices/axis2/trunk/c/modules/core/deployment/desc_builder.c
    webservices/axis2/trunk/c/modules/util/Makefile.am
    webservices/axis2/trunk/c/modules/util/param.c
    webservices/axis2/trunk/c/modules/xml/om/om_attribute.c

Added: webservices/axis2/trunk/c/include/axis2_generic_obj.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_generic_obj.h?rev=407146&view=auto
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_generic_obj.h (added)
+++ webservices/axis2/trunk/c/include/axis2_generic_obj.h Tue May 16 21:13:58 2006
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AXIS2_GENERIC_OBJ_H
+#define AXIS2_GENERIC_OBJ_H
+
+#include <axis2_defines.h>
+#include <axis2_error.h>
+#include <axis2_env.h>
+#include <axis2_const.h>
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+    
+typedef struct axis2_generic_obj axis2_generic_obj_t;
+typedef struct axis2_generic_obj_ops axis2_generic_obj_ops_t;
+    
+/**
+ * @defgroup axis2_generic_obj Generic Object
+ * @ingroup axis2_util 
+ * @{
+ */
+
+/** 
+ * @brief Description Builder ops struct
+ * Encapsulator struct for ops of axis2_desc_builder
+ */
+AXIS2_DECLARE_DATA struct axis2_generic_obj_ops
+{
+
+    axis2_status_t (AXIS2_CALL *
+    free) (axis2_generic_obj_t *generic_obj, 
+            axis2_env_t **env);
+
+    axis2_status_t (AXIS2_CALL *
+    set_free_func) (axis2_generic_obj_t *generic_obj,
+                    axis2_env_t **env,
+                    AXIS2_FREE_VOID_ARG free_func);
+
+    axis2_status_t (AXIS2_CALL *
+    set_value) (axis2_generic_obj_t *generic_obj,
+                axis2_env_t **env,
+                void *value);
+    void *(AXIS2_CALL *
+    get_value) (axis2_generic_obj_t *generic_obj,
+                            axis2_env_t **env);
+
+};
+    
+     
+/** 
+     * @brief
+     */ 
+AXIS2_DECLARE_DATA struct axis2_generic_obj
+{
+	axis2_generic_obj_ops_t *ops;
+};
+
+/**
+ * create new generic_obj
+ * @return generic_obj newly created generic_obj
+ */
+AXIS2_DECLARE(axis2_generic_obj_t *)
+axis2_generic_obj_create(axis2_env_t **env);
+
+/*************************** Function macros **********************************/
+
+#define AXIS2_GENERIC_OBJ_FREE(generic_obj, env) \
+		(((axis2_generic_obj_t *) generic_obj)->ops->free (generic_obj, env))
+
+#define AXIS2_GENERIC_OBJ_SET_FREE_FUNC(generic_obj, env, free_func) \
+		((generic_obj)->ops->set_free_func (generic_obj, env, free_func))  
+
+#define AXIS2_GENERIC_OBJ_SET_VALUE(generic_obj, env, value) \
+		((generic_obj)->ops->set_value (generic_obj, env, value))
+
+#define AXIS2_GENERIC_OBJ_GET_VALUE(generic_obj, env) \
+        ((generic_obj)->ops->get_value(generic_obj, env))
+                                        
+/*************************** End of function macros ***************************/
+
+
+
+/** @} */
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* AXIS2_GENERIC_OBJ_H */

Modified: webservices/axis2/trunk/c/include/axis2_om_attribute.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_om_attribute.h?rev=407146&r1=407145&r2=407146&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_om_attribute.h (original)
+++ webservices/axis2/trunk/c/include/axis2_om_attribute.h Tue May 16 21:13:58 2006
@@ -184,7 +184,16 @@
                                const axis2_char_t *localname,
                                const axis2_char_t *value,
                                axis2_om_namespace_t *ns);
-
+    /**
+     * Free om attribute passed as void pointer. This will be
+     * cast into appropriate type and then pass the cast object
+     * into the om_attribute structure's free method
+     */
+    AXIS2_DECLARE(axis2_status_t) 
+    axis2_om_attribute_free_void_arg (
+            void *om_attribute,
+            axis2_env_t **env);
+     
 /******************** Macros **************************************************/
     
     

Modified: webservices/axis2/trunk/c/modules/core/deployment/desc_builder.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/core/deployment/desc_builder.c?rev=407146&r1=407145&r2=407146&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/core/deployment/desc_builder.c (original)
+++ webservices/axis2/trunk/c/modules/core/deployment/desc_builder.c Tue May 16 21:13:58 2006
@@ -18,6 +18,7 @@
 #include <axis2_string.h>
 #include <axis2_class_loader.h>
 #include <axis2_utils.h>
+#include <axis2_generic_obj.h>
 #include <axis2_raw_xml_in_out_msg_recv.h>
 
 /** 
@@ -636,7 +637,43 @@
         
         /* Setting attributes */
         attrs = AXIS2_OM_ELEMENT_EXTRACT_ATTRIBUTES(param_element, env, param_node);
-        AXIS2_PARAM_SET_ATTRIBUTES(param, env, attrs);
+        if(attrs)
+        {
+            axis2_hash_index_t *i = NULL;
+
+            for (i = axis2_hash_first (attrs, env); i; i = 
+                    axis2_hash_next (env, i))
+            {
+                void *v = NULL;
+                axis2_om_attribute_t *value = NULL;
+                axis2_generic_obj_t *obj = NULL;
+                axis2_qname_t *attr_qname = NULL;
+                axis2_char_t *attr_name = NULL;
+
+                axis2_hash_this (i, NULL, NULL, &v);
+                if(!v) 
+                {
+                    AXIS2_PARAM_FREE(param, env);
+                    return AXIS2_FAILURE;
+                }
+                obj = axis2_generic_obj_create(env);
+                if(!obj)
+                {
+                    AXIS2_PARAM_FREE(param, env);
+                    AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, 
+                            AXIS2_FAILURE);
+                    return AXIS2_FAILURE;
+                }
+                value = (axis2_om_attribute_t *) v;
+                AXIS2_GENERIC_OBJ_SET_VALUE(obj, env, value);
+                AXIS2_GENERIC_OBJ_SET_FREE_FUNC(obj, env, 
+                        axis2_om_attribute_free_void_arg);
+                attr_qname = AXIS2_OM_ATTRIBUTE_GET_QNAME(value, env);
+                attr_name = AXIS2_QNAME_TO_STRING(attr_qname, env);
+                axis2_hash_set(attrs, attr_name, AXIS2_HASH_KEY_STRING, obj); 
+            }
+            AXIS2_PARAM_SET_ATTRIBUTES(param, env, attrs);
+        }
 
         /* Setting paramter name */
         att_qname = axis2_qname_create(env, AXIS2_ATTNAME, NULL, NULL);

Modified: webservices/axis2/trunk/c/modules/util/Makefile.am
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/Makefile.am?rev=407146&r1=407145&r2=407146&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/util/Makefile.am (original)
+++ webservices/axis2/trunk/c/modules/util/Makefile.am Tue May 16 21:13:58 2006
@@ -29,7 +29,8 @@
 						param_container.c \
 						dll_desc.c\
 						url.c\
-                        stack.c 
+                        stack.c \
+						generic_obj.c
 
 
 INCLUDES = -I$(top_builddir)/include \

Added: webservices/axis2/trunk/c/modules/util/generic_obj.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/generic_obj.c?rev=407146&view=auto
==============================================================================
--- webservices/axis2/trunk/c/modules/util/generic_obj.c (added)
+++ webservices/axis2/trunk/c/modules/util/generic_obj.c Tue May 16 21:13:58 2006
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+#include <axis2_generic_obj.h>
+
+typedef struct axis2_generic_obj_impl
+{
+    axis2_generic_obj_t generic_obj;
+    AXIS2_FREE_VOID_ARG free_func;
+    void *value;
+    
+}axis2_generic_obj_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(generic_obj) \
+    ((axis2_generic_obj_impl_t *) generic_obj)
+
+axis2_status_t AXIS2_CALL
+axis2_generic_obj_free (axis2_generic_obj_t *generic_obj, 
+                    axis2_env_t **env); 
+
+axis2_status_t AXIS2_CALL
+axis2_generic_obj_set_free_func(axis2_generic_obj_t *generic_obj,
+                            axis2_env_t **env,
+                            AXIS2_FREE_VOID_ARG free_func);
+
+axis2_status_t AXIS2_CALL
+axis2_generic_obj_set_value(axis2_generic_obj_t *generic_obj,
+                            axis2_env_t **env,
+                            void *value);
+
+void *AXIS2_CALL
+axis2_generic_obj_get_value(axis2_generic_obj_t *generic_obj,
+                            axis2_env_t **env);
+
+/************************** End of function prototypes ************************/
+
+axis2_generic_obj_t *AXIS2_CALL 
+axis2_generic_obj_create(axis2_env_t **env)
+{
+    axis2_generic_obj_impl_t *generic_obj_impl = NULL;
+    
+	AXIS2_ENV_CHECK(env, NULL);
+	
+	generic_obj_impl = (axis2_generic_obj_impl_t *) AXIS2_MALLOC((*env)->allocator, 
+        sizeof(axis2_generic_obj_impl_t));
+	
+	if(NULL == generic_obj_impl)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); 
+        return NULL;
+    }
+    generic_obj_impl->value= NULL;
+    generic_obj_impl->free_func = 0;
+    
+    generic_obj_impl->generic_obj.ops = 
+		AXIS2_MALLOC ((*env)->allocator, sizeof(axis2_generic_obj_ops_t));
+	if(NULL == generic_obj_impl->generic_obj.ops)
+    {
+        axis2_generic_obj_free(&(generic_obj_impl->generic_obj), env);
+		AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    
+    generic_obj_impl->generic_obj.ops->free =  axis2_generic_obj_free;
+    generic_obj_impl->generic_obj.ops->set_free_func = axis2_generic_obj_set_free_func;
+    generic_obj_impl->generic_obj.ops->set_value = axis2_generic_obj_set_value;
+	generic_obj_impl->generic_obj.ops->get_value = axis2_generic_obj_get_value;
+	return &(generic_obj_impl->generic_obj);
+}
+
+/***************************Function implementation****************************/
+
+axis2_status_t AXIS2_CALL 
+axis2_generic_obj_free (axis2_generic_obj_t *generic_obj, 
+                    axis2_env_t **env)
+{
+    axis2_generic_obj_impl_t *generic_obj_impl = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    generic_obj_impl = AXIS2_INTF_TO_IMPL(generic_obj);
+    
+    if(generic_obj_impl->value)
+    {
+        if(generic_obj_impl->free_func)
+        {
+            generic_obj_impl->free_func(generic_obj_impl->value, env);
+        }
+        else
+        {
+            AXIS2_FREE((*env)->allocator, generic_obj_impl->value);
+        }
+        generic_obj_impl->value = NULL;
+    }
+    
+    if(generic_obj_impl->generic_obj.ops)
+    {
+        AXIS2_FREE((*env)->allocator, generic_obj_impl->generic_obj.ops);
+        generic_obj_impl->generic_obj.ops = NULL;
+    }
+    
+    if(generic_obj_impl)
+    {
+        AXIS2_FREE((*env)->allocator, generic_obj_impl);
+        generic_obj_impl = NULL;
+    }
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_generic_obj_set_free_func(axis2_generic_obj_t *generic_obj,
+                            axis2_env_t **env,
+                            AXIS2_FREE_VOID_ARG free_func)
+{
+    axis2_generic_obj_impl_t *generic_obj_impl = NULL;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    generic_obj_impl = AXIS2_INTF_TO_IMPL(generic_obj);
+   
+    generic_obj_impl->free_func = free_func;
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_generic_obj_set_value(axis2_generic_obj_t *generic_obj,
+                            axis2_env_t **env,
+                            void *value)
+{
+    axis2_generic_obj_impl_t *generic_obj_impl = NULL;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    generic_obj_impl = AXIS2_INTF_TO_IMPL(generic_obj);
+   
+    generic_obj_impl->value = value;
+    return AXIS2_SUCCESS;
+}
+
+void *AXIS2_CALL
+axis2_generic_obj_get_value(axis2_generic_obj_t *generic_obj,
+                            axis2_env_t **env)
+{
+    axis2_generic_obj_impl_t *generic_obj_impl = NULL;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    generic_obj_impl = AXIS2_INTF_TO_IMPL(generic_obj);
+
+    return generic_obj_impl->value;
+}

Modified: webservices/axis2/trunk/c/modules/util/param.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/param.c?rev=407146&r1=407145&r2=407146&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/util/param.c (original)
+++ webservices/axis2/trunk/c/modules/util/param.c Tue May 16 21:13:58 2006
@@ -294,11 +294,11 @@
                 i = axis2_hash_next (env, i))
         {
             axis2_hash_this (i, NULL, NULL, &v);
-            AXIS2_OM_ATTRIBUTE_FREE(v, env);
+            AXIS2_GENERIC_OBJ_FREE(v, env);
         }
         axis2_hash_free(param_impl->attrs, env);
     }
-    
+   
     param_impl->attrs = attrs;
     return AXIS2_SUCCESS;
 
@@ -349,7 +349,7 @@
                 i = axis2_hash_next (env, i))
         {
             axis2_hash_this (i, NULL, NULL, &v);
-            AXIS2_OM_ATTRIBUTE_FREE(v, env);
+            AXIS2_GENERIC_OBJ_FREE(v, env);
         }
         axis2_hash_free(param_impl->attrs, env);
     }

Modified: webservices/axis2/trunk/c/modules/xml/om/om_attribute.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/om/om_attribute.c?rev=407146&r1=407145&r2=407146&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/om/om_attribute.c (original)
+++ webservices/axis2/trunk/c/modules/xml/om/om_attribute.c Tue May 16 21:13:58 2006
@@ -191,6 +191,19 @@
     return AXIS2_SUCCESS;
 }
 
+axis2_status_t AXIS2_CALL
+axis2_om_attribute_free_void_arg (
+        void *om_attribute,
+        axis2_env_t **env)
+{
+    axis2_om_attribute_t *om_attribute_l = NULL;
+    
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    om_attribute_l = (axis2_om_attribute_t *) om_attribute;
+    return axis2_om_attribute_free(om_attribute_l, env);
+}
+
+
 axis2_qname_t * AXIS2_CALL 
 axis2_om_attribute_get_qname (axis2_om_attribute_t *om_attribute,
                                    axis2_env_t **env)