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 2005/10/06 14:13:29 UTC

svn commit: r306607 - in /webservices/axis2/trunk/c: include/axis2_om_document.h include/axis2_stax_ombuilder.h modules/xml/om/src/axis2_om_document.c modules/xml/om/src/axis2_stax_ombuilder.c

Author: samisa
Date: Thu Oct  6 05:13:03 2005
New Revision: 306607

URL: http://svn.apache.org/viewcvs?rev=306607&view=rev
Log: (empty)

Modified:
    webservices/axis2/trunk/c/include/axis2_om_document.h
    webservices/axis2/trunk/c/include/axis2_stax_ombuilder.h
    webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_document.c
    webservices/axis2/trunk/c/modules/xml/om/src/axis2_stax_ombuilder.c

Modified: webservices/axis2/trunk/c/include/axis2_om_document.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_om_document.h?rev=306607&r1=306606&r2=306607&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_om_document.h (original)
+++ webservices/axis2/trunk/c/include/axis2_om_document.h Thu Oct  6 05:13:03 2005
@@ -1,109 +1,114 @@
-/*
- * 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_DOCUMENT_H
-#define AXIS2_OM_DOCUMENT_H
-#include <axis2_om_node.h>
-
-//typedef struct axis2_stax_om_builder_t axis2_stax_om_builder_t;
-
-/**
- * @file axis2_om_node.h
- * @brief om_document represents a xml document
- *	
- */
-
-
-
-#define CHAR_SET_ENCODING "UTF-8"
-#define XML_VERSION	"1.0"
-
-
-typedef struct axis2_om_document_t
-{
-	axis2_om_node_t *root_element;
-	axis2_om_node_t *first_child;
-	axis2_om_node_t *last_child;
-	int done;
-	axis2_stax_om_builder_t *builder;
-	char *char_set_encoding;
-	char *xml_version;
-
-}axis2_om_document_t;
-
-
-/**
- *	creates and returns axis2_om_document returns null if there isn't enough memory
- *  @param root_ele pointer to document's root node IF NUll is parsed a document root
- *         will be set to NULL
- *  @param builder pointer to xml builder 
- */
-
-axis2_om_document_t *axis2_om_document_create(axis2_om_node_t *root_ele,axis2_stax_om_builder_t *builder);
-
-/** 
- *  Free axis2_om_document_t struct
- *	@param document 
- */
-
-
-void axis2_free_om_document(axis2_om_document_t *document);
-
-/**
- *	causes the parser to proceed if the xml input is not finised yet
- *	@param document 
- */
-
-
-void axis2_om_document_build_next(axis2_om_document_t *document);
-
-/**
- *	adds the child node as a child to the back of the list
- */
-void axis2_om_document_add_child(axis2_om_document_t *document,axis2_om_node_t *child);
-
-/**
- *	This cause the parser to proceed 	
- *	@param document
- *	@ returns The first 
- */
-
-
-axis2_om_node_t *axis2_om_document_get_first_child(axis2_om_document_t *document);
-
-/**
- * set the CHAR SET ENCODING of this document
- */
-void axis2_document_set_char_set_encoding(axis2_om_document_t *char_set_encoding);
-
-/**
- * set the xml version of this document
- */
-void axis2_document_set_xmlversion(axis2_om_document_t *document);
-
-
-
-
-/*	to implement
- *	get first child with qname
- *	get children iterator
- *	get children with name
- */
-
-
-
-
-#endif // AXIS2_OM_DOCUMENT_H
+/*
+ * 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_DOCUMENT_H
+#define AXIS2_OM_DOCUMENT_H
+#include <axis2_om_node.h>
+
+//typedef struct axis2_stax_om_builder_t axis2_stax_om_builder_t;
+
+/**
+ * @file axis2_om_node.h
+ * @brief om_document represents a xml document
+ *	
+ */
+
+
+
+#define CHAR_SET_ENCODING "UTF-8"
+#define XML_VERSION	"1.0"
+
+
+typedef struct axis2_om_document_t
+{
+	axis2_om_node_t *root_element;
+	axis2_om_node_t *last_child;
+	axis2_om_node_t *first_child;
+	int done;
+	axis2_stax_om_builder_t *builder;
+	char *char_set_encoding;
+	char *xml_version;
+
+}axis2_om_document_t;
+
+
+/**
+ *	creates and returns axis2_om_document returns null if there isn't enough memory
+ *  @param root_ele pointer to document's root node IF NUll is parsed a document root
+ *         will be set to NULL
+ *  @param builder pointer to xml builder 
+ */
+
+axis2_om_document_t *axis2_om_document_create(axis2_om_node_t *root_ele,axis2_stax_om_builder_t *builder);
+
+/** 
+ *  Free axis2_om_document_t struct
+ *	@param document 
+ */
+
+
+void axis2_free_om_document(axis2_om_document_t *document);
+
+/**
+ *	causes the parser to proceed if the xml input is not finised yet
+ *	@param document 
+ */
+
+
+void axis2_om_document_build_next(axis2_om_document_t *document);
+
+/**
+ *	adds the child node as a child to the back of the list
+ */
+void axis2_om_document_add_child(axis2_om_document_t *document,axis2_om_node_t *child);
+
+/**
+ *	This cause the parser to proceed 	
+ *	@param document
+ *	@ returns The first 
+ */
+
+
+axis2_om_node_t *axis2_om_document_get_root_element(axis2_om_document_t *document);
+
+/**
+ * set the CHAR SET ENCODING of this document
+ */
+void axis2_document_set_char_set_encoding(axis2_om_document_t *char_set_encoding);
+
+/**
+ * set the xml version of this document
+ */
+void axis2_document_set_xmlversion(axis2_om_document_t *document);
+
+
+axis2_om_node_t *axis2_om_document_get_next_sibling(axis2_om_document_t *document);
+
+
+axis2_om_node_t *axis2_om_document_get_first_child(axis2_om_document_t *document);
+
+axis2_om_node_t *axis2_om_document_get_current_child(axis2_om_document_t *document);
+
+/*	to implement
+ *	get first child with qname
+ *	get children iterator
+ *	get children with name
+ */
+
+
+
+
+#endif // AXIS2_OM_DOCUMENT_H

