diff options
author | shankar | 2010-03-23 05:56:22 +0000 |
---|---|---|
committer | shankar | 2010-03-23 05:56:22 +0000 |
commit | e58fa35ea4989a309b9b392ec97c09ddc9dc54d8 (patch) | |
tree | 9f2ad248037954ff38576a3565d5b1779f579aaa /axiom | |
parent | 6c449d8ae9530baf32b5f29e0c733c2d7299b7bf (diff) | |
download | axis2c-e58fa35ea4989a309b9b392ec97c09ddc9dc54d8.tar.gz axis2c-e58fa35ea4989a309b9b392ec97c09ddc9dc54d8.tar.bz2 |
refactoring
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@926468 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'axiom')
-rw-r--r-- | axiom/src/parser/guththila/guththila_xml_reader_wrapper.c | 306 |
1 files changed, 102 insertions, 204 deletions
diff --git a/axiom/src/parser/guththila/guththila_xml_reader_wrapper.c b/axiom/src/parser/guththila/guththila_xml_reader_wrapper.c index 086ed12..6dfce12 100644 --- a/axiom/src/parser/guththila/guththila_xml_reader_wrapper.c +++ b/axiom/src/parser/guththila/guththila_xml_reader_wrapper.c @@ -22,15 +22,18 @@ /**************** function prototypes ******************************************/ -int AXIS2_CALL guththila_xml_reader_wrapper_next( +int AXIS2_CALL +guththila_xml_reader_wrapper_next( axiom_xml_reader_t * parser, const axutil_env_t * env); -void AXIS2_CALL guththila_xml_reader_wrapper_free( +void AXIS2_CALL +guththila_xml_reader_wrapper_free( axiom_xml_reader_t * parser, const axutil_env_t * env); -int AXIS2_CALL guththila_xml_reader_wrapper_get_attribute_count( +int AXIS2_CALL +guththila_xml_reader_wrapper_get_attribute_count( axiom_xml_reader_t * parser, const axutil_env_t * env); @@ -58,11 +61,13 @@ guththila_xml_reader_wrapper_get_attribute_namespace_by_number( const axutil_env_t * env, int i); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_value( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_value( axiom_xml_reader_t * parser, const axutil_env_t * env); -int AXIS2_CALL guththila_xml_reader_wrapper_get_namespace_count( +int AXIS2_CALL +guththila_xml_reader_wrapper_get_namespace_count( axiom_xml_reader_t * parser, const axutil_env_t * env); @@ -78,36 +83,44 @@ guththila_xml_reader_wrapper_get_namespace_prefix_by_number( const axutil_env_t * env, int i); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_prefix( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_prefix( axiom_xml_reader_t * parser, const axutil_env_t * env); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_name( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_name( axiom_xml_reader_t * parser, const axutil_env_t * env); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_pi_target( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_pi_target( axiom_xml_reader_t * parser, const axutil_env_t * env); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_pi_data( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_pi_data( axiom_xml_reader_t * parser, const axutil_env_t * env); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_dtd( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_dtd( axiom_xml_reader_t * parser, const axutil_env_t * env); -void AXIS2_CALL guththila_xml_reader_wrapper_xml_free( +void AXIS2_CALL +guththila_xml_reader_wrapper_xml_free( axiom_xml_reader_t * parser, const axutil_env_t * env, void *data); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_char_set_encoding( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_char_set_encoding( axiom_xml_reader_t * parser, const axutil_env_t * env); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_namespace_uri( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_namespace_uri( axiom_xml_reader_t * parser, const axutil_env_t * env); @@ -147,37 +160,38 @@ typedef struct guththila_xml_reader_wrapper_impl /**********End macros -- event_map initializing function *********************/ -static axis2_status_t +static void guththila_xml_reader_wrapper_init_map( guththila_xml_reader_wrapper_impl_t * parser) { - if(parser) - { - parser->event_map[GUTHTHILA_START_DOCUMENT] = AXIOM_XML_READER_START_DOCUMENT; - parser->event_map[GUTHTHILA_START_ELEMENT] = AXIOM_XML_READER_START_ELEMENT; - parser->event_map[GUTHTHILA_END_ELEMENT] = AXIOM_XML_READER_END_ELEMENT; - parser->event_map[GUTHTHILA_SPACE] = AXIOM_XML_READER_SPACE; - parser->event_map[GUTHTHILA_EMPTY_ELEMENT] = AXIOM_XML_READER_EMPTY_ELEMENT; - parser->event_map[GUTHTHILA_CHARACTER] = AXIOM_XML_READER_CHARACTER; - parser->event_map[GUTHTHILA_ENTITY_REFERANCE] = AXIOM_XML_READER_ENTITY_REFERENCE; - parser->event_map[GUTHTHILA_COMMENT] = AXIOM_XML_READER_COMMENT; - return AXIS2_SUCCESS; - } - return AXIS2_FAILURE; + parser->event_map[GUTHTHILA_START_DOCUMENT] = AXIOM_XML_READER_START_DOCUMENT; + parser->event_map[GUTHTHILA_START_ELEMENT] = AXIOM_XML_READER_START_ELEMENT; + parser->event_map[GUTHTHILA_END_ELEMENT] = AXIOM_XML_READER_END_ELEMENT; + parser->event_map[GUTHTHILA_SPACE] = AXIOM_XML_READER_SPACE; + parser->event_map[GUTHTHILA_EMPTY_ELEMENT] = AXIOM_XML_READER_EMPTY_ELEMENT; + parser->event_map[GUTHTHILA_CHARACTER] = AXIOM_XML_READER_CHARACTER; + parser->event_map[GUTHTHILA_ENTITY_REFERANCE] = AXIOM_XML_READER_ENTITY_REFERENCE; + parser->event_map[GUTHTHILA_COMMENT] = AXIOM_XML_READER_COMMENT; } -static const axiom_xml_reader_ops_t axiom_xml_reader_ops_var = { guththila_xml_reader_wrapper_next, - guththila_xml_reader_wrapper_free, guththila_xml_reader_wrapper_get_attribute_count, +static const axiom_xml_reader_ops_t axiom_xml_reader_ops_var = { + guththila_xml_reader_wrapper_next, + guththila_xml_reader_wrapper_free, + guththila_xml_reader_wrapper_get_attribute_count, guththila_xml_reader_wrapper_get_attribute_name_by_number, guththila_xml_reader_wrapper_get_attribute_prefix_by_number, guththila_xml_reader_wrapper_get_attribute_value_by_number, guththila_xml_reader_wrapper_get_attribute_namespace_by_number, - guththila_xml_reader_wrapper_get_value, guththila_xml_reader_wrapper_get_namespace_count, + guththila_xml_reader_wrapper_get_value, + guththila_xml_reader_wrapper_get_namespace_count, guththila_xml_reader_wrapper_get_namespace_uri_by_number, guththila_xml_reader_wrapper_get_namespace_prefix_by_number, - guththila_xml_reader_wrapper_get_prefix, guththila_xml_reader_wrapper_get_name, - guththila_xml_reader_wrapper_get_pi_target, guththila_xml_reader_wrapper_get_pi_data, - guththila_xml_reader_wrapper_get_dtd, guththila_xml_reader_wrapper_xml_free, + guththila_xml_reader_wrapper_get_prefix, + guththila_xml_reader_wrapper_get_name, + guththila_xml_reader_wrapper_get_pi_target, + guththila_xml_reader_wrapper_get_pi_data, + guththila_xml_reader_wrapper_get_dtd, + guththila_xml_reader_wrapper_xml_free, guththila_xml_reader_wrapper_get_char_set_encoding, guththila_xml_reader_wrapper_get_namespace_uri, guththila_xml_reader_wrapper_get_namespace_uri_by_prefix, @@ -186,65 +200,67 @@ static const axiom_xml_reader_ops_t axiom_xml_reader_ops_var = { guththila_xml_r /********************************************************************************/ -AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL -axiom_xml_reader_create_for_file( - const axutil_env_t * env, - char *filename, - const axis2_char_t * encoding) +static axiom_xml_reader_t *AXIS2_CALL +axiom_xml_reader_create_basic( + const axutil_env_t *env, + guththila_reader_t *reader, + void *ctx) { guththila_xml_reader_wrapper_impl_t *guththila_impl = NULL; guththila_t *guththila = NULL; - AXIS2_ENV_CHECK(env, NULL); + if(!reader) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid guththila reader"); + return NULL; + } guththila_impl = AXIS2_MALLOC(env->allocator, sizeof(guththila_xml_reader_wrapper_impl_t)); - if(!guththila_impl) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + guththila_reader_free(reader, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Insufficient memory to create xml reader wrapper"); return NULL; } - guththila_impl->reader = guththila_reader_create_for_file(filename, env); - - if(!(guththila_impl->reader)) + guththila = (guththila_t *)AXIS2_MALLOC(env->allocator, sizeof(guththila_t)); + if(!guththila) { AXIS2_FREE(env->allocator, guththila_impl); + guththila_reader_free(reader, env); AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Insufficient memory to create guththila"); return NULL; } - guththila = (guththila_t *)AXIS2_MALLOC(env->allocator, sizeof(guththila_t)); - guththila_init(guththila, guththila_impl->reader, env); - if(!guththila) + if(guththila_init(guththila, reader, env) != GUTHTHILA_SUCCESS) { AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_FREE(env->allocator, guththila); + guththila_reader_free(reader, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Guththila initialization failed"); return NULL; } guththila_impl->guththila_parser = guththila; - guththila_impl->context = NULL; - guththila_impl->parser.ops = NULL; - /* guththila_impl->parser.ops = - (axiom_xml_reader_ops_t *) AXIS2_MALLOC(env->allocator, - sizeof(axiom_xml_reader_ops_t)); - if (!(guththila_impl->parser.ops)) - { - guththila_free(guththila, env); - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - */ + guththila_impl->reader = reader; + guththila_impl->context = ctx; guththila_xml_reader_wrapper_init_map(guththila_impl); - - /************** ops *****/ guththila_impl->parser.ops = &axiom_xml_reader_ops_var; return &(guththila_impl->parser); } -/****** pull parser for io create function ***************************/ +AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL +axiom_xml_reader_create_for_file( + const axutil_env_t * env, + char *filename, + const axis2_char_t * encoding) +{ + guththila_reader_t *reader = guththila_reader_create_for_file(filename, env); + return axiom_xml_reader_create_basic(env, reader, NULL); +} axiom_xml_reader_t *AXIS2_CALL axiom_xml_reader_create_for_io( @@ -254,62 +270,22 @@ axiom_xml_reader_create_for_io( void *ctx, const char *encoding) { - guththila_xml_reader_wrapper_impl_t *guththila_impl = NULL; - /*axutil_allocator_t *allocator = NULL; */ - guththila_t *guththila = NULL; - - AXIS2_ENV_CHECK(env, NULL); - - guththila_impl = AXIS2_MALLOC(env->allocator, sizeof(guththila_xml_reader_wrapper_impl_t)); - - if(!guththila_impl) - { - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - /*allocator = axutil_allocator_init(NULL); */ - - /*-------difference of two create function is here--------*/ - guththila_impl->reader = guththila_reader_create_for_io(read_input_callback, ctx, env); - - if(!(guththila_impl->reader)) - { - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - guththila = (guththila_t *)AXIS2_MALLOC(env->allocator, sizeof(guththila_t)); - guththila_init(guththila, guththila_impl->reader, env); - if(!guththila) - { - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - guththila_impl->guththila_parser = guththila; - guththila_impl->context = ctx; - guththila_impl->parser.ops = NULL; - /* guththila_impl->parser.ops = (axiom_xml_reader_ops_t *) - AXIS2_MALLOC(env->allocator, sizeof(axiom_xml_reader_ops_t)); - if (!(guththila_impl->parser.ops)) - { - guththila_free(guththila, env); - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - }*/ - - guththila_xml_reader_wrapper_init_map(guththila_impl); + guththila_reader_t *reader = guththila_reader_create_for_io(read_input_callback, ctx, env); + return axiom_xml_reader_create_basic(env, reader, ctx); +} - /************** ops *****/ - guththila_impl->parser.ops = &axiom_xml_reader_ops_var; - return &(guththila_impl->parser); +AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL +axiom_xml_reader_create_for_memory( + const axutil_env_t * env, + void *buffer, + int size, + const char *encoding, + int type) +{ + guththila_reader_t *reader = guththila_reader_create_for_memory(buffer, size, env); + return axiom_xml_reader_create_basic(env, reader, NULL); } -/* ####################################################################### */ AXIS2_EXTERN axis2_status_t AXIS2_CALL axiom_xml_reader_init() { @@ -322,78 +298,12 @@ axiom_xml_reader_cleanup() return AXIS2_SUCCESS; } -/* ######################################################################## */ - -AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL -axiom_xml_reader_create_for_memory( - const axutil_env_t * env, - void *buffer, - int size, - const char *encoding, - int type) -{ - guththila_xml_reader_wrapper_impl_t *guththila_impl = NULL; - /*axutil_allocator_t *allocator = NULL; */ - guththila_t *guththila = NULL; - - AXIS2_ENV_CHECK(env, NULL); - - guththila_impl = AXIS2_MALLOC(env->allocator, sizeof(guththila_xml_reader_wrapper_impl_t)); - - if(!guththila_impl) - { - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - /*allocator = axutil_allocator_init(NULL); */ - - /*-------difference of two create function is here--------*/ - guththila_impl->reader = guththila_reader_create_for_memory(buffer, size, env); - - if(!(guththila_impl->reader)) - { - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - guththila = (guththila_t *)AXIS2_MALLOC(env->allocator, sizeof(guththila_t)); - guththila_init(guththila, guththila_impl->reader, env); - if(!guththila) - { - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - guththila_impl->guththila_parser = guththila; - guththila_impl->context = NULL; - guththila_impl->parser.ops = NULL; - /* guththila_impl->parser.ops = (axiom_xml_reader_ops_t *) - AXIS2_MALLOC(env->allocator, sizeof(axiom_xml_reader_ops_t)); - if (!(guththila_impl->parser.ops)) - { - guththila_free(guththila, env); - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - */ - guththila_xml_reader_wrapper_init_map(guththila_impl); - - /************** ops *****/ - guththila_impl->parser.ops = &axiom_xml_reader_ops_var; - return &(guththila_impl->parser); -} - int AXIS2_CALL guththila_xml_reader_wrapper_next( axiom_xml_reader_t * parser, const axutil_env_t * env) { int i = -1; - AXIS2_ENV_CHECK(env, -1); i = guththila_next(AXIS2_INTF_TO_IMPL(parser)->guththila_parser, env); return i == -1 ? -1 : AXIS2_INTF_TO_IMPL(parser)->event_map[i]; } @@ -404,7 +314,6 @@ guththila_xml_reader_wrapper_free( const axutil_env_t * env) { guththila_xml_reader_wrapper_impl_t *parser_impl = NULL; - AXIS2_ENV_CHECK(env, AXIS2_FAILURE); parser_impl = AXIS2_INTF_TO_IMPL(parser); if(parser_impl->reader) { @@ -424,7 +333,6 @@ guththila_xml_reader_wrapper_get_attribute_count( axiom_xml_reader_t * parser, const axutil_env_t * env) { - AXIS2_ENV_CHECK(env, AXIS2_FAILURE); return guththila_get_attribute_count(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, env); } @@ -434,9 +342,8 @@ guththila_xml_reader_wrapper_get_attribute_name_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); - return guththila_get_attribute_name_by_number(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, - env); + return guththila_get_attribute_name_by_number( + AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } axis2_char_t *AXIS2_CALL @@ -445,9 +352,8 @@ guththila_xml_reader_wrapper_get_attribute_prefix_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); - return guththila_get_attribute_prefix_by_number(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, - i, env); + return guththila_get_attribute_prefix_by_number( + AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } axis2_char_t *AXIS2_CALL @@ -456,9 +362,8 @@ guththila_xml_reader_wrapper_get_attribute_value_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); - return guththila_get_attribute_value_by_number(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, - i, env); + return guththila_get_attribute_value_by_number( + AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } axis2_char_t *AXIS2_CALL @@ -467,7 +372,6 @@ guththila_xml_reader_wrapper_get_attribute_namespace_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); return guththila_get_attribute_namespace_by_number( AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } @@ -477,7 +381,6 @@ guththila_xml_reader_wrapper_get_value( axiom_xml_reader_t * parser, const axutil_env_t * env) { - AXIS2_ENV_CHECK(env, NULL); return guththila_get_value(AXIS2_INTF_TO_IMPL(parser)->guththila_parser, env); } @@ -486,7 +389,6 @@ guththila_xml_reader_wrapper_get_namespace_count( axiom_xml_reader_t * parser, const axutil_env_t * env) { - AXIS2_ENV_CHECK(env, AXIS2_FAILURE); return guththila_get_namespace_count(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, env); } @@ -496,9 +398,8 @@ guththila_xml_reader_wrapper_get_namespace_uri_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); - return guththila_get_namespace_uri_by_number(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, - env); + return guththila_get_namespace_uri_by_number( + AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } axis2_char_t *AXIS2_CALL @@ -507,9 +408,8 @@ guththila_xml_reader_wrapper_get_namespace_prefix_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); - return guththila_get_namespace_prefix_by_number(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, - i, env); + return guththila_get_namespace_prefix_by_number( + AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } axis2_char_t *AXIS2_CALL @@ -517,7 +417,6 @@ guththila_xml_reader_wrapper_get_prefix( axiom_xml_reader_t * parser, const axutil_env_t * env) { - AXIS2_ENV_CHECK(env, NULL); return guththila_get_prefix(AXIS2_INTF_TO_IMPL(parser)->guththila_parser, env); } @@ -526,7 +425,6 @@ guththila_xml_reader_wrapper_get_name( axiom_xml_reader_t * parser, const axutil_env_t * env) { - AXIS2_ENV_CHECK(env, NULL); return guththila_get_name(AXIS2_INTF_TO_IMPL(parser)->guththila_parser, env); } |