diff options
Diffstat (limited to 'axiom/src/om/om_document.c')
-rw-r--r-- | axiom/src/om/om_document.c | 123 |
1 files changed, 35 insertions, 88 deletions
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 |