Modified: webservices/axis2/trunk/c/include/axis2_stax_ombuilder.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_stax_ombuilder.h?rev=306607&r1=306606&r2=306607&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_stax_ombuilder.h (original)
+++ webservices/axis2/trunk/c/include/axis2_stax_ombuilder.h Thu Oct  6 05:13:03 2005
@@ -1,135 +1,139 @@
-/*
- * 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_STAX_OMBUILDER_H
-#define AXIS2_STAX_OMBUILDER_H
-
-/**
- * @file axis2_stax_om_builder.h
- * @brief om model stax builder 
- */
-
-
-
-#define XMLNS_URI "http://www.w3.org/XML/1998/namespace"
-#define XMLNS_PREFIX "xml"
-
-#include <xmlpullparser.h>
-#include <axis2_om_node.h>
-#include <axis2_om_document.h>
-
-struct axis2_stax_om_builder_s
-{
-	XML_PullParser			*parser;	
-	axis2_om_node_t			*lastnode;
-	axis2_om_document_t	*document;
-	int				done;
-	int				parser_accessed;
-	int				cache;
-};
-
-/**
- *	create an stax_om_builder
- * @param parser   This is the XMLStreamReader of xmlparser
- *				   [ Guththila ]	
- */
-
-axis2_stax_om_builder_t *axis2_stax_om_builder_create(XML_PullParser *parser);
-
-/**
- *	Create an om element and adds to the document
- *	@param builder pointer to the builder
- *  @param returns a pointer to axis2_om_node_t containing the element or NULL if there
- *  isn't enough memory
- */
-
-axis2_om_node_t *axis2_stax_om_builder_create_om_element(
-						axis2_stax_om_builder_t *builder);
-
-/**
- *	creates an om comment
- *	@param builder
- *  @returns 
- */
-
-
-axis2_om_node_t *axis2_stax_om_builder_create_om_comment(
-						axis2_stax_om_builder_t *builder);
-
-/**
- *	create an om doctype
- *
- */
-axis2_om_node_t *axis2_stax_om_builder_create_om_doctype(
-						axis2_stax_om_builder_t *builder_t);
-
-/**
- *	create om_processing_instruction
- */
-
-axis2_om_node_t *axis2_stax_om_builder_create_om_processing_instruction(
-						axis2_stax_om_builder_t *builder);
-
-/**
- *	End element processing
- */
-void axis2_stax_om_builder_end_element(axis2_stax_om_builder_t *builder);
-/**
- *	move parser forward and reacts to events 
- */
-
-int axis2_stax_om_builder_next(axis2_stax_om_builder_t *builder);
-
-/**
- *	process attrbites 
- *
- */
-
-void axis2_stax_om_builder_process_attributes(axis2_stax_om_builder_t *builder,axis2_om_node_t *element_node);
-
-/**
- *	create om text
- *
- */
-axis2_om_node_t *axis2_stax_om_builder_create_om_text(axis2_stax_om_builder_t *builder);
-
-/**
- *	discard building an element
- */
-
-
-void axis2_stax_om_builder_discard(axis2_stax_om_builder_t *builder,axis2_om_node_t *element_node);
-
-/**
- *	process namespaces 
- *
- */
-
-axis2_om_node_t *axis2_stax_om_builder_process_namespace_data(axis2_stax_om_builder_t *builder,axis2_om_node_t *element,int is_soap_element);
-
-char *axis2_stax_om_builder_get_attribute_name(axis2_stax_om_builder_t *builder,int i);
-
-char *axis2_stax_om_builder_get_attribute_prefix(axis2_stax_om_builder_t *builder,int i);
-
-
-char *axis2_stax_om_builder_get_attribute_namespace(axis2_stax_om_builder_t *builder,int i);
-
-
-int axis2_stax_om_builder_get_attribute_count(axis2_stax_om_builder_t *builder);
-
-
-
-#endif // AXIS2_STAX_OMBUILDER_H
+/*
+ * 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_STAX_OMBUILDER_H
+#define AXIS2_STAX_OMBUILDER_H
+
+/**
+ * @file axis2_stax_om_builder.h
+ * @brief om model stax builder 
+ */
+
+
+
+
+
+#include <xmlpullparser.h>
+#include <axis2_om_node.h>
+#include <axis2_om_document.h>
+
+struct axis2_stax_om_builder_s
+{
+	XML_PullParser			*parser;	
+	axis2_om_node_t			*lastnode;
+	axis2_om_document_t	*document;
+	int				done;
+	int				parser_accessed;
+	int				cache;
+	//apr_array_header_t *element_stack;
+};
+
+/**
+ *	create an stax_om_builder
+ * @param parser   This is the XMLStreamReader of xmlparser
+ *				   [ Guththila ]	
+ */
+
+axis2_stax_om_builder_t *axis2_stax_om_builder_create(XML_PullParser *parser);
+
+/**
+ *	Create an om element and adds to the document
+ *	@param builder pointer to the builder
+ *  @param returns a pointer to axis2_om_node_t containing the element or NULL if there
+ *  isn't enough memory
+ */
+
+axis2_om_node_t *axis2_stax_om_builder_create_om_element(
+						axis2_stax_om_builder_t *builder);
+
+/**
+ *	creates an om comment
+ *	@param builder
+ *  @returns 
+ */
+
+
+axis2_om_node_t *axis2_stax_om_builder_create_om_comment(
+						axis2_stax_om_builder_t *builder);
+
+/**
+ *	create an om doctype
+ *
+ */
+axis2_om_node_t *axis2_stax_om_builder_create_om_doctype(
+						axis2_stax_om_builder_t *builder_t);
+
+/**
+ *	create om_processing_instruction
+ */
+
+axis2_om_node_t *axis2_stax_om_builder_create_om_processing_instruction(
+						axis2_stax_om_builder_t *builder);
+
+/**
+ *	End element processing
+ */
+void axis2_stax_om_builder_end_element(axis2_stax_om_builder_t *builder);
+/**
+ *	move parser forward and reacts to events 
+ */
+
+int axis2_stax_om_builder_next(axis2_stax_om_builder_t *builder);
+
+/**
+ *	process attrbites 
+ *
+ */
+
+void axis2_stax_om_builder_process_attributes(axis2_stax_om_builder_t *builder,axis2_om_node_t *element_node);
+
+/**
+ *	create om text
+ *
+ */
+axis2_om_node_t *axis2_stax_om_builder_create_om_text(axis2_stax_om_builder_t *builder);
+
+/**
+ *	discard building an element
+ */
+
+
+void axis2_stax_om_builder_discard(axis2_stax_om_builder_t *builder,axis2_om_node_t *element_node);
+
+/**
+ *	process namespaces 
+ *
+ */
+
+axis2_om_node_t *axis2_stax_om_builder_process_namespace_data(axis2_stax_om_builder_t *builder,axis2_om_node_t *element,int is_soap_element);
+
+char *axis2_stax_om_builder_get_attribute_name(axis2_stax_om_builder_t *builder,int i);
+
+char *axis2_stax_om_builder_get_attribute_prefix(axis2_stax_om_builder_t *builder,int i);
+
+void axis2_stax_om_builder_process_start_document(axis2_stax_om_builder_t* builder);
+
+
+
+
+char *axis2_stax_om_builder_get_attribute_namespace(axis2_stax_om_builder_t *builder,int i);
+
+
+int axis2_stax_om_builder_get_attribute_count(axis2_stax_om_builder_t *builder);
+
+
+
+#endif // AXIS2_STAX_OMBUILDER_H

