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 08:46:35 UTC
svn commit: r321037 - in /webservices/axis2/trunk/c:
include/axis2_om_attribute.h include/axis2_qname.h
modules/xml/om/src/axis2_om_attribute.c modules/xml/om/src/axis2_qname.c
Author: samisa
Date: Thu Oct 13 23:46:11 2005
New Revision: 321037
URL: http://svn.apache.org/viewcvs?rev=321037&view=rev
Log:
axis2_qname and axis2_om_attribute changed
patch applied
Modified:
webservices/axis2/trunk/c/include/axis2_om_attribute.h
webservices/axis2/trunk/c/include/axis2_qname.h
webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_attribute.c
webservices/axis2/trunk/c/modules/xml/om/src/axis2_qname.c
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=321037&r1=321036&r2=321037&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_om_attribute.h (original)
+++ webservices/axis2/trunk/c/include/axis2_om_attribute.h Thu Oct 13 23:46:11 2005
@@ -1,70 +1,97 @@
/*
- * 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.
- */
+* 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_OM_ATTRIBUTE_H
#define AXIS2_OM_ATTRIBUTE_H
/**
- * @file axis2_om_attribute.h
- * @brief om attribute strcut represents an xml attribute
- */
+* @file axis2_om_attribute.h
+* @brief om attribute struct represents an xml attribute
+*/
#include <axis2_qname.h>
-#include <axis2_om_node.h>
#include <axis2_om_namespace.h>
#include <axis2_om_output.h>
-/**
- * localname
- * value
- * namespace
+
+
+struct axis2_om_attribute;
+struct axis2_om_attribute_ops;
+
+/** \struct axis2_om_attribute
+ * \brief OM attribute operations struct
+ *
+ * Encapsulator struct for axis2_om_attribute_t
*/
+typedef struct axis2_om_attribute_ops
+{
+ /**
+ * Free an axis2_om_attribute struct
+ * @return Status code
+ */
+
+ int (*axis2_om_attribute_ops_free)(axis2_environment_t *environment,struct axis2_om_attribute *om_attribute);
+
+ /**
+ * Creates and returns a qname struct for this attribute
+ * @param om_attribute
+ * @return returns null on error
+ */
+
+ axis2_qname_t *(*axis2_om_attribute_ops_get_qname)(axis2_environment_t *environment,struct axis2_om_attribute *om_attribute);
+
+ /**
+ * Serialize operation
+ * @param om_output OM output handler to be used in serializing
+ * @return Status code
+ */
-typedef struct axis2_om_attribute_t{
- char *localname;
- char *value;
- axis2_om_namespace_t *ns;
-}axis2_om_attribute_t;
+ int (*axis2_om_attribute_ops_serialize)(axis2_environment_t *environment,struct axis2_om_attribute *om_attribute,axis2_om_output_t *om_output);
-/**
- * creates an om_attribute structure
- * @param localname
- * @param value
- * @param axis2_om_namespace namespace
- * @return The attribute struct just created
- */
+}axis2_om_attribute_ops_t;
-axis2_om_attribute_t *axis2_om_attribute_create(const char *localname,const char *value, axis2_om_namespace_t *ns);
-/**
- * creates and returns a unique qname struct for this attribute
- * @param attribute pointer to an attribute struct
- * @return axis2_qname_t struct
- */
-axis2_qname_t *axis2_om_attribute_get_qname(axis2_om_attribute_t *attribute);
+typedef struct axis2_om_attribute_t{
+ /** operations of attributes */
+ axis2_om_attribute_ops_t *ops;
+
+ /** localname of this attribute */
+ axis2_char_t *localname;
+ /** value of this attribute */
+ axis2_char_t *value;
+ /** attribute namespace */
+ axis2_om_namespace_t *ns;
+}axis2_om_attribute_t;
/**
- * free a om attribute struct
- * @param attr pointer to the struct to be freed
- * @return
+ * creates an om_attribute structure
+ * @environment axis2_environment
+ * @param localname The local part of the attribute name
+ * @param value normalized attribute value
+ * @param ns The namespace name, if any, of the attribute
+ * @return The a pointer to newly created attribute struct
*/
-void axis2_om_attribute_free(axis2_om_attribute_t *attr);
+axis2_om_attribute_t *axis2_om_attribute_create(axis2_environment_t *environment ,const axis2_char_t *localname,const axis2_char_t *value, axis2_om_namespace_t *ns);
+
+/* macros */
+#define axis2_om_attribute_free(environment,om_attribute) ((om_attribute)->ops->axis2_om_attribute_ops_free(environment,om_attribute))
+#define axis2_om_attribute_get_qname(environment,om_attribute) ((om_attribute)->ops->axis2_om_attribute_ops_get_qname(environment,om_attribute))
+#define axis2_om_attribute_serialize(environment,om_attribute,om_ouput) ((om_attribute)->ops->axis2_om_attribute_ops_serialize(environment,om_attribute,om_output))
-int axis2_om_attribute_serialize(axis2_om_attribute_t *attribute, axis2_om_output_t* om_output);
#endif /* AXIS2_OM_ATTRIBUTE_H */
Modified: webservices/axis2/trunk/c/include/axis2_qname.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_qname.h?rev=321037&r1=321036&r2=321037&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_qname.h (original)
+++ webservices/axis2/trunk/c/include/axis2_qname.h Thu Oct 13 23:46:11 2005
@@ -17,39 +17,71 @@
#ifndef AXIS2_QNAME_H
#define AXIS2_QNAME_H
-
/**
* @file axis2_qname.h
* @brief represents a qualified name
*/
-#include <axis2.h>
+#include <axis2_defines.h>
+#include <axis2_environment.h>
+
-static const char XML_NAMESPACE_URI[] ="http://www.w3c.org/XML/1998/namespace";
+const axis2_char_t XML_NAMESPACE_URI[] ="http://www.w3c.org/XML/1998/namespace";
-typedef struct axis2_qname_t{
- char *localpart;
- char *ns_uri;
- char *prefix;
-
+struct axis2_qname;
+struct axis2_qname_ops;
+
+typedef struct axis2_qname_ops
+{
+ /**
+ * Free a qname struct
+ * @return Status code
+ */
+ axis2_status_t (*axis2_qname_ops_free)(axis2_environment_t *environment,struct axis2_qname *qname);
+
+ /**
+ * Compare two qnames
+ * prefix is ignored when comparing
+ * If ns_uri and localpart of qname1 and qname2 is equal returns true
+ * @return true if qname1 equals qname2, false otherwise
+ */
+
+ axis2_bool_t (*axis2_qname_ops_equals)(axis2_environment_t *environment,struct axis2_qname *qname1,struct axis2_qname *qname2);
+
+}axis2_qname_ops_t;
+
+typedef struct axis2_qname
+{
+ /** operations related to qname */
+ axis2_qname_ops_t *ops;
+
+ /** localpart of qname is mandatory */
+
+ axis2_char_t *localpart;
+
+ /** namespace uri is optional */
+ axis2_char_t *namespace_uri;
+
+ /** prefix mandatory */
+ axis2_char_t *prefix;
+
}axis2_qname_t;
/**
* creates a qname struct
- *
+ * returns a pointer to a qname struct
+ * @localpart mandatory
+ * @prefix mandatory
+ * @ns_uri optional
+ * The prefix. Must not be null. Use "" (empty string) to indicate that no namespace URI is present or the namespace URI is not relevant
+ * if null is passed for prefix and uri , "'(empty string ) will be assinged to those fields
+ * @return a pointer to newly created qname struct
*/
-axis2_qname_t *axis2_qname_create(const char *localname,const char *ns_uri,const char *prefix);
-/**
- * Free a qname struct
- */
+axis2_qname_t *axis2_qname_create(axis2_environment_t *environment ,const axis2_char_t *localpart,const axis2_char_t *namespace_uri, const axis2_char_t *prefix);
-void axis2_qname_free(axis2_qname_t *qn);
-/**
- * compare tow qname structs and returns true (1) if equals and false (0) otherwise
- *
- */
-int axis2_qname_equals(axis2_qname_t *qn1,axis2_qname_t *qn2);
+#define axis2_qname_free(environment,qname) ((qname)->ops->axis2_qname_ops_free(environment,qname))
+#define axis2_qname_equals(environment,qname1,qname2) ((qname1)->ops->axis2_qname_ops_equals(environment,qname1,qname2))
#endif // AXIS2_QNAME_H
Modified: webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_attribute.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_attribute.c?rev=321037&r1=321036&r2=321037&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_attribute.c (original)
+++ webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_attribute.c Thu Oct 13 23:46:11 2005
@@ -19,66 +19,109 @@
#include <axis2_defines.h>
-axis2_om_attribute_t *axis2_om_attribute_create(const char *localname,
- const char *value,axis2_om_namespace_t *ns)
+
+axis2_status_t axis2_om_attribute_impl_free(axis2_environment_t *environment,axis2_om_attribute_t * attr);
+
+axis2_qname_t *axis2_om_attribute_impl_get_qname(axis2_environment_t *environment,axis2_om_attribute_t * attr);
+
+axis2_status_t axis2_om_attribute_impl_serialize(axis2_environment_t *environment,axis2_om_attribute_t *attribute, axis2_om_output_t* om_output);
+
+
+axis2_om_attribute_t *axis2_om_attribute_create(axis2_environment_t *environment,const axis2_char_t *localname,
+ const axis2_char_t *value,axis2_om_namespace_t *ns)
{
- axis2_om_attribute_t *attr = (axis2_om_attribute_t *) malloc(
- sizeof(axis2_om_attribute_t));
+ axis2_om_attribute_t *attr = NULL;
+ if(!localname)
+ { /** localname is mandatory */
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
+ return NULL;
+ }
+
+ attr = (axis2_om_attribute_t *)axis2_malloc(environment->allocator,sizeof(axis2_om_attribute_t));
if (!attr)
{
+ environment->error->errorno = AXIS2_ERROR_NO_MEMORY;
return NULL;
}
-
- attr->localname = strdup(localname);
- attr->value = strdup(value);
+ /** initialize fields */
+ attr->localname = axis2_strdup(environment->string,localname);
+ if(!(attr->localname))
+ {
+ axis2_free(environment->allocator,attr);
+ environment->error->errorno = AXIS2_ERROR_NO_MEMORY;
+ return NULL;
+ }
+ attr->value = axis2_strdup(environment->string,value);
+ if(!(attr->value))
+ {
+ axis2_free(environment->allocator,attr);
+ axis2_free(environment->allocator,attr);
+ environment->error->errorno = AXIS2_ERROR_NO_MEMORY;
+ return NULL;
+ }
attr->ns = ns;
+
+ /** operations */
+
+ attr->ops = axis2_malloc(environment->allocator,sizeof(axis2_om_attribute_ops_t));
+ if(!(attr->ops))
+ {
+ environment->error->errorno = AXIS2_ERROR_NO_MEMORY;
+ axis2_free(environment->allocator,attr->localname);
+ axis2_free(environment->allocator,attr->value);
+ axis2_free(environment->allocator,attr);
+ return NULL;
+ }
+ attr->ops->axis2_om_attribute_ops_free = axis2_om_attribute_impl_free;
+ attr->ops->axis2_om_attribute_ops_get_qname = axis2_om_attribute_impl_get_qname;
+ attr->ops->axis2_om_attribute_ops_serialize = axis2_om_attribute_impl_serialize;
return attr;
}
-void axis2_om_attribute_free(axis2_om_attribute_t * attr)
+axis2_status_t axis2_om_attribute_impl_free(axis2_environment_t *environment,axis2_om_attribute_t * attr)
{
if (attr)
{
- if(attr->localname)
+ if(attr->localname)
{
- free(attr->localname);
+ axis2_free(environment->allocator,attr->localname);
}
if(attr->value)
{
- free(attr->value);
- }
- if(attr->ns)
- {
- axis2_om_namespace_free(attr->ns);
+ free(environment->allocator,attr->value);
}
- free(attr);
+ axis2_free(environment->allocator,attr);
+ return AXIS2_SUCCESS;
}
-
+ AXIS2_FAILURE;
}
-axis2_qname_t *axis2_om_attribute_get_qname(axis2_om_attribute_t * attr)
+axis2_qname_t *axis2_om_attribute_impl_get_qname(axis2_environment_t *environment,axis2_om_attribute_t *attr)
{
axis2_qname_t *qname = NULL;
if (!attr)
{
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
return NULL;
}
- if (attr->ns)
- {
- qname = axis2_qname_create(attr->localname, attr->ns->uri,attr->ns->prefix);
- }
- else
- {
- qname = axis2_qname_create(attr->localname, NULL, NULL);
- }
- return qname;
+ if (attr->ns)
+ qname = axis2_qname_create(environment,attr->localname,attr->ns->uri,attr->ns->prefix);
+ else
+ qname = axis2_qname_create(environment,attr->localname,NULL,NULL);
+
+ return qname;
}
-int axis2_om_attribute_serialize(axis2_om_attribute_t *attribute, axis2_om_output_t* om_output)
+axis2_status_t axis2_om_attribute_impl_serialize(axis2_environment_t *environment,axis2_om_attribute_t *attribute, axis2_om_output_t* om_output)
{
int status = AXIS2_TRUE;
- /* TODO : handle null pointer errors*/
+ if(!attribute || !om_output)
+ {
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
+ return AXIS2_FAILURE;
+ }
+
if (attribute->ns && attribute->ns->uri && attribute->ns->prefix)
status = axis2_om_output_write (om_output, AXIS2_OM_ATTRIBUTE, 4,
attribute->localname, attribute->value, attribute->ns->uri,
Modified: webservices/axis2/trunk/c/modules/xml/om/src/axis2_qname.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/om/src/axis2_qname.c?rev=321037&r1=321036&r2=321037&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/om/src/axis2_qname.c (original)
+++ webservices/axis2/trunk/c/modules/xml/om/src/axis2_qname.c Thu Oct 13 23:46:11 2005
@@ -15,82 +15,158 @@
*/
#include <axis2_qname.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <axis2_errno.h>
+#include <axis2_environment.h>
-axis2_qname_t *axis2_qname_create(const char *localname,
- const char *ns_uri, const char *prefix)
+axis2_status_t axis2_qname_impl_free(axis2_environment_t *environment,axis2_qname_t *qname);
+axis2_bool_t axis2_qname_impl_equals(axis2_environment_t *environment,axis2_qname_t *qn1,axis2_qname_t *qn2);
+axis2_qname_t *axis2_qname_create(axis2_environment_t *environment,const axis2_char_t *localpart,
+ const axis2_char_t *namespace_uri, const axis2_char_t *prefix);
+
+
+axis2_status_t axis2_qname_impl_free(axis2_environment_t *environment,axis2_qname_t *qname)
{
- axis2_qname_t *qn = (axis2_qname_t *) malloc(sizeof(axis2_qname_t));
- if (!qn)
- {
- fprintf(stderr," %d Error ",AXIS2_ERROR_OM_MEMORY_ALLOCATION);
- return NULL;
+ if (!qname)
+ {
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
+ return AXIS2_FAILURE;
}
- if(localname)
+ if(qname->localpart)
{
- qn->localpart = strdup(localname);
+ axis2_free(environment->allocator,qname->localpart);
}
- if(ns_uri)
+ if(qname->namespace_uri)
{
- qn->ns_uri = strdup(ns_uri);
+ axis2_free(environment->allocator,qname->namespace_uri);
}
- if(prefix)
+ if(qname->prefix)
{
- qn->prefix = strdup(prefix);
+ axis2_free(environment->allocator,qname->prefix);
}
- return qn;
-}
-
-void axis2_free_qname(axis2_qname_t * qn)
-{
- if (qn)
+ if(qname->ops)
{
- if(qn->localpart)
- {
- free(qn->localpart);
- }
- if(qn->ns_uri)
- {
- free(qn->ns_uri);
- }
- if(qn->prefix)
- {
- free(qn->prefix);
- }
- free(qn);
+ axis2_free(environment->allocator,qname->ops);
}
+ axis2_free(environment->allocator,qname);
+ return AXIS2_SUCCESS;
+
}
-int axis2_qname_equals(axis2_qname_t *qn1,axis2_qname_t *qn2)
+axis2_bool_t axis2_qname_impl_equals(axis2_environment_t *environment,axis2_qname_t *qn1,axis2_qname_t *qn2)
{
+
int uris_differ = 0;
int localparts_differ = 0;
-
- if(!qn1 && !qn2)
+
+ if(!qn1 || !qn2)
+ {
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
+ return AXIS2_FALSE;
+ }
+
+ if(qn1 && qn2)
{
if( qn1 == qn2)
{
- return TRUE;
+ return AXIS2_TRUE;
}
}
if(qn1->localpart && qn2->localpart)
{
- localparts_differ = strcmp(qn1->localpart , qn2->localpart);
+ localparts_differ = axis2_strcmp(environment->string ,qn1->localpart , qn2->localpart);
}
else
{
- localparts_differ = (!(qn1->localpart) || !(qn2->localpart));
+ localparts_differ = ((qn1->localpart) || (qn2->localpart));
}
- if( qn1->ns_uri && qn2->ns_uri )
+ if( qn1->namespace_uri && qn2->namespace_uri )
{
- uris_differ = strcmp( qn1->ns_uri , qn2->ns_uri );
+ uris_differ = axis2_strcmp(environment->string, qn1->namespace_uri , qn2->namespace_uri );
}
else
{
- uris_differ = (!(qn1->ns_uri) || !(qn2->ns_uri));
+ uris_differ = ((qn1->namespace_uri) || (qn2->namespace_uri));
}
- return (!uris_differ && !localparts_differ);
+ return (!uris_differ && !localparts_differ) ? AXIS2_TRUE : AXIS2_FALSE ;
+
+}
+
+
+axis2_qname_t *axis2_qname_create(axis2_environment_t *environment,const axis2_char_t *localpart,
+ const axis2_char_t *namespace_uri, const axis2_char_t *prefix)
+{
+
+ axis2_qname_t *qn=NULL;
+ /* localpart or prefix can't be null */
+ if(!localpart)
+ {
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
+ return NULL;
+ }
+
+ qn = (axis2_qname_t *)axis2_malloc(environment->allocator,sizeof(axis2_qname_t));
+ if (!qn)
+ {
+ environment->error->errorno = AXIS2_ERROR_INVALID_NULL_PARAMETER;
+ return NULL;
+ }
+ /* set properties */
+
+ qn->localpart = axis2_strdup(environment->string,localpart);
+ if(!(qn->localpart))
+ {
+ axis2_free(environment->allocator,qn);
+ environment->error->errorno = AXIS2_ERROR_NO_MEMORY;
+ return NULL;
+ }
+
+ if(!prefix)
+ {
+ qn->prefix = axis2_strdup(environment->string,"");
+ }
+ else
+ {
+ qn->prefix = axis2_strdup(environment->string,prefix);
+ }
+ if(!(qn->prefix))
+ {
+ axis2_free(environment->allocator,qn->localpart);
+ axis2_free(environment->allocator,qn);
+ environment->error->errorno = AXIS2_ERROR_NO_MEMORY;
+ return NULL;
+ }
+ if(!namespace_uri)
+ {
+ qn->namespace_uri = axis2_strdup(environment->string,"");
+ }
+ else
+ {
+ qn->namespace_uri = axis2_strdup(environment->string,namespace_uri);
+ }
+ if(!(qn->namespace_uri))
+ {
+ axis2_free(environment->allocator,qn->localpart);
+ axis2_free(environment->allocator,qn->prefix);
+ axis2_free(environment->allocator,qn);
+ environment->error->errorno = AXIS2_ERROR_NO_MEMORY;
+ return NULL;
+ }
+
+
+ qn->ops = NULL;
+ qn->ops = axis2_malloc(environment->allocator,sizeof(axis2_qname_ops_t));
+ /* operations */
+ if(!qn->ops)
+ {
+ axis2_free(environment->allocator,qn->localpart);
+ if(qn->namespace_uri)
+ axis2_free(environment->allocator,qn->namespace_uri);
+ axis2_free(environment->allocator,qn->prefix);
+ axis2_free(environment->allocator,qn);
+ environment->error->errorno = AXIS2_ERROR_NO_MEMORY;
+ return NULL;
+ }
+
+ qn->ops->axis2_qname_ops_free = axis2_qname_impl_free;
+ qn->ops->axis2_qname_ops_equals = axis2_qname_impl_equals;
+ return qn;
}