summaryrefslogtreecommitdiffstats
path: root/axiom/src/om
diff options
context:
space:
mode:
Diffstat (limited to 'axiom/src/om')
-rw-r--r--axiom/src/om/axiom_stax_builder_internal.h27
-rw-r--r--axiom/src/om/om_document.c123
-rw-r--r--axiom/src/om/om_stax_builder.c5
3 files changed, 55 insertions, 100 deletions
diff --git a/axiom/src/om/axiom_stax_builder_internal.h b/axiom/src/om/axiom_stax_builder_internal.h
index e78c776..ca78e7d 100644
--- a/axiom/src/om/axiom_stax_builder_internal.h
+++ b/axiom/src/om/axiom_stax_builder_internal.h
@@ -66,18 +66,7 @@ extern "C"
axiom_stax_builder_t * builder,
const axutil_env_t * env);
- /**
- * Builds the next node from stream. Moves pull parser forward and reacts
- * to events.
- * @param builder pointer to stax builder struct to be used
- * @param environment Environment. MUST NOT be NULL.
- * @return a pointer to the next node, or NULL if there are no more nodes.
- * On erros sets the error and returns NULL.
- */
- axiom_node_t *AXIS2_CALL
- axiom_stax_builder_next(
- struct axiom_stax_builder *builder,
- const axutil_env_t * env);
+
/**
* builder is finished building om structure
@@ -103,6 +92,19 @@ extern "C"
struct axiom_stax_builder *builder,
const axutil_env_t * env);
+ /**
+ * Builds the next node from stream. Moves pull parser forward and reacts
+ * to events.
+ * @param builder pointer to stax builder struct to be used
+ * @param environment Environment. MUST NOT be NULL.
+ * @return a pointer to the next node, or NULL if there are no more nodes.
+ * On erros sets the error and returns NULL.
+ */
+ axiom_node_t *AXIS2_CALL
+ axiom_stax_builder_next(
+ struct axiom_stax_builder *builder,
+ const axutil_env_t * env);
+
#if 0
/**
* Discards the element that is being built currently.
@@ -126,6 +128,7 @@ extern "C"
const axutil_env_t * env,
axis2_bool_t enable_cache);
+
#endif
/** @} */
diff --git a/axiom/src/om/om_document.c b/axiom/src/om/om_document.c
index 70e905a..625fd5b 100644
--- a/axiom/src/om/om_document.c
+++ b/axiom/src/om/om_document.c
@@ -24,15 +24,11 @@ struct axiom_document
/** root element */
axiom_node_t *root_element;
- /** last child */
- axiom_node_t *last_child;
-
/** builder of the document */
struct axiom_stax_builder *builder;
};
-
axiom_document_t *AXIS2_CALL
axiom_document_create(
const axutil_env_t * env,
@@ -50,7 +46,6 @@ axiom_document_create(
document->builder = builder;
document->root_element = root;
- document->last_child = root;
return document;
}
@@ -74,59 +69,18 @@ axiom_document_free_self(
AXIS2_FREE(env->allocator, document);
}
-axiom_node_t *AXIS2_CALL
-axiom_document_build_next(
- axiom_document_t * document,
- const axutil_env_t * env)
-{
- axiom_node_t *last_child = NULL;
-
-
- if(!document->builder)
- {
- return NULL;
- }
-
- if(!(document->root_element))
- {
- last_child = axiom_stax_builder_next(document->builder, env);
- if(last_child)
- {
- document->last_child = last_child;
- document->root_element = last_child;
- }
- return last_child;
- }
- else if((document->root_element) && (axiom_node_is_complete(document->root_element, env)
- == AXIS2_TRUE))
- return NULL; /* Nothing wrong but done with pulling */
-
- last_child = axiom_stax_builder_next(document->builder, env);
- if(last_child)
- {
- document->last_child = last_child;
- }
- return last_child;
-}
-
axis2_status_t AXIS2_CALL
axiom_document_set_root_element(
axiom_document_t * document,
const axutil_env_t * env,
axiom_node_t * node)
{
- AXIS2_PARAM_CHECK(env->error, node, AXIS2_FAILURE);
-
if(document->root_element)
{
axiom_node_free_tree(document->root_element, env);
- document->root_element = node;
- return AXIS2_SUCCESS;
- }
- else
- {
- document->root_element = node;
}
+
+ document->root_element = node;
return AXIS2_SUCCESS;
}
@@ -135,62 +89,42 @@ axiom_document_get_root_element(
axiom_document_t * document,
const axutil_env_t * env)
{
- axiom_node_t *node = NULL;
-
if(document->root_element)
{
return document->root_element;
}
- node = axiom_document_build_next(document, env);
- if(document->root_element)
+ /* force to build the root node */
+ if(!axiom_stax_builder_next(document->builder, env))
{
- return document->root_element;
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_DOCUMENT_STATE_ROOT_NULL, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unable to get root node");
}
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_DOCUMENT_STATE_ROOT_NULL, AXIS2_FAILURE);
- return NULL;
+
+ return document->root_element;
}
AXIS2_EXTERN axiom_node_t *AXIS2_CALL
axiom_document_build_all(
- struct axiom_document * document,
- const axutil_env_t * env)
+ axiom_document_t *document,
+ const axutil_env_t *env)
{
- if(!document)
- {
- return NULL;
- }
- if(!document->root_element)
+ do
{
- axiom_document_get_root_element(document, env);
- }
- if(document->root_element)
- {
- do
+ axiom_node_t *ret_val = NULL;
+ ret_val = axiom_stax_builder_next(document->builder, env);
+ if(!ret_val && !axiom_node_is_complete(document->root_element, env))
{
- axiom_node_t *ret_val = NULL;
- ret_val = axiom_document_build_next(document, env);
- if(!ret_val)
- {
- if(axiom_node_is_complete(document->root_element, env) == AXIS2_TRUE)
- {
-
- /** document is completly build */
- return document->root_element;
- }
- else
- {
-
- /** error occurred */
- return NULL;
- }
- }
+ /* if return value is null and root node is not fully completed, this means there is
+ * an error occurred */
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "Error occurred when building all nodes of document");
+ return NULL;
}
- while(!axiom_node_is_complete(document->root_element, env));
- return document->root_element;
}
- else
- return NULL;
+ while(document->root_element && !axiom_node_is_complete(document->root_element, env));
+
+ return document->root_element;
}
#if 0
@@ -233,4 +167,17 @@ axiom_document_serialize(
return AXIS2_FAILURE;
}
}
+
+axiom_node_t *AXIS2_CALL
+axiom_document_build_next(
+ axiom_document_t * document,
+ const axutil_env_t * env)
+{
+ if(document->root_element && axiom_node_is_complete(document->root_element, env))
+ {
+ return NULL; /* Nothing wrong but done with pulling */
+ }
+
+ return axiom_stax_builder_next(document->builder, env);
+}
#endif
diff --git a/axiom/src/om/om_stax_builder.c b/axiom/src/om/om_stax_builder.c
index 77a8c3e..892a46c 100644
--- a/axiom/src/om/om_stax_builder.c
+++ b/axiom/src/om/om_stax_builder.c
@@ -488,6 +488,11 @@ axiom_stax_builder_create_om_element(
{
/* since last node is null, this should be the root node */
om_ele = axiom_element_create_str(env, NULL, temp_localname_str, NULL, &element_node);
+ if(!element_node)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create element");
+ return NULL;
+ }
om_builder->root_node = element_node;
if(om_builder->document)
{