Modified: webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_document.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_document.c?rev=306607&r1=306606&r2=306607&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_document.c (original)
+++ webservices/axis2/trunk/c/modules/xml/om/src/axis2_om_document.c Thu Oct  6 05:13:03 2005
@@ -1,108 +1,167 @@
-/*
- * 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_om_document.h>
-#include <stdlib.h>
-#include <axis2_errno.h>
-
-axis2_om_document_t *axis2_om_document_create(axis2_om_node_t * root_ele, 
-									axis2_stax_om_builder_t * builder)
-{
-
-    axis2_om_document_t *doc = (axis2_om_document_t *) malloc(
-										sizeof(axis2_om_document_t));
-    if (!doc)
-    {
-		fprintf(stderr,"%d Error",AXIS2_ERROR_OM_MEMORY_ALLOCATION);
-		return NULL;
-    }
-    doc->builder = builder;
-    doc->root_element = root_ele;
-    doc->first_child = NULL;
-    doc->last_child = NULL;
-    doc->char_set_encoding = CHAR_SET_ENCODING;
-    doc->xml_version = XML_VERSION;
-    return doc;
-}
-
-
-void axis2_free_om_document(axis2_om_document_t * doc)
-{
-	if(doc)
-	{
-		if(doc->char_set_encoding)
-			free(doc->char_set_encoding);
-		if(doc->xml_version)
-			free(doc->xml_version);
-		/*   */		
-	
-	free(doc);
-	}
-}
-
-
-void axis2_om_document_set_char_set_encoding(axis2_om_document_t *document,
-					    const char *char_set_encoding)
-{
-    if (document)
-    {
-		if (document->char_set_encoding)
-		{
-			free(document->char_set_encoding);
-		}
-	document->char_set_encoding = strdup(char_set_encoding);
-    }
-}
-
-void axis2_om_document_add_child(axis2_om_document_t * document,
-				  axis2_om_node_t * child)
-{
-    if (!document || !child)
-    {	/* nothing to do */
-		return;
-	}
-    if (document->first_child == NULL)
-    {
-		document->first_child = child;
-		child->prev_sibling = NULL;
-    }
-	else
-    {
-		child->prev_sibling = document->last_child;
-		document->last_child->next_sibling = child;
-    }
-    child->next_sibling = NULL;
-}
-
-
-void axis2_om_document_set_xmlversion(axis2_om_document_t *document,const char *xmlversion)
-{
-	if(document)
-	{
-		if(document->xml_version)
-		{
-			free(document->xml_version);
-		}
-		document->xml_version = strdup(xmlversion);
-	}
-}
-
-
-void axis2_om_document_build_next(axis2_om_document_t *document)
-{
-	axis2_stax_om_builder_next(document->builder);
-}
+/*
+ * 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_om_document.h>
+#include <stdlib.h>
+#include <axis2_errno.h>
+#include <axis2_stax_ombuilder.h>
+
+axis2_om_document_t *axis2_om_document_create(axis2_om_node_t * root_ele,axis2_stax_om_builder_t * builder)
+{
+
+    axis2_om_document_t *doc = (axis2_om_document_t *) malloc(sizeof(axis2_om_document_t));
+    if (!doc)
+    {
+		fprintf(stderr,"%d Error",AXIS2_ERROR_OM_MEMORY_ALLOCATION);
+		return NULL;
+    }
+    doc->builder = builder;
+    doc->root_element = root_ele;
+    doc->first_child = NULL;
+    doc->last_child = NULL;
+    doc->char_set_encoding = CHAR_SET_ENCODING;
+    doc->xml_version = XML_VERSION;
+    doc->done = FALSE;
+    if(builder)
+    {
+        builder->document=doc;
+    }
+    return doc;
+}
+
+
+void axis2_free_om_document(axis2_om_document_t * doc)
+{
+	if(doc)
+	{
+		if(doc->char_set_encoding)
+			free(doc->char_set_encoding);
+		if(doc->xml_version)
+			free(doc->xml_version);
+		/*   */		
+	
+	free(doc);
+	}
+}
+
+
+void axis2_om_document_set_char_set_encoding(axis2_om_document_t *document,
+					    const char *char_set_encoding)
+{
+    if (document)
+    {
+		if (document->char_set_encoding)
+		{
+			free(document->char_set_encoding);
+		}
+	document->char_set_encoding = strdup(char_set_encoding);
+    }
+}
+
+void axis2_om_document_add_child(axis2_om_document_t * document,
+				  axis2_om_node_t * child)
+{
+   if(!(document->root_element) && child)
+   {
+        document->root_element = child;
+   
+   }
+   
+   if(document->root_element && child)
+   {
+        axis2_om_node_add_child(document->root_element,child);
+   }
+   
+}
+
+
+void axis2_om_document_set_xmlversion(axis2_om_document_t *document,const char *xmlversion)
+{
+	if(document)
+	{
+		if(document->xml_version)
+		{
+			free(document->xml_version);
+		}
+		document->xml_version = strdup(xmlversion);
+	}
+}
+
+
+void axis2_om_document_build_next(axis2_om_document_t *document)
+{
+   // printf("next");
+	axis2_stax_om_builder_next(document->builder);
+}
+
+
+axis2_om_node_t *axis2_om_document_get_root_element(axis2_om_document_t *document)
+{
+        if(document && document->root_element)
+        {
+            return document->root_element;
+        }
+        else
+        {   
+            while(!document->root_element)
+                axis2_om_document_build_next(document);
+        }
+        
+        return document->root_element;
+           
+}
+
+axis2_om_node_t *axis2_om_document_get_next_sibling(axis2_om_document_t *document)
+{
+    axis2_om_node_t *lastchild =document->builder->lastnode;
+    if(document && document->builder && document->builder->lastnode)
+    {
+         
+        if(!(lastchild->parent))
+        {
+            /* if parent is null there can't be siblings */
+            return NULL;
+        }
+        while( !(lastchild->next_sibling) && !(lastchild->parent->done))
+            axis2_om_document_build_next(document); 
+    }
+    return lastchild->next_sibling;
+}
+
+axis2_om_node_t *axis2_om_document_get_first_child(axis2_om_document_t *document)
+{
+    axis2_om_node_t *current_child = NULL;
+    current_child = document->builder->lastnode;
+    if(current_child)
+    {
+        while(!(current_child->first_child)&& !(current_child->done))
+        {
+           axis2_om_document_build_next(document);
+        }
+       if(current_child->first_child)
+        return current_child->first_child;
+        else
+            return NULL;
+        
+    }
+    
+}
+
+axis2_om_node_t *axis2_om_document_get_child(axis2_om_document_t *document)
+{
+    return document->builder->lastnode;
+}

Modified: webservices/axis2/trunk/c/modules/xml/om/src/axis2_stax_ombuilder.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/om/src/axis2_stax_ombuilder.c?rev=306607&r1=306606&r2=306607&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/om/src/axis2_stax_ombuilder.c (original)
+++ webservices/axis2/trunk/c/modules/xml/om/src/axis2_stax_ombuilder.c Thu Oct  6 05:13:03 2005
@@ -1,340 +1,434 @@
-/*
- * 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_stax_ombuilder.h>
-#include <axis2_om_node.h>
-#include <stdlib.h>
-#include <namespace.h>
-#include <axis2_om_element.h>
-#include <axis2_errno.h>
-#include <xmlpullparser.h>
-
-axis2_stax_om_builder_t *create_stax_om_builder(XML_PullParser *parser)
-{
-	axis2_om_document_t *document;
-	axis2_stax_om_builder_t *builder = (axis2_stax_om_builder_t*)malloc(sizeof(axis2_stax_om_builder_t));
-	if(!builder)
-	{
-		fprintf(stderr," %d Error ",AXIS2_ERROR_OM_MEMORY_ALLOCATION);
-		return NULL;
-	}
-	builder->parser = parser;
-	builder->cache  = TRUE;
-	builder->parser_accessed = FALSE;
-	builder->done   = FALSE;
-	builder->lastnode=NULL;
-
-	document = axis2_om_document_create(NULL,builder);
-	if(document)
-	{
-		builder->document = document;
-	}
-	return builder;
-}
-
-axis2_om_node_t *axis2_stax_om_builder_create_om_element(
-						axis2_stax_om_builder_t *builder)
-{
-	axis2_om_node_t *element_node;
-	char *localname = XML_PullParser_getName(builder->parser);
-	
-	if(!(builder->lastnode))
-	{	/*  */
-		axis2_om_element_create_with_builder(NULL,localname,NULL,builder,element_node);
-		builder->document->root_element = element_node;
-		axis2_om_document_add_child(builder->document,element_node);
-	}
-	else if(builder->lastnode->done)
-	{	/*  */
-		 axis2_om_element_create_with_builder(builder->lastnode->parent,localname,NULL
-				,builder,element_node);
-		builder->lastnode->next_sibling = element_node;
-		element_node->prev_sibling = builder->lastnode;
-	}
-	else 
-	{	/* */
-		axis2_om_element_create_with_builder(builder->lastnode,localname,NULL,builder,element_node);
-		builder->lastnode->first_child = element_node;
-		element_node->parent = builder->lastnode;
-	}
-
-	// process namespace data
-	// process attributes
-
-return NULL;
-}
-
-axis2_om_node_t *axis2_stax_om_builder_create_om_comment(
-						axis2_stax_om_builder_t *builder)
-{
-	
-	/* guththila does not support yet*/
-	return NULL;
-}
-
-
-axis2_om_node_t *axis2_stax_om_builder_create_om_doctype(
-						axis2_stax_om_builder_t *builder)
-{
-	/*  guththila does not support yet */
-}
-
-
-axis2_om_node_t *axis2_stax_om_builder_create_om_processing_instruction(
-						axis2_stax_om_builder_t *builder)
-{
-	/* guththila does not support yet */
-
-
-
-
-
-}
-
-void axis2_stax_om_builder_end_element(axis2_stax_om_builder_t *builder)
-{	
-	axis2_om_node_t *parent;
-	if(builder->lastnode->done)
-	{
-		parent = builder->lastnode->parent;
-		parent->done = TRUE;
-		builder->lastnode = parent;
-	}
-	else
-	{
-		builder->lastnode->done = TRUE;
-	}
-}
-
-
-int axis2_stax_om_builder_next(axis2_stax_om_builder_t *builder)
-{
-	int token = 0;
-	if(builder->done)
-	{
-		fprintf(stderr,"%d Errpr",-1);
-		return NULL;
-	}
-	
-	token = XML_PullParser_next (builder->parser);
-	if(!(builder->cache))
-	{
-		return token;
-	}
-
-
-	switch(token)
-	{
-	case START_DOCUMENT:
-		{
-		
-		}
-		break;
-
-	case START_ELEMENT:
-		{
-			builder->lastnode = axis2_stax_om_builder_create_om_element(builder);
-		}
-		break;
-	case END_ELEMENT:
-		{
-		
-			axis2_stax_om_builder_end_element(builder);
-	
-		
-		
-		}
-		break;
-	case CHARACTER:
-		{
-			builder->lastnode = axis2_stax_om_builder_create_om_text(builder);
-		
-		
-		
-		}
-		break;
-	case COMMENT:
-		{
-				
-		
-		
-		}
-		break;
-		
-		
-	};
-}
-
-
-void axis2_stax_om_builder_process_attributes(axis2_stax_om_builder_t *builder,axis2_om_node_t *element_node)
-{
-	int i=0;
-	axis2_om_namespace_t *ns=NULL;
-	char *uri=NULL;
-	char *prefix=NULL;
-	
-	int attribute_count = XML_PullParser_getAttributeCount(builder->parser);
-	for(i=0 ; i < attribute_count ; i++)
-	{
-			
-		uri     = XML_PullParser_getAttributeNamespace_by_number(builder->parser,i);
-		prefix  = XML_PullParser_getAttributePrefix_by_number(builder->parser,i);
-		if(strcmp(uri,"") != 0)
-		{
-			ns = axis2_om_element_find_namespace(element_node,uri,prefix);	
-		}
-		
-		if(ns == NULL && (prefix != NULL) && 	(uri != NULL)
-				&& (strcmp(prefix,XMLNS_PREFIX) == 0)
-				&& (strcmp(uri,XMLNS_URI) == 0))
-		{
-			axis2_om_element_declare_namespace_with_ns_uri_prefix(element_node,
-										XMLNS_URI,XMLNS_PREFIX);
-			ns = axis2_om_element_find_namespace(element_node,uri,prefix);
-			
-			
-		}
-		axis2_om_element_add_attribute_with_namespace(element_node
-				,XML_PullParser_getAttributeName_by_number(builder->parser,i)
-				,XML_PullParser_getAttributeValue_by_number(builder->parser,i),ns);	
-	}
-}
-
-
-axis2_om_node_t *axis2_stax_om_builder_create_om_text(axis2_stax_om_builder_t *builder)
-{
-	axis2_om_node_t *node;
-	if(builder->lastnode)
-	{
-		fprintf(stderr," ERROR");
-		return NULL;
-	}
-	if(builder->lastnode->done)
-	{
-		axis2_om_text_create(builder->lastnode->parent,
-			XML_PullParser_getValue(builder->parser),node);		
-	}
-	else
-	{
-		axis2_om_text_create(builder->lastnode,
-			XML_PullParser_getValue(builder->parser),node);		
-		
-	}
-	return node;	
-}
-
-
-void axis2_stax_om_builder_discard(axis2_stax_om_builder_t *builder,axis2_om_node_t *element_node)
-{
-/*	axis2_om_node_t *element;
-	if(element_node->done || !(builder->cache))
-	{
-		fprintf(stderr," Error");
-		return;		
-	}
-	
-		cache = FALSE;
-		do
-		(
-			while(XML_PullParser_next(builder->parser) != END_ELEMENT);
-				
-		}while(
-				
-	 
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-*/	
-	
-	
-}
-
-
-axis2_om_node_t *axis2_stax_om_builder_process_namespace_data(axis2_stax_om_builder_t *builder,axis2_om_node_t *element,int is_soap_element)
-{
-	int i=0;
-	char *nsuri  = NULL;
-	char *prefix = NULL;
-	NAMESPACE *NS;
-	axis2_om_namespace_t *ns,*ns1;
-	int namespace_count = XML_PullParser_getNamespaceCount (builder->parser);
-	for( i = 0 ; i < namespace_count ; i++)
-	{
-		axis2_om_element_declare_namespace_with_ns_uri_prefix(element,XML_PullParser_getNamespaceUri_by_number(builder->parser,i),XML_PullParser_getNamespacePrefix_by_number(builder->parser,i));
-	}
-	/* set own namespace */
-	NS = XML_PullParser_getNamespace(builder->parser);
-	nsuri  =XML_PullParser_getNamespaceUri(builder->parser,NS);
-	prefix =XML_PullParser_getNamespacePrefix(builder->parser,NS);
-	if(strcmp(nsuri,"") != 0)
-	{
-		if(!prefix)
-		{
-			
-			ns =  axis2_om_element_find_namespace(element,nsuri,"");
-			if(!ns)
-			{
-				ns = axis2_om_element_declare_namespace_with_ns_uri_prefix(element,nsuri,"");			
-			}
-			if(((axis2_om_element_t*)element)->ns == ns)
-			{
-				axis2_om_element_set_namespace(element,ns);
-			}
-		}
-		else
-		{
-			ns = axis2_om_element_find_namespace(element,nsuri,prefix);
-			if(!ns)
-			{
-				ns1 = axis2_om_namespace_create(nsuri,prefix);
-				axis2_om_element_set_namespace(element,ns);
-			}
-			else
-			{
-				axis2_om_element_set_namespace(element,ns);
-			}
-		}
-	}
-}
-
-char *axis2_stax_om_builder_get_attribute_prefix(axis2_stax_om_builder_t *builder,int i)
-{
-	return XML_PullParser_getAttributePrefix_by_number(builder->parser,i);
-}
-
-
-
-char *axis2_stax_om_builder_get_attribute_name(axis2_stax_om_builder_t *builder,int i)
-{
-	return XML_PullParser_getAttributeName_by_number(builder->parser,i);
-}
-
-int axis2_stax_om_builder_get_attribute_count(axis2_stax_om_builder_t *builder)
-{
-	return XML_PullParser_getAttributeCount(builder->parser);	
-}
-
-char *axis2_stax_om_builder_get_attribute_namespace(axis2_stax_om_builder_t *builder,int i)
-{
-	XML_PullParser_getAttributeNamespace_by_number(	builder->parser,i);
-}
+/*
+ * 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_stax_ombuilder.h>
+#include <axis2_om_node.h>
+#include <stdlib.h>
+#include <namespace.h>
+#include <axis2_om_element.h>
+#include <axis2_errno.h>
+#include <xmlpullparser.h>
+#include <axis2_om_text.h>
+
+const char XMLNS_URI[] ="http://www.w3.org/XML/1998/namespace";
+const char XMLNS_PREFIX[]= "xml";
+
+static int isnot_whitespace(char s[])
+{
+   
+    int n=0;
+     
+    for(n = strlen(s)-1;n>=0;n--)
+        if(s[n] !=' ' && s[n] !='\t' && s[n] != '\n')
+            break;
+    if(n== -1)
+        n =0;
+    
+    return n;
+}
+
+static int trim(char s[])
+{
+    int n;
+    for(n = strlen(s)-1;n>=0;n--)
+        if(s[n] !=' ' && s[n] !='\t' && s[n] != '\n')
+            break;
+    s[n+1] = '\0';
+  return n;
+}
+
+axis2_stax_om_builder_t *axis2_stax_om_builder_create(XML_PullParser *parser)
+{
+	axis2_om_document_t *document;
+	axis2_stax_om_builder_t *builder = (axis2_stax_om_builder_t*)malloc(sizeof(axis2_stax_om_builder_t));
+	if(!builder)
+	{
+		fprintf(stderr," %d Error ",AXIS2_ERROR_OM_MEMORY_ALLOCATION);
+		return NULL;
+	}
+	builder->parser  = parser;
+	builder->cache   = TRUE;
+	builder->parser_accessed = FALSE;
+	builder->done   = FALSE;
+	builder->lastnode = NULL;
+    builder->document= NULL;
+	return builder;
+}
+
+
+axis2_om_node_t *axis2_stax_om_builder_create_om_element(
+						axis2_stax_om_builder_t *builder)
+{
+	axis2_om_node_t *element_node;
+	char *localname = XML_PullParser_getName(builder->parser);
+	
+	if(!(builder->lastnode))
+	{	/*  */
+		axis2_om_element_create(NULL,localname,NULL,&element_node);
+		builder->document->root_element = element_node;
+		
+		//axis2_om_document_add_child(builder->document,element_node);
+	}
+	else if(builder->lastnode->done)
+	{	/*  */
+		axis2_om_element_create(builder->lastnode->parent,localname,NULL,&element_node);
+		builder->lastnode->next_sibling = element_node;
+		element_node->prev_sibling = builder->lastnode;
+	}
+	else 
+	{	/* */
+		axis2_om_element_create(builder->lastnode,localname,NULL,&element_node);
+		builder->lastnode->first_child = element_node;
+		element_node->parent = builder->lastnode;
+	}
+    axis2_stax_om_builder_process_attributes(builder,element_node);
+	axis2_stax_om_builder_process_namespace_data(builder,element_node,0);
+	
+	// process attributes
+
+return element_node;
+}
+
+axis2_om_node_t *axis2_stax_om_builder_create_om_comment(
+						axis2_stax_om_builder_t *builder)
+{
+	
+	/* guththila does not support yet*/
+	return NULL;
+}
+
+
+axis2_om_node_t *axis2_stax_om_builder_create_om_doctype(
+						axis2_stax_om_builder_t *builder)
+{
+	/*  guththila does not support yet */
+	return NULL;
+}
+
+
+axis2_om_node_t *axis2_stax_om_builder_create_om_processing_instruction(
+						axis2_stax_om_builder_t *builder)
+{
+	/* guththila does not support yet */
+	return NULL;
+}
+
+void axis2_stax_om_builder_end_element(axis2_stax_om_builder_t *builder)
+{	
+	axis2_om_node_t *parent;
+	if(builder->lastnode)
+	{
+    	if(builder->lastnode->done)
+	    {
+		    parent = builder->lastnode->parent;
+		    parent->done = TRUE;
+		    builder->lastnode = parent;
+	    }
+	    else
+	    {
+		    builder->lastnode->done = TRUE;
+	    }
+	}
+}
+
+
+int axis2_stax_om_builder_next(axis2_stax_om_builder_t *builder)
+{
+	int token = 0;
+
+	
+	if(builder->done)
+	{
+		fprintf(stderr,"%d Error",-1);
+		return NULL;
+	}
+	
+	token = XML_PullParser_next (builder->parser);
+	 if(token = -1)
+    {
+        builder->done = TRUE;
+        return 0;
+    }
+	if(!(builder->cache))
+	{
+		return token;
+	}
+   
+
+	switch(token)
+	{
+	case START_DOCUMENT:
+		{
+		
+		axis2_stax_om_builder_process_start_document(builder);
+		}
+		break;
+
+	case START_ELEMENT:
+		{
+		    
+		builder->lastnode = axis2_stax_om_builder_create_om_element(builder);
+		}
+		break;
+	case END_ELEMENT:
+		{
+		  axis2_stax_om_builder_end_element(builder);
+	   	}
+		break;
+	case CHARACTER:
+		{
+		
+		builder->lastnode = axis2_stax_om_builder_create_om_text(builder);
+		}
+		break;
+	case COMMENT:
+		{
+				
+		
+		
+		}
+		break;
+		
+		
+	};
+	
+}
+
+
+void axis2_stax_om_builder_process_attributes(axis2_stax_om_builder_t *builder,axis2_om_node_t *element_node)
+{
+	int i=0;
+	axis2_om_namespace_t *ns=NULL;
+	char *uri=NULL;
+	char *prefix=NULL;
+	
+	int attribute_count = XML_PullParser_getAttributeCount(builder->parser);
+	for(i=0 ; i < attribute_count ; i++)
+	{
+	    
+		uri     = XML_PullParser_getAttributeNamespace_by_number(builder->parser,i);
+		prefix  = XML_PullParser_getAttributePrefix_by_number(builder->parser,i);
+		//printf("\nAttribute count %d %s %s\n",attribute_count,uri,prefix);
+		
+		if(uri){
+		    if(strcmp(uri," ") != 0);
+		    {
+			    ns = axis2_om_element_find_namespace(element_node,uri,prefix);	
+		    }
+		}
+		
+		if(ns == NULL && prefix && uri	&& (strcmp(prefix,XMLNS_PREFIX) == 0)
+				&& (strcmp(uri,XMLNS_URI) == 0))
+		{
+			axis2_om_element_declare_namespace_with_ns_uri_prefix(element_node,
+										XMLNS_URI,XMLNS_PREFIX);
+			ns = axis2_om_element_find_namespace(element_node,uri,prefix);
+			
+			
+		}
+		axis2_om_element_add_attribute_with_namespace(element_node
+				,XML_PullParser_getAttributeName_by_number(builder->parser,i)
+				,XML_PullParser_getAttributeValue_by_number(builder->parser,i),ns);	
+				
+		
+	}
+	
+}
+
+
+axis2_om_node_t *axis2_stax_om_builder_create_om_text(axis2_stax_om_builder_t *builder)
+{
+    char *value;
+	axis2_om_node_t *node=NULL;
+	//axis2_om_text_t *t,*t1;
+	value = XML_PullParser_getValue(builder->parser);
+	
+
+	
+	
+	if(!value || !(builder->lastnode) )
+	{
+	         return builder->lastnode;
+	}
+	
+	if(!isnot_whitespace(value))
+	        return builder->lastnode;
+	
+	if(builder->lastnode->done)
+	{
+		axis2_om_text_create(builder->lastnode->parent,
+			value,&node);
+					
+	}
+	else
+	{  
+		 axis2_om_text_create(builder->lastnode,value,&node);
+	}
+	return node;	
+}
+
+
+void axis2_stax_om_builder_discard_element(axis2_stax_om_builder_t *builder)
+{
+   axis2_om_node_t *element=NULL;
+   axis2_om_node_t *prev_node=NULL;
+   axis2_om_node_t *parent = NULL;
+   element = builder->lastnode;
+	
+	if(element->done || !(builder->cache))
+	{
+		fprintf(stderr," Error");
+		return;		
+	}
+	
+	builder->cache = FALSE;
+	do
+	{   
+		while(XML_PullParser_next(builder->parser) != END_ELEMENT);
+	}while(!(element->done));
+	
+	//All children of this element is build 
+	
+	prev_node = element->prev_sibling;
+	if(prev_node)
+	{
+	    prev_node->next_sibling = NULL;
+	
+	}else
+	{
+	    parent = element->parent;
+	    parent->first_child = NULL;
+	    builder->lastnode = parent;
+	}
+	builder->cache = TRUE;
+}
+
+void axis2_stax_om_builder_process_start_document(axis2_stax_om_builder_t* builder)
+{
+    /* skiping */
+    ATTRIBUTE *a;
+	char *p;
+	 int ix;
+    if(!(builder->document))
+    {
+        return;
+    }
+   
+    ix = XML_PullParser_getAttributeCount (builder->parser);
+    for (; ix > 0; ix--)
+    {
+		a = XML_PullParser_getAttribute (builder->parser);
+		p = XML_PullParser_getAttributeName (builder->parser, a);
+		free (p);
+		p = XML_PullParser_getAttributeValue (builder->parser, a);
+    	free (p);
+    }
+}
+
+
+
+
+
+
+
+axis2_om_node_t *axis2_stax_om_builder_process_namespace_data(axis2_stax_om_builder_t *builder,axis2_om_node_t *element,int is_soap_element)
+{
+	int i=0;
+	char *nsuri  = NULL;
+	char *prefix = NULL;
+	char *uri=NULL;
+	char *prefixi=NULL;
+	NAMESPACE *NS;
+	
+	
+	int namespace_count;
+	
+	
+	axis2_om_namespace_t *ns,*ns1;
+	//e = Stack_last (builder->parser->dep);
+	//d = e->depth->count;
+	namespace_count = XML_PullParser_getNamespaceCount (builder->parser);
+	
+	for( ;namespace_count >0 ; namespace_count--)
+	{
+	   // uri = XML_PullParser_getNamespaceUri_by_number(builder->parser,namespace_count);
+	   // prefix = XML_PullParser_getNamespacePrefix_by_number(builder->parser,namespace_count);
+		axis2_om_element_declare_namespace_with_ns_uri_prefix(element,XML_PullParser_getNamespaceUri_by_number(builder->parser,namespace_count),XML_PullParser_getNamespacePrefix_by_number(builder->parser,namespace_count));
+	
+	}
+	// set own namespace //
+	
+	NS = XML_PullParser_getNamespace(builder->parser);
+	nsuri  =XML_PullParser_getNamespaceUri(builder->parser,NS);
+	prefix =XML_PullParser_getNamespacePrefix(builder->parser,NS);
+    
+	if(strcmp(nsuri," ") != 0)
+	{
+		if(!prefix)
+		{
+			
+			ns =  axis2_om_element_find_namespace(element,nsuri,"");
+			if(!ns)
+			{
+				ns = axis2_om_element_declare_namespace_with_ns_uri_prefix(element,nsuri,"");			
+			}
+			if(((axis2_om_element_t*)element)->ns == ns)
+			{
+				axis2_om_element_set_namespace(element,ns);
+			}
+		}
+		else
+		{
+			ns = axis2_om_element_find_namespace(element,nsuri,prefix);
+			
+			if(!ns)
+			{
+				ns1 = axis2_om_namespace_create(nsuri,prefix);
+				axis2_om_element_set_namespace(element,ns1);
+				
+			}
+			else
+			{
+			    
+				axis2_om_element_set_namespace(element,ns);
+			}
+		}
+	}
+	
+}
+
+char *axis2_stax_om_builder_get_attribute_prefix(axis2_stax_om_builder_t *builder,int i)
+{
+	return XML_PullParser_getAttributePrefix_by_number(builder->parser,i);
+}
+
+
+
+char *axis2_stax_om_builder_get_attribute_name(axis2_stax_om_builder_t *builder,int i)
+{
+	return XML_PullParser_getAttributeName_by_number(builder->parser,i);
+}
+
+int axis2_stax_om_builder_get_attribute_count(axis2_stax_om_builder_t *builder)
+{
+	return XML_PullParser_getAttributeCount(builder->parser);	
+}
+
+char *axis2_stax_om_builder_get_attribute_namespace(axis2_stax_om_builder_t *builder,int i)
+{
+	XML_PullParser_getAttributeNamespace_by_number(	builder->parser,i);
+}
+