You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@axis.apache.org by Nabeel <na...@wso2.com> on 2006/04/18 13:23:42 UTC

[Axis2] Patch - new functions to libxml2 wrapper

The patch contains -
a new reader that reads a xmlDoc
a new writer that writes to a xmlDoc

(these methods are used by the php extension to prevent double 
serialization when exchanging XML)

Please apply to svn.

thanks
-Nabeel

Re: Patch - new functions to libxml2 wrapper

Posted by nandika jayawardana <ja...@gmail.com>.
it is appropriate to change axis2_xml_reader_create_for_buffer
function name to axis2_xml_reader_create_for_memory since we use a
memory buffer . Then we need to change the name of the existing
axis2_xml_reader_create_for_memory function name.
I think we should name it as axis2_xml_reader_create_for_io(....) .

I think it will not be much work to refactor the code.

Thanks

nandika

On 4/19/06, Nabeel <na...@wso2.com> wrote:
> Having considered all the replies, the following changes will sort out
> most of the concerns.
>
> writer
> ======
> new attributes to impl struct:
> int type;
> xmlDocPtr *docp;
>
> Original:
> AXIS2_DECLARE(axis2_xml_writer_t *)
> axis2_xml_writer_create_for_memory(axis2_env_t **env,
>                                    axis2_char_t *encoding,
>                                    int is_prefix_default,
>                                    int compression);
>
> Modified:
> AXIS2_DECLARE(axis2_xml_writer_t *)
> axis2_xml_writer_create_for_memory(axis2_env_t **env,
>                                    axis2_char_t *encoding,
>                                    int is_prefix_default,
>                                    int compression,
>                     int type);
>
>
>
> Original:
> axis2_char_t* AXIS2_CALL
> axis2_libxml2_writer_wrapper_get_xml(axis2_xml_writer_t *writer,
>                                      axis2_env_t **env);
>
> Modified:
> void* AXIS2_CALL
> axis2_libxml2_writer_wrapper_get_xml(axis2_xml_writer_t *writer,
>                                      axis2_env_t **env);
>
>
> Reader
> ======
> Original:
> AXIS2_DECLARE(axis2_xml_reader_t *)
> axis2_xml_reader_create_for_buffer(axis2_env_t **env,
>                                   const axis2_char_t *buffer,
>                                   int size,
>                                   const axis2_char_t *encoding);
>
> Modified:
> AXIS2_DECLARE(axis2_xml_reader_t *)
> axis2_xml_reader_create_for_buffer(axis2_env_t **env,
>                                   void *container,
>                                   int size,
>                                   const axis2_char_t *encoding,
>                   int type);
>
> Note: method name should ideally be axis2_xml_reader_create_for_memory.
> Since we already have a method with the same name, need to check with
> Nandika to see how difficult it is to refactor.
>
> -Nabeel
>
>
> Samisa Abeysinghe wrote:
>
> > OK, So nabeel want to create the reader/writer in a different manner.
> > If that is the case, why not keep more or less the same API and add an
> > optinal thir parameter (or a variable param list) to the create_for
> > memory method of reader/writer?
> > This way, the impl details will be hidden from the user, and we could
> > have the same API, wont cause problems raised by Sahan.
> > Samisa...
> >
> > Sahan Gamage wrote:
> >
> >> Hi Nabeel,
> >>
> >> Pls see my inline comments.
> >>
> >> Nabeel wrote:
> >>
> >>
> >>
> >>> Sahan Gamage wrote:
> >>>
> >>>
> >>>
> >>>> Hi Nabeel,
> >>>>
> >>>> What is this xmlDoc ? Is it libxml2 thing ? If so aren't we adding a
> >>>> hard binding to Axis2C with libxml2 ?
> >>>>
> >>>>
> >>>>
> >>>
> >>>   Yes, xmlDoc is libxml2 specific. But xmlDoc is hidden inside the
> >>> impls of the libxml2 wrapper to prevent hard binding.  (if you have a
> >>> look at the public interfaces axis2_xml_reader.h and
> >>> axis2_xml_writer.h you won't find any xmlDoc pointers)
> >>>
> >>
> >>
> >> Yes. I saw that. But the problem is where are you going to use it ? At
> >> the point you are using these functions, say foo()is something similar
> >> to this:
> >>
> >> void foo()
> >> {
> >>    xmlDoc *doc = get_by_some_way();
> >>    axis2_xml_reader_t *reader = NULL;
> >>    ...
> >>    reader = axis2_xml_reader_create_for_xml_doc(env, doc);
> >>    ...
> >> }
> >> This code is pretty dependent on libxml2. So if this is for code for
> >> axis2 as soon as we change the parser (to guththila or to any other pull
> >> parser) the code will break unless we add a hard link dependancy for
> >> libxml2. Isn't it ?
> >>
> >>
> >>
> >>>    Only catch is that the new functions are useful only when you are
> >>> using libxml2. If you are using some other xml parser library,
> >>> Guththila for example, you may not want to implement these new
> >>> prototypes in your wrapper.
> >>>
> >>
> >>
> >> My understanding is that wrpper is an interface to the common
> >> functionality that every library that it wraps, can provide. So if
> >> guththila can't provide this functionality we are breaking the rules of
> >> wrapper. And the worst thing is we are exposing these libxml2 specific
> >> stuff to the outside world by putting it to the public headers
> >> axis2_xml_reader.h and axis2_xml_writer.h
> >>
> >>
> >>
> >>> thanks
> >>> -Nabeel
> >>>
> >>>
> >>>
> >>>> IMHO the wrapper is there to hide implemention specific (in this case
> >>>> libxml2) details. If we expose the libxml2 things in the wrapper, the
> >>>> idea of the wrapper is not there any more. Please clarify
> >>>>
> >>>> - Sahan
> >>>>
> >>>> Nabeel wrote:
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>> The patch contains -
> >>>>> a new reader that reads a xmlDoc
> >>>>> a new writer that writes to a xmlDoc
> >>>>>
> >>>>> (these methods are used by the php extension to prevent double
> >>>>> serialization when exchanging XML)
> >>>>>
> >>>>> Please apply to svn.
> >>>>>
> >>>>> thanks
> >>>>> -Nabeel
> >>>>>
> >>>>>
> ------------------------------------------------------------------------
> >>>>>
> >>>>>
> >>>>>
> >>>>> Index: modules/xml/parser/libxml2/libxml2_writer_wrapper.c
> >>>>> ===================================================================
> >>>>> --- modules/xml/parser/libxml2/libxml2_writer_wrapper.c    (revision
> >>>>> 394906)
> >>>>> +++ modules/xml/parser/libxml2/libxml2_writer_wrapper.c    (working
> >>>>> copy)
> >>>>> @@ -34,6 +34,7 @@
> >>>>>
> >>>>> #define AXIS2_LIBXML2_WRITER_MEMORY 1
> >>>>> #define AXIS2_LIBXML2_WRITER_FILE   2
> >>>>> +#define AXIS2_LIBXML2_WRITER_DOC    3
> >>>>>
> >>>>> /************************ structures
> >>>>> *****************************************/
> >>>>>
> >>>>> @@ -56,6 +57,8 @@
> >>>>>   xmlTextWriterPtr xml_writer;
> >>>>>      xmlBufferPtr buffer;
> >>>>> +
> >>>>> +    xmlDocPtr doc;
> >>>>>      int writer_type;
> >>>>>   @@ -262,6 +265,10 @@
> >>>>> axis2_char_t* AXIS2_CALL
> >>>>> axis2_libxml2_writer_wrapper_get_xml(axis2_xml_writer_t *writer,
> >>>>>                                    axis2_env_t **env);
> >>>>> +
> >>>>> +void* AXIS2_CALL
> >>>>> +axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
> >>>>> +                                                axis2_env_t **env);
> >>>>>                                    /*********************** static
> >>>>> functions ************************************/
> >>>>> static axis2_status_t
> >>>>> @@ -658,6 +665,180 @@
> >>>>>   return &(writer_impl->writer);
> >>>>> }
> >>>>>
> >>>>> +/*********************** writer create func for file
> >>>>> ***************************/
> >>>>> +
> >>>>> +AXIS2_DECLARE(axis2_xml_writer_t *)
> >>>>> +axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
> >>>>> +                                   axis2_char_t *encoding,
> >>>>> +                                   int is_prefix_default,
> >>>>> +                                   int compression)
> >>>>> +{
> >>>>> +    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
> >>>>> +    AXIS2_ENV_CHECK(env, NULL);
> >>>>> +    writer_impl = (axis2_libxml2_writer_wrapper_impl_t
> >>>>> *)AXIS2_MALLOC((*env)->allocator,
> >>>>> +                   sizeof(axis2_libxml2_writer_wrapper_impl_t));
> >>>>> +    if(!writer_impl)
> >>>>> +    {
> >>>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
> >>>>> AXIS2_FAILURE);
> >>>>> +        return NULL;
> >>>>> +    }
> >>>>> +    +    writer_impl->writer.ops = NULL;
> >>>>> +    writer_impl->encoding = NULL;
> >>>>> +    writer_impl->buffer = NULL;
> >>>>> +    writer_impl->in_empty_element = AXIS2_FALSE;
> >>>>> +    writer_impl->in_start_element = AXIS2_FALSE;
> >>>>> +    writer_impl->stack = NULL;
> >>>>> +    writer_impl->uri_prefix_map = NULL;
> >>>>> +    writer_impl->default_lang_namespace = NULL;
> >>>>> +    +    writer_impl->writer_type = AXIS2_LIBXML2_WRITER_DOC;
> >>>>> +    writer_impl->compression = compression;
> >>>>> +    +    +    /*writer_impl->buffer = xmlBufferCreate();
> >>>>> +    if(writer_impl->buffer == NULL)
> >>>>> +    {
> >>>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
> >>>>> env);
> >>>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
> >>>>> AXIS2_FAILURE);
> >>>>> +        return NULL;
> >>>>> +    }*/
> >>>>> +    +    writer_impl->xml_writer =
> >>>>> /*xmlNewTextWriterMemory(writer_impl->buffer, 0);*/
> >>>>> +
> >>>>> xmlNewTextWriterDoc(&writer_impl->doc, 0);
> >>>>> +    if(writer_impl->xml_writer == NULL)
> >>>>> +    {
> >>>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
> >>>>> env);
> >>>>> +        AXIS2_ERROR_SET((*env)->error,
> >>>>> AXIS2_ERROR_CREATING_XML_STREAM_WRITER , AXIS2_FAILURE);
> >>>>> +        return NULL;
> >>>>> +    }
> >>>>> +
> >>>>> +     if(encoding)
> >>>>> +        writer_impl->encoding = AXIS2_STRDUP(encoding , env);
> >>>>> +    else
> >>>>> +        writer_impl->encoding = AXIS2_STRDUP(ENCODING, env);
> >>>>> +     +    +    writer_impl->uri_prefix_map = axis2_hash_make(env);
> >>>>> +    if(!(writer_impl->uri_prefix_map))
> >>>>> +    {
> >>>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
> >>>>> env);
> >>>>> +        AXIS2_ERROR_SET((*env)->error, +
> >>>>> AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
> >>>>> +        +        return NULL;
> >>>>> +    }
> >>>>> +    writer_impl->stack = axis2_stack_create(env);
> >>>>> +    if(!(writer_impl->stack))
> >>>>> +    {
> >>>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
> >>>>> env);
> >>>>> +        AXIS2_ERROR_SET((*env)->error, +
> >>>>> AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
> >>>>> +        return NULL;
> >>>>> +    }
> >>>>> +    +
> >>>>>
> axis2_libxml2_writer_wrapper_set_default_lang_namespace(&(writer_impl->writer),
> >>>>>
> >>>>> env);
> >>>>> +    +    writer_impl->writer.ops =
> >>>>> (axis2_xml_writer_ops_t*)AXIS2_MALLOC((*env)->allocator,
> >>>>> +                                    sizeof(axis2_xml_writer_ops_t));
> >>>>> +    if(!(writer_impl->writer.ops))
> >>>>> +    {
> >>>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
> >>>>> env);
> >>>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
> >>>>> AXIS2_FAILURE);
> >>>>> +        return NULL;
> >>>>> +    }
> >>>>> +    +    /* ops */
> >>>>> +    writer_impl->writer.ops->free = +
> >>>>> axis2_libxml2_writer_wrapper_free;
> >>>>> +            +    writer_impl->writer.ops->write_start_element =
> >>>>> +            axis2_libxml2_writer_wrapper_write_start_element;
> >>>>> +            +
> >>>>> writer_impl->writer.ops->write_start_element_with_namespace =
> >>>>> +
> >>>>> axis2_libxml2_writer_wrapper_write_start_element_with_namespace;
> >>>>> +            +
> >>>>> writer_impl->writer.ops->write_start_element_with_namespace_prefix =
> >>>>> +
> >>>>>
> axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix;
> >>>>>
> >>>>> +    +    writer_impl->writer.ops->write_empty_element =
> >>>>> +            axis2_libxml2_writer_wrapper_write_empty_element;
> >>>>> +            +
> >>>>> writer_impl->writer.ops->write_empty_element_with_namespace  =
> >>>>> +
> >>>>> axis2_libxml2_writer_wrapper_write_empty_element_with_namespace;
> >>>>> +            +
> >>>>> writer_impl->writer.ops->write_empty_element_with_namespace_prefix =
> >>>>> +
> >>>>>
> axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix;
> >>>>>
> >>>>> +    +    writer_impl->writer.ops->write_end_element = +
> >>>>> axis2_libxml2_writer_wrapper_write_end_element;
> >>>>> +            +    writer_impl->writer.ops->write_end_document =
> >>>>> +            axis2_libxml2_writer_wrapper_write_end_document;
> >>>>> +    +    writer_impl->writer.ops->write_attribute = +
> >>>>> axis2_libxml2_writer_wrapper_write_attribute;
> >>>>> +            +
> >>>>> writer_impl->writer.ops->write_attribute_with_namespace =
> >>>>> +
> >>>>> axis2_libxml2_writer_wrapper_write_attribute_with_namespace;
> >>>>> +            +
> >>>>> writer_impl->writer.ops->write_attribute_with_namespace_prefix =
> >>>>> +
> >>>>> axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix;
> >>>>> +            +    writer_impl->writer.ops->write_namespace =
> >>>>> +            axis2_libxml2_writer_wrapper_write_namespace;
> >>>>> +            +    writer_impl->writer.ops->write_default_namespace =
> >>>>> +            axis2_libxml2_writer_wrapper_write_default_namespace;
> >>>>> +            +    writer_impl->writer.ops->write_comment =
> >>>>> +            axis2_libxml2_writer_wrapper_write_comment;
> >>>>> +            +
> >>>>> writer_impl->writer.ops->write_processing_instruction =
> >>>>> +
> >>>>> axis2_libxml2_writer_wrapper_write_processing_instruction;
> >>>>> +            +
> >>>>> writer_impl->writer.ops->write_processing_instruction_data =
> >>>>> +
> >>>>> axis2_libxml2_writer_wrapper_write_processing_instruction_data;
> >>>>> +            +    writer_impl->writer.ops->write_cdata =
> >>>>> +            axis2_libxml2_writer_wrapper_write_cdata;
> >>>>> +            +    writer_impl->writer.ops->write_dtd = +
> >>>>> axis2_libxml2_writer_wrapper_write_dtd;
> >>>>> +            +    writer_impl->writer.ops->write_entity_ref =
> >>>>> +            axis2_libxml2_writer_wrapper_write_entity_ref;
> >>>>> +            +    writer_impl->writer.ops->write_start_document =
> >>>>> +            axis2_libxml2_writer_wrapper_write_start_document;
> >>>>> +            +
> >>>>> writer_impl->writer.ops->write_start_document_with_version =
> >>>>> +
> >>>>> axis2_libxml2_writer_wrapper_write_start_document_with_version;
> >>>>> +            +
> >>>>> writer_impl->writer.ops->write_start_document_with_version_encoding
> >>>>> = +
> >>>>>
> axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding;
> >>>>>
> >>>>>
> >>>>> +            +    writer_impl->writer.ops->write_characters =
> >>>>> +            axis2_libxml2_writer_wrapper_write_characters;
> >>>>> +            +    writer_impl->writer.ops->get_prefix =
> >>>>> +            axis2_libxml2_writer_wrapper_get_prefix;
> >>>>> +            +    writer_impl->writer.ops->set_prefix =
> >>>>> +           axis2_libxml2_writer_wrapper_set_prefix;
> >>>>> +            +    writer_impl->writer.ops->set_default_prefix =
> >>>>> +            axis2_libxml2_writer_wrapper_set_default_prefix;
> >>>>> +            +    writer_impl->writer.ops->write_encoded =
> >>>>> +            axis2_libxml2_writer_wrapper_write_encoded;
> >>>>> +            +    writer_impl->writer.ops->get_xml =
> >>>>> +            axis2_libxml2_writer_wrapper_get_xml_doc;
> >>>>> +                             +    return &(writer_impl->writer);
> >>>>> +}
> >>>>> +
> >>>>>
> /*******************************************************************************/
> >>>>>
> >>>>>
> >>>>> axis2_status_t AXIS2_CALL
> >>>>> axis2_libxml2_writer_wrapper_free(axis2_xml_writer_t *writer,
> >>>>> @@ -1561,6 +1742,26 @@
> >>>>>   return output;   }
> >>>>>
> >>>>> +void* AXIS2_CALL
> >>>>> +axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
> >>>>> +                                        axis2_env_t **env)
> >>>>> +{
> >>>>> +    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
> >>>>> +    writer_impl = AXIS2_INTF_TO_IMPL(writer);
> >>>>> +
> >>>>> +    if(writer_impl->xml_writer)
> >>>>> +    {
> >>>>> +        xmlFreeTextWriter(writer_impl->xml_writer);
> >>>>> +        writer_impl->xml_writer = NULL;
> >>>>> +    }
> >>>>> +
> >>>>> +    if (writer_impl->writer_type == AXIS2_LIBXML2_WRITER_DOC)
> >>>>> +    {
> >>>>> +        return (void*)writer_impl->doc;
> >>>>> +    }
> >>>>> +    return NULL;
> >>>>> +}
> >>>>> +
> >>>>> static axis2_status_t
> >>>>> axis2_libxml2_writer_wrapper_pop_context(axis2_xml_writer_t *writer,
> >>>>>                                        axis2_env_t **env)
> >>>>> Index: modules/xml/parser/libxml2/libxml2_reader_wrapper.c
> >>>>> ===================================================================
> >>>>> --- modules/xml/parser/libxml2/libxml2_reader_wrapper.c    (revision
> >>>>> 394906)
> >>>>> +++ modules/xml/parser/libxml2/libxml2_reader_wrapper.c    (working
> >>>>> copy)
> >>>>> @@ -555,6 +555,102 @@
> >>>>>                               return &(wrapper_impl->parser);
> >>>>> }
> >>>>> +
> >>>>> +
> >>>>> +/***************** create function for xmlDoc
> >>>>> ************************/
> >>>>> +AXIS2_DECLARE(axis2_xml_reader_t *)
> >>>>> +axis2_xml_reader_create_for_xml_doc(axis2_env_t **env,
> >>>>> +                                    void *doc)
> >>>>> +{    +    axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL;
> >>>>> +    +    AXIS2_ENV_CHECK( env, NULL);
> >>>>> +        +    wrapper_impl =
> >>>>> (axis2_libxml2_reader_wrapper_impl_t*)AXIS2_MALLOC((*env)->allocator,
> >>>>> +         sizeof(axis2_libxml2_reader_wrapper_impl_t));
> >>>>> +    if(!wrapper_impl)
> >>>>> +    {
> >>>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
> >>>>> AXIS2_FAILURE);
> >>>>> +        return NULL;   +    }
> >>>>> +    wrapper_impl->close_input_callback = NULL;
> >>>>> +    wrapper_impl->read_input_callback = NULL;
> >>>>> +    wrapper_impl->ctx = NULL;
> >>>>> +   +    wrapper_impl->reader =  xmlReaderWalker((xmlDocPtr)doc);
> >>>>> +
> >>>>> +    if(!(wrapper_impl->reader))
> >>>>> +    {
> >>>>> +        AXIS2_FREE((*env)->allocator, wrapper_impl);
> >>>>> +        AXIS2_ERROR_SET((*env)->error, +
> >>>>> AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE);
> >>>>> +        return NULL;
> >>>>> +    }
> >>>>> +
> >>>>> +    /*xmlTextReaderSetErrorHandler(wrapper_impl->reader, +
> >>>>> (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler,
> >>>>> +         (*env));
> >>>>> +    */
> >>>>> +    wrapper_impl->current_event = -1;
> >>>>> +    +    axis2_libxml2_reader_wrapper_init_map(wrapper_impl);
> >>>>> +    +    wrapper_impl->parser.ops = NULL;
> >>>>> +    wrapper_impl->parser.ops =
> >>>>> (axis2_xml_reader_ops_t*)AXIS2_MALLOC((*env)->allocator,
> >>>>> +                                sizeof(axis2_xml_reader_ops_t));
> >>>>> +    +    if(!(wrapper_impl->parser.ops))
> >>>>> +    {
> >>>>> +        xmlFreeTextReader(wrapper_impl->reader);
> >>>>> +        AXIS2_FREE((*env)->allocator, wrapper_impl);
> >>>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
> >>>>> AXIS2_FAILURE);
> >>>>> +        return NULL;
> >>>>> +    }
> >>>>> +
> >>>>> +   +    wrapper_impl->parser.ops->free =
> >>>>> axis2_libxml2_reader_wrapper_free;
> >>>>> +    wrapper_impl->parser.ops->next =
> >>>>> axis2_libxml2_reader_wrapper_next;
> >>>>> +    wrapper_impl->parser.ops->xml_free =
> >>>>> axis2_libxml2_reader_wrapper_xml_free;
> >>>>> +    +    wrapper_impl->parser.ops->get_attribute_count =
> >>>>> +        axis2_libxml2_reader_wrapper_get_attribute_count;
> >>>>> +    wrapper_impl->parser.ops->get_attribute_name_by_number =
> >>>>> +        axis2_libxml2_reader_wrapper_get_attribute_name_by_number;
> >>>>> +    wrapper_impl->parser.ops->get_attribute_value_by_number =
> >>>>> +        axis2_libxml2_reader_wrapper_get_attribute_value_by_number;
> >>>>> +    wrapper_impl->parser.ops->get_attribute_namespace_by_number =
> >>>>> +
> >>>>> axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number;
> >>>>> +    wrapper_impl->parser.ops->get_attribute_prefix_by_number =
> >>>>> +        axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number;
> >>>>> +    +    wrapper_impl->parser.ops->get_value =
> >>>>> +        axis2_libxml2_reader_wrapper_get_value;
> >>>>> +    wrapper_impl->parser.ops->get_prefix =
> >>>>> +        axis2_libxml2_reader_wrapper_get_prefix;
> >>>>> +    wrapper_impl->parser.ops->get_name =
> >>>>> +        axis2_libxml2_reader_wrapper_get_name;
> >>>>> +        +        +
> >>>>> wrapper_impl->parser.ops->get_namespace_count =
> >>>>> +        axis2_libxml2_reader_wrapper_get_namespace_count;
> >>>>> +    wrapper_impl->parser.ops->get_namespace_prefix_by_number =
> >>>>> +        axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number;
> >>>>> +    wrapper_impl->parser.ops->get_namespace_uri_by_number =
> >>>>> +        axis2_libxml2_reader_wrapper_get_namespace_uri_by_number;
> >>>>> +        +    wrapper_impl->parser.ops->get_pi_target =
> >>>>> +        axis2_libxml2_reader_wrapper_get_pi_target;
> >>>>> +    wrapper_impl->parser.ops->get_pi_data =
> >>>>> +        axis2_libxml2_reader_wrapper_get_pi_data;
> >>>>> +        +    wrapper_impl->parser.ops->get_dtd =
> >>>>> +        axis2_libxml2_reader_wrapper_get_dtd;
> >>>>> +        +    wrapper_impl->parser.ops->get_char_set_encoding =
> >>>>> +        axis2_libxml2_reader_wrapper_get_char_set_encoding;
> >>>>> +
> >>>>> +    return &(wrapper_impl->parser);
> >>>>> +}
> >>>>> /****************** end create functions
> >>>>> ***************************************/
> >>>>>
> >>>>> int AXIS2_CALL
> >>>>> Index: include/axis2_xml_reader.h
> >>>>> ===================================================================
> >>>>> --- include/axis2_xml_reader.h    (revision 394906)
> >>>>> +++ include/axis2_xml_reader.h    (working copy)
> >>>>> @@ -355,6 +355,9 @@
> >>>>>                                 int size,
> >>>>>                                 const axis2_char_t *encoding);
> >>>>>
> >>>>> +AXIS2_DECLARE(axis2_xml_reader_t *)
> >>>>> +axis2_xml_reader_create_for_xml_doc(axis2_env_t **env,
> >>>>> +                                    void *doc);   /**
> >>>>> * init function initializes the parser */
> >>>>> Index: include/axis2_xml_writer.h
> >>>>> ===================================================================
> >>>>> --- include/axis2_xml_writer.h    (revision 394906)
> >>>>> +++ include/axis2_xml_writer.h    (working copy)
> >>>>> @@ -464,6 +464,12 @@
> >>>>>                                  int is_prefix_default,
> >>>>>                                  int compression);
> >>>>>
> >>>>> +AXIS2_DECLARE(axis2_xml_writer_t *)
> >>>>> +    axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
> >>>>> +                                   axis2_char_t *encoding,
> >>>>> +                                   int is_prefix_default,
> >>>>> +                                   int compression);
> >>>>> +   /********************** start macros
> >>>>> *******************************************/
> >>>>>
> >>>>> #define AXIS2_XML_WRITER_FREE(writer, env) \
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> >>
> >>
> >>
> >>
> >>
> >
> >
>
>

Re: [Axis2] Patch - new functions to libxml2 wrapper

Posted by Nabeel <na...@wso2.com>.
Having considered all the replies, the following changes will sort out 
most of the concerns.

writer
======
new attributes to impl struct:
int type;
xmlDocPtr *docp;

Original:
AXIS2_DECLARE(axis2_xml_writer_t *)
axis2_xml_writer_create_for_memory(axis2_env_t **env,
                                   axis2_char_t *encoding,
                                   int is_prefix_default,
                                   int compression);

Modified:
AXIS2_DECLARE(axis2_xml_writer_t *)
axis2_xml_writer_create_for_memory(axis2_env_t **env,
                                   axis2_char_t *encoding,
                                   int is_prefix_default,
                                   int compression,
                    int type);



Original:
axis2_char_t* AXIS2_CALL
axis2_libxml2_writer_wrapper_get_xml(axis2_xml_writer_t *writer,
                                     axis2_env_t **env);

Modified:
void* AXIS2_CALL
axis2_libxml2_writer_wrapper_get_xml(axis2_xml_writer_t *writer,
                                     axis2_env_t **env);


Reader
======
Original:
AXIS2_DECLARE(axis2_xml_reader_t *)
axis2_xml_reader_create_for_buffer(axis2_env_t **env,
                                  const axis2_char_t *buffer,
                                  int size,
                                  const axis2_char_t *encoding);

Modified:
AXIS2_DECLARE(axis2_xml_reader_t *)
axis2_xml_reader_create_for_buffer(axis2_env_t **env,
                                  void *container,
                                  int size,
                                  const axis2_char_t *encoding,
                  int type);

Note: method name should ideally be axis2_xml_reader_create_for_memory. 
Since we already have a method with the same name, need to check with 
Nandika to see how difficult it is to refactor.

-Nabeel


Samisa Abeysinghe wrote:

> OK, So nabeel want to create the reader/writer in a different manner.
> If that is the case, why not keep more or less the same API and add an 
> optinal thir parameter (or a variable param list) to the create_for 
> memory method of reader/writer?
> This way, the impl details will be hidden from the user, and we could 
> have the same API, wont cause problems raised by Sahan.
> Samisa...
>
> Sahan Gamage wrote:
>
>> Hi Nabeel,
>>
>> Pls see my inline comments.
>>
>> Nabeel wrote:
>>
>>  
>>
>>> Sahan Gamage wrote:
>>>
>>>   
>>>
>>>> Hi Nabeel,
>>>>
>>>> What is this xmlDoc ? Is it libxml2 thing ? If so aren't we adding a
>>>> hard binding to Axis2C with libxml2 ?
>>>>
>>>>
>>>>     
>>>
>>>   Yes, xmlDoc is libxml2 specific. But xmlDoc is hidden inside the
>>> impls of the libxml2 wrapper to prevent hard binding.  (if you have a
>>> look at the public interfaces axis2_xml_reader.h and
>>> axis2_xml_writer.h you won't find any xmlDoc pointers)
>>>   
>>
>>
>> Yes. I saw that. But the problem is where are you going to use it ? At
>> the point you are using these functions, say foo()is something similar
>> to this:
>>
>> void foo()
>> {
>>    xmlDoc *doc = get_by_some_way();
>>    axis2_xml_reader_t *reader = NULL;
>>    ...
>>    reader = axis2_xml_reader_create_for_xml_doc(env, doc);
>>    ...
>> }
>> This code is pretty dependent on libxml2. So if this is for code for
>> axis2 as soon as we change the parser (to guththila or to any other pull
>> parser) the code will break unless we add a hard link dependancy for
>> libxml2. Isn't it ?
>>
>>  
>>
>>>    Only catch is that the new functions are useful only when you are
>>> using libxml2. If you are using some other xml parser library,
>>> Guththila for example, you may not want to implement these new
>>> prototypes in your wrapper.
>>>   
>>
>>
>> My understanding is that wrpper is an interface to the common
>> functionality that every library that it wraps, can provide. So if
>> guththila can't provide this functionality we are breaking the rules of
>> wrapper. And the worst thing is we are exposing these libxml2 specific
>> stuff to the outside world by putting it to the public headers
>> axis2_xml_reader.h and axis2_xml_writer.h
>>
>>  
>>
>>> thanks
>>> -Nabeel
>>>
>>>   
>>>
>>>> IMHO the wrapper is there to hide implemention specific (in this case
>>>> libxml2) details. If we expose the libxml2 things in the wrapper, the
>>>> idea of the wrapper is not there any more. Please clarify
>>>>
>>>> - Sahan
>>>>
>>>> Nabeel wrote:
>>>>
>>>>
>>>>
>>>>     
>>>>
>>>>> The patch contains -
>>>>> a new reader that reads a xmlDoc
>>>>> a new writer that writes to a xmlDoc
>>>>>
>>>>> (these methods are used by the php extension to prevent double
>>>>> serialization when exchanging XML)
>>>>>
>>>>> Please apply to svn.
>>>>>
>>>>> thanks
>>>>> -Nabeel
>>>>>
>>>>> ------------------------------------------------------------------------ 
>>>>>
>>>>>
>>>>>
>>>>> Index: modules/xml/parser/libxml2/libxml2_writer_wrapper.c
>>>>> ===================================================================
>>>>> --- modules/xml/parser/libxml2/libxml2_writer_wrapper.c    (revision
>>>>> 394906)
>>>>> +++ modules/xml/parser/libxml2/libxml2_writer_wrapper.c    (working
>>>>> copy)
>>>>> @@ -34,6 +34,7 @@
>>>>>
>>>>> #define AXIS2_LIBXML2_WRITER_MEMORY 1
>>>>> #define AXIS2_LIBXML2_WRITER_FILE   2
>>>>> +#define AXIS2_LIBXML2_WRITER_DOC    3
>>>>>
>>>>> /************************ structures
>>>>> *****************************************/
>>>>>
>>>>> @@ -56,6 +57,8 @@
>>>>>   xmlTextWriterPtr xml_writer;
>>>>>      xmlBufferPtr buffer;
>>>>> +
>>>>> +    xmlDocPtr doc;
>>>>>      int writer_type;
>>>>>   @@ -262,6 +265,10 @@
>>>>> axis2_char_t* AXIS2_CALL
>>>>> axis2_libxml2_writer_wrapper_get_xml(axis2_xml_writer_t *writer,
>>>>>                                    axis2_env_t **env);
>>>>> +
>>>>> +void* AXIS2_CALL
>>>>> +axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
>>>>> +                                                axis2_env_t **env);
>>>>>                                    /*********************** static
>>>>> functions ************************************/
>>>>> static axis2_status_t
>>>>> @@ -658,6 +665,180 @@
>>>>>   return &(writer_impl->writer);
>>>>> }
>>>>>
>>>>> +/*********************** writer create func for file
>>>>> ***************************/
>>>>> +
>>>>> +AXIS2_DECLARE(axis2_xml_writer_t *)
>>>>> +axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
>>>>> +                                   axis2_char_t *encoding,
>>>>> +                                   int is_prefix_default,
>>>>> +                                   int compression)
>>>>> +{
>>>>> +    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
>>>>> +    AXIS2_ENV_CHECK(env, NULL);
>>>>> +    writer_impl = (axis2_libxml2_writer_wrapper_impl_t
>>>>> *)AXIS2_MALLOC((*env)->allocator,
>>>>> +                   sizeof(axis2_libxml2_writer_wrapper_impl_t));
>>>>> +    if(!writer_impl)
>>>>> +    {
>>>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>>>> AXIS2_FAILURE);
>>>>> +        return NULL;
>>>>> +    }
>>>>> +    +    writer_impl->writer.ops = NULL;
>>>>> +    writer_impl->encoding = NULL;
>>>>> +    writer_impl->buffer = NULL;
>>>>> +    writer_impl->in_empty_element = AXIS2_FALSE;
>>>>> +    writer_impl->in_start_element = AXIS2_FALSE;
>>>>> +    writer_impl->stack = NULL;
>>>>> +    writer_impl->uri_prefix_map = NULL;
>>>>> +    writer_impl->default_lang_namespace = NULL;
>>>>> +    +    writer_impl->writer_type = AXIS2_LIBXML2_WRITER_DOC;
>>>>> +    writer_impl->compression = compression;
>>>>> +    +    +    /*writer_impl->buffer = xmlBufferCreate();
>>>>> +    if(writer_impl->buffer == NULL)
>>>>> +    {
>>>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>>>> env);
>>>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>>>> AXIS2_FAILURE);
>>>>> +        return NULL;
>>>>> +    }*/
>>>>> +    +    writer_impl->xml_writer =
>>>>> /*xmlNewTextWriterMemory(writer_impl->buffer, 0);*/
>>>>> +                               
>>>>> xmlNewTextWriterDoc(&writer_impl->doc, 0);
>>>>> +    if(writer_impl->xml_writer == NULL)
>>>>> +    {
>>>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>>>> env);
>>>>> +        AXIS2_ERROR_SET((*env)->error,
>>>>> AXIS2_ERROR_CREATING_XML_STREAM_WRITER , AXIS2_FAILURE);
>>>>> +        return NULL;
>>>>> +    }
>>>>> +
>>>>> +     if(encoding)
>>>>> +        writer_impl->encoding = AXIS2_STRDUP(encoding , env);
>>>>> +    else
>>>>> +        writer_impl->encoding = AXIS2_STRDUP(ENCODING, env);
>>>>> +     +    +    writer_impl->uri_prefix_map = axis2_hash_make(env);
>>>>> +    if(!(writer_impl->uri_prefix_map))
>>>>> +    {
>>>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>>>> env);
>>>>> +        AXIS2_ERROR_SET((*env)->error, +           
>>>>> AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>>>> +        +        return NULL;
>>>>> +    }
>>>>> +    writer_impl->stack = axis2_stack_create(env);
>>>>> +    if(!(writer_impl->stack))
>>>>> +    {
>>>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>>>> env);
>>>>> +        AXIS2_ERROR_SET((*env)->error, +           
>>>>> AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>>>> +        return NULL;
>>>>> +    }
>>>>> +    +   
>>>>> axis2_libxml2_writer_wrapper_set_default_lang_namespace(&(writer_impl->writer), 
>>>>>
>>>>> env);
>>>>> +    +    writer_impl->writer.ops =
>>>>> (axis2_xml_writer_ops_t*)AXIS2_MALLOC((*env)->allocator,
>>>>> +                                    sizeof(axis2_xml_writer_ops_t));
>>>>> +    if(!(writer_impl->writer.ops))
>>>>> +    {
>>>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>>>> env);
>>>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>>>> AXIS2_FAILURE);
>>>>> +        return NULL;
>>>>> +    }
>>>>> +    +    /* ops */
>>>>> +    writer_impl->writer.ops->free = +           
>>>>> axis2_libxml2_writer_wrapper_free;
>>>>> +            +    writer_impl->writer.ops->write_start_element =
>>>>> +            axis2_libxml2_writer_wrapper_write_start_element;
>>>>> +            +   
>>>>> writer_impl->writer.ops->write_start_element_with_namespace =
>>>>> +           
>>>>> axis2_libxml2_writer_wrapper_write_start_element_with_namespace;
>>>>> +            +   
>>>>> writer_impl->writer.ops->write_start_element_with_namespace_prefix =
>>>>> +           
>>>>> axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix; 
>>>>>
>>>>> +    +    writer_impl->writer.ops->write_empty_element =
>>>>> +            axis2_libxml2_writer_wrapper_write_empty_element;
>>>>> +            +   
>>>>> writer_impl->writer.ops->write_empty_element_with_namespace  =
>>>>> +           
>>>>> axis2_libxml2_writer_wrapper_write_empty_element_with_namespace;
>>>>> +            +   
>>>>> writer_impl->writer.ops->write_empty_element_with_namespace_prefix =
>>>>> +           
>>>>> axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix; 
>>>>>
>>>>> +    +    writer_impl->writer.ops->write_end_element = +           
>>>>> axis2_libxml2_writer_wrapper_write_end_element;
>>>>> +            +    writer_impl->writer.ops->write_end_document =
>>>>> +            axis2_libxml2_writer_wrapper_write_end_document;
>>>>> +    +    writer_impl->writer.ops->write_attribute = +           
>>>>> axis2_libxml2_writer_wrapper_write_attribute;
>>>>> +            +   
>>>>> writer_impl->writer.ops->write_attribute_with_namespace =
>>>>> +           
>>>>> axis2_libxml2_writer_wrapper_write_attribute_with_namespace;
>>>>> +            +   
>>>>> writer_impl->writer.ops->write_attribute_with_namespace_prefix =
>>>>> +           
>>>>> axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix;
>>>>> +            +    writer_impl->writer.ops->write_namespace =
>>>>> +            axis2_libxml2_writer_wrapper_write_namespace;
>>>>> +            +    writer_impl->writer.ops->write_default_namespace =
>>>>> +            axis2_libxml2_writer_wrapper_write_default_namespace;
>>>>> +            +    writer_impl->writer.ops->write_comment =
>>>>> +            axis2_libxml2_writer_wrapper_write_comment;
>>>>> +            +   
>>>>> writer_impl->writer.ops->write_processing_instruction = 
>>>>> +           
>>>>> axis2_libxml2_writer_wrapper_write_processing_instruction;
>>>>> +            +   
>>>>> writer_impl->writer.ops->write_processing_instruction_data =
>>>>> +           
>>>>> axis2_libxml2_writer_wrapper_write_processing_instruction_data;
>>>>> +            +    writer_impl->writer.ops->write_cdata =
>>>>> +            axis2_libxml2_writer_wrapper_write_cdata;
>>>>> +            +    writer_impl->writer.ops->write_dtd = +           
>>>>> axis2_libxml2_writer_wrapper_write_dtd;
>>>>> +            +    writer_impl->writer.ops->write_entity_ref =
>>>>> +            axis2_libxml2_writer_wrapper_write_entity_ref;
>>>>> +            +    writer_impl->writer.ops->write_start_document =
>>>>> +            axis2_libxml2_writer_wrapper_write_start_document;
>>>>> +            +   
>>>>> writer_impl->writer.ops->write_start_document_with_version =
>>>>> +           
>>>>> axis2_libxml2_writer_wrapper_write_start_document_with_version;
>>>>> +            +   
>>>>> writer_impl->writer.ops->write_start_document_with_version_encoding
>>>>> = +           
>>>>> axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding; 
>>>>>
>>>>>
>>>>> +            +    writer_impl->writer.ops->write_characters =
>>>>> +            axis2_libxml2_writer_wrapper_write_characters;
>>>>> +            +    writer_impl->writer.ops->get_prefix =
>>>>> +            axis2_libxml2_writer_wrapper_get_prefix;
>>>>> +            +    writer_impl->writer.ops->set_prefix = 
>>>>> +           axis2_libxml2_writer_wrapper_set_prefix;
>>>>> +            +    writer_impl->writer.ops->set_default_prefix =
>>>>> +            axis2_libxml2_writer_wrapper_set_default_prefix;
>>>>> +            +    writer_impl->writer.ops->write_encoded =
>>>>> +            axis2_libxml2_writer_wrapper_write_encoded;
>>>>> +            +    writer_impl->writer.ops->get_xml =
>>>>> +            axis2_libxml2_writer_wrapper_get_xml_doc;
>>>>> +                             +    return &(writer_impl->writer);
>>>>> +}
>>>>> +
>>>>> /*******************************************************************************/ 
>>>>>
>>>>>
>>>>> axis2_status_t AXIS2_CALL
>>>>> axis2_libxml2_writer_wrapper_free(axis2_xml_writer_t *writer,
>>>>> @@ -1561,6 +1742,26 @@
>>>>>   return output;   }
>>>>>
>>>>> +void* AXIS2_CALL
>>>>> +axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
>>>>> +                                        axis2_env_t **env)
>>>>> +{
>>>>> +    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
>>>>> +    writer_impl = AXIS2_INTF_TO_IMPL(writer);
>>>>> +
>>>>> +    if(writer_impl->xml_writer)
>>>>> +    {
>>>>> +        xmlFreeTextWriter(writer_impl->xml_writer);
>>>>> +        writer_impl->xml_writer = NULL;
>>>>> +    }
>>>>> +
>>>>> +    if (writer_impl->writer_type == AXIS2_LIBXML2_WRITER_DOC)
>>>>> +    {
>>>>> +        return (void*)writer_impl->doc;
>>>>> +    }
>>>>> +    return NULL;
>>>>> +}
>>>>> +
>>>>> static axis2_status_t
>>>>> axis2_libxml2_writer_wrapper_pop_context(axis2_xml_writer_t *writer,
>>>>>                                        axis2_env_t **env)
>>>>> Index: modules/xml/parser/libxml2/libxml2_reader_wrapper.c
>>>>> ===================================================================
>>>>> --- modules/xml/parser/libxml2/libxml2_reader_wrapper.c    (revision
>>>>> 394906)
>>>>> +++ modules/xml/parser/libxml2/libxml2_reader_wrapper.c    (working
>>>>> copy)
>>>>> @@ -555,6 +555,102 @@
>>>>>                               return &(wrapper_impl->parser);
>>>>> }
>>>>> +
>>>>> +
>>>>> +/***************** create function for xmlDoc
>>>>> ************************/
>>>>> +AXIS2_DECLARE(axis2_xml_reader_t *)
>>>>> +axis2_xml_reader_create_for_xml_doc(axis2_env_t **env,
>>>>> +                                    void *doc)
>>>>> +{    +    axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL;
>>>>> +    +    AXIS2_ENV_CHECK( env, NULL);
>>>>> +        +    wrapper_impl =
>>>>> (axis2_libxml2_reader_wrapper_impl_t*)AXIS2_MALLOC((*env)->allocator,
>>>>> +         sizeof(axis2_libxml2_reader_wrapper_impl_t));
>>>>> +    if(!wrapper_impl)
>>>>> +    {
>>>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>>>> AXIS2_FAILURE);
>>>>> +        return NULL;   +    }
>>>>> +    wrapper_impl->close_input_callback = NULL;
>>>>> +    wrapper_impl->read_input_callback = NULL;
>>>>> +    wrapper_impl->ctx = NULL;
>>>>> +   +    wrapper_impl->reader =  xmlReaderWalker((xmlDocPtr)doc);
>>>>> +
>>>>> +    if(!(wrapper_impl->reader))
>>>>> +    {
>>>>> +        AXIS2_FREE((*env)->allocator, wrapper_impl);
>>>>> +        AXIS2_ERROR_SET((*env)->error, +               
>>>>> AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE);
>>>>> +        return NULL;
>>>>> +    }
>>>>> +
>>>>> +    /*xmlTextReaderSetErrorHandler(wrapper_impl->reader, +        
>>>>> (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler,
>>>>> +         (*env));
>>>>> +    */
>>>>> +    wrapper_impl->current_event = -1;
>>>>> +    +    axis2_libxml2_reader_wrapper_init_map(wrapper_impl);
>>>>> +    +    wrapper_impl->parser.ops = NULL;
>>>>> +    wrapper_impl->parser.ops =
>>>>> (axis2_xml_reader_ops_t*)AXIS2_MALLOC((*env)->allocator,
>>>>> +                                sizeof(axis2_xml_reader_ops_t));
>>>>> +    +    if(!(wrapper_impl->parser.ops))
>>>>> +    {
>>>>> +        xmlFreeTextReader(wrapper_impl->reader);
>>>>> +        AXIS2_FREE((*env)->allocator, wrapper_impl);
>>>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>>>> AXIS2_FAILURE);
>>>>> +        return NULL;
>>>>> +    }
>>>>> +
>>>>> +   +    wrapper_impl->parser.ops->free =
>>>>> axis2_libxml2_reader_wrapper_free;
>>>>> +    wrapper_impl->parser.ops->next =
>>>>> axis2_libxml2_reader_wrapper_next;
>>>>> +    wrapper_impl->parser.ops->xml_free =
>>>>> axis2_libxml2_reader_wrapper_xml_free;
>>>>> +    +    wrapper_impl->parser.ops->get_attribute_count =
>>>>> +        axis2_libxml2_reader_wrapper_get_attribute_count;
>>>>> +    wrapper_impl->parser.ops->get_attribute_name_by_number =
>>>>> +        axis2_libxml2_reader_wrapper_get_attribute_name_by_number;
>>>>> +    wrapper_impl->parser.ops->get_attribute_value_by_number =
>>>>> +        axis2_libxml2_reader_wrapper_get_attribute_value_by_number;
>>>>> +    wrapper_impl->parser.ops->get_attribute_namespace_by_number =
>>>>> +       
>>>>> axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number;
>>>>> +    wrapper_impl->parser.ops->get_attribute_prefix_by_number =
>>>>> +        axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number;
>>>>> +    +    wrapper_impl->parser.ops->get_value =
>>>>> +        axis2_libxml2_reader_wrapper_get_value;
>>>>> +    wrapper_impl->parser.ops->get_prefix =
>>>>> +        axis2_libxml2_reader_wrapper_get_prefix;
>>>>> +    wrapper_impl->parser.ops->get_name =
>>>>> +        axis2_libxml2_reader_wrapper_get_name;
>>>>> +        +        +    
>>>>> wrapper_impl->parser.ops->get_namespace_count =
>>>>> +        axis2_libxml2_reader_wrapper_get_namespace_count;
>>>>> +    wrapper_impl->parser.ops->get_namespace_prefix_by_number =
>>>>> +        axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number;
>>>>> +    wrapper_impl->parser.ops->get_namespace_uri_by_number =
>>>>> +        axis2_libxml2_reader_wrapper_get_namespace_uri_by_number;
>>>>> +        +    wrapper_impl->parser.ops->get_pi_target =
>>>>> +        axis2_libxml2_reader_wrapper_get_pi_target;
>>>>> +    wrapper_impl->parser.ops->get_pi_data =
>>>>> +        axis2_libxml2_reader_wrapper_get_pi_data;
>>>>> +        +    wrapper_impl->parser.ops->get_dtd =
>>>>> +        axis2_libxml2_reader_wrapper_get_dtd;
>>>>> +        +    wrapper_impl->parser.ops->get_char_set_encoding =
>>>>> +        axis2_libxml2_reader_wrapper_get_char_set_encoding;
>>>>> +
>>>>> +    return &(wrapper_impl->parser);
>>>>> +}
>>>>> /****************** end create functions
>>>>> ***************************************/
>>>>>
>>>>> int AXIS2_CALL
>>>>> Index: include/axis2_xml_reader.h
>>>>> ===================================================================
>>>>> --- include/axis2_xml_reader.h    (revision 394906)
>>>>> +++ include/axis2_xml_reader.h    (working copy)
>>>>> @@ -355,6 +355,9 @@
>>>>>                                 int size,
>>>>>                                 const axis2_char_t *encoding);
>>>>>
>>>>> +AXIS2_DECLARE(axis2_xml_reader_t *)
>>>>> +axis2_xml_reader_create_for_xml_doc(axis2_env_t **env,
>>>>> +                                    void *doc);   /**
>>>>> * init function initializes the parser */
>>>>> Index: include/axis2_xml_writer.h
>>>>> ===================================================================
>>>>> --- include/axis2_xml_writer.h    (revision 394906)
>>>>> +++ include/axis2_xml_writer.h    (working copy)
>>>>> @@ -464,6 +464,12 @@
>>>>>                                  int is_prefix_default,
>>>>>                                  int compression);
>>>>>
>>>>> +AXIS2_DECLARE(axis2_xml_writer_t *)
>>>>> +    axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
>>>>> +                                   axis2_char_t *encoding,
>>>>> +                                   int is_prefix_default,
>>>>> +                                   int compression);
>>>>> +   /********************** start macros
>>>>> *******************************************/
>>>>>
>>>>> #define AXIS2_XML_WRITER_FREE(writer, env) \
>>>>>
>>>>>
>>>>>  
>>>>>       
>>>>
>>>>
>>>>
>>>>
>>>>     
>>>
>>>   
>>
>>
>>
>>  
>>
>
>


Re: [Axis2] Patch - new functions to libxml2 wrapper

Posted by Samisa Abeysinghe <sa...@gmail.com>.
OK, So nabeel want to create the reader/writer in a different manner.
If that is the case, why not keep more or less the same API and add an 
optinal thir parameter (or a variable param list) to the create_for 
memory method of reader/writer?
This way, the impl details will be hidden from the user, and we could 
have the same API, wont cause problems raised by Sahan.
Samisa...

Sahan Gamage wrote:

>Hi Nabeel,
>
>Pls see my inline comments.
>
>Nabeel wrote:
>
>  
>
>>Sahan Gamage wrote:
>>
>>    
>>
>>>Hi Nabeel,
>>>
>>>What is this xmlDoc ? Is it libxml2 thing ? If so aren't we adding a
>>>hard binding to Axis2C with libxml2 ?
>>> 
>>>
>>>      
>>>
>>   Yes, xmlDoc is libxml2 specific. But xmlDoc is hidden inside the
>>impls of the libxml2 wrapper to prevent hard binding.  (if you have a
>>look at the public interfaces axis2_xml_reader.h and
>>axis2_xml_writer.h you won't find any xmlDoc pointers)
>>    
>>
>
>Yes. I saw that. But the problem is where are you going to use it ? At
>the point you are using these functions, say foo()is something similar
>to this:
>
>void foo()
>{
>    xmlDoc *doc = get_by_some_way();
>    axis2_xml_reader_t *reader = NULL;
>    ...
>    reader = axis2_xml_reader_create_for_xml_doc(env, doc);
>    ...
>}
>This code is pretty dependent on libxml2. So if this is for code for
>axis2 as soon as we change the parser (to guththila or to any other pull
>parser) the code will break unless we add a hard link dependancy for
>libxml2. Isn't it ?
>
>  
>
>>    Only catch is that the new functions are useful only when you are
>>using libxml2. If you are using some other xml parser library,
>>Guththila for example, you may not want to implement these new
>>prototypes in your wrapper.
>>    
>>
>
>My understanding is that wrpper is an interface to the common
>functionality that every library that it wraps, can provide. So if
>guththila can't provide this functionality we are breaking the rules of
>wrapper. And the worst thing is we are exposing these libxml2 specific
>stuff to the outside world by putting it to the public headers
>axis2_xml_reader.h and axis2_xml_writer.h
>
>  
>
>>thanks
>>-Nabeel
>>
>>    
>>
>>>IMHO the wrapper is there to hide implemention specific (in this case
>>>libxml2) details. If we expose the libxml2 things in the wrapper, the
>>>idea of the wrapper is not there any more. Please clarify
>>>
>>>- Sahan
>>>
>>>Nabeel wrote:
>>>
>>> 
>>>
>>>      
>>>
>>>>The patch contains -
>>>>a new reader that reads a xmlDoc
>>>>a new writer that writes to a xmlDoc
>>>>
>>>>(these methods are used by the php extension to prevent double
>>>>serialization when exchanging XML)
>>>>
>>>>Please apply to svn.
>>>>
>>>>thanks
>>>>-Nabeel
>>>>
>>>>------------------------------------------------------------------------
>>>>
>>>>
>>>>Index: modules/xml/parser/libxml2/libxml2_writer_wrapper.c
>>>>===================================================================
>>>>--- modules/xml/parser/libxml2/libxml2_writer_wrapper.c    (revision
>>>>394906)
>>>>+++ modules/xml/parser/libxml2/libxml2_writer_wrapper.c    (working
>>>>copy)
>>>>@@ -34,6 +34,7 @@
>>>>
>>>>#define AXIS2_LIBXML2_WRITER_MEMORY 1
>>>>#define AXIS2_LIBXML2_WRITER_FILE   2
>>>>+#define AXIS2_LIBXML2_WRITER_DOC    3
>>>>
>>>>/************************ structures
>>>>*****************************************/
>>>>
>>>>@@ -56,6 +57,8 @@
>>>>   xmlTextWriterPtr xml_writer;
>>>>      xmlBufferPtr buffer;
>>>>+
>>>>+    xmlDocPtr doc;
>>>>      int writer_type;
>>>>   @@ -262,6 +265,10 @@
>>>>axis2_char_t* AXIS2_CALL
>>>>axis2_libxml2_writer_wrapper_get_xml(axis2_xml_writer_t *writer,
>>>>                                    axis2_env_t **env);
>>>>+
>>>>+void* AXIS2_CALL
>>>>+axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
>>>>+                                                axis2_env_t **env);
>>>>                                    /*********************** static
>>>>functions ************************************/
>>>>static axis2_status_t
>>>>@@ -658,6 +665,180 @@
>>>>   return &(writer_impl->writer);
>>>>}
>>>>
>>>>+/*********************** writer create func for file
>>>>***************************/
>>>>+
>>>>+AXIS2_DECLARE(axis2_xml_writer_t *)
>>>>+axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
>>>>+                                   axis2_char_t *encoding,
>>>>+                                   int is_prefix_default,
>>>>+                                   int compression)
>>>>+{
>>>>+    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
>>>>+    AXIS2_ENV_CHECK(env, NULL);
>>>>+    writer_impl = (axis2_libxml2_writer_wrapper_impl_t
>>>>*)AXIS2_MALLOC((*env)->allocator,
>>>>+                   sizeof(axis2_libxml2_writer_wrapper_impl_t));
>>>>+    if(!writer_impl)
>>>>+    {
>>>>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>>>AXIS2_FAILURE);
>>>>+        return NULL;
>>>>+    }
>>>>+    +    writer_impl->writer.ops = NULL;
>>>>+    writer_impl->encoding = NULL;
>>>>+    writer_impl->buffer = NULL;
>>>>+    writer_impl->in_empty_element = AXIS2_FALSE;
>>>>+    writer_impl->in_start_element = AXIS2_FALSE;
>>>>+    writer_impl->stack = NULL;
>>>>+    writer_impl->uri_prefix_map = NULL;
>>>>+    writer_impl->default_lang_namespace = NULL;
>>>>+    +    writer_impl->writer_type = AXIS2_LIBXML2_WRITER_DOC;
>>>>+    writer_impl->compression = compression;
>>>>+    +    +    /*writer_impl->buffer = xmlBufferCreate();
>>>>+    if(writer_impl->buffer == NULL)
>>>>+    {
>>>>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>>>env);
>>>>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>>>AXIS2_FAILURE);
>>>>+        return NULL;
>>>>+    }*/
>>>>+    +    writer_impl->xml_writer =
>>>>/*xmlNewTextWriterMemory(writer_impl->buffer, 0);*/
>>>>+                               
>>>>xmlNewTextWriterDoc(&writer_impl->doc, 0);
>>>>+    if(writer_impl->xml_writer == NULL)
>>>>+    {
>>>>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>>>env);
>>>>+        AXIS2_ERROR_SET((*env)->error,
>>>>AXIS2_ERROR_CREATING_XML_STREAM_WRITER , AXIS2_FAILURE);
>>>>+        return NULL;
>>>>+    }
>>>>+
>>>>+     if(encoding)
>>>>+        writer_impl->encoding = AXIS2_STRDUP(encoding , env);
>>>>+    else
>>>>+        writer_impl->encoding = AXIS2_STRDUP(ENCODING, env);
>>>>+     +    +    writer_impl->uri_prefix_map = axis2_hash_make(env);
>>>>+    if(!(writer_impl->uri_prefix_map))
>>>>+    {
>>>>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>>>env);
>>>>+        AXIS2_ERROR_SET((*env)->error, +           
>>>>AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>>>+        +        return NULL;
>>>>+    }
>>>>+    writer_impl->stack = axis2_stack_create(env);
>>>>+    if(!(writer_impl->stack))
>>>>+    {
>>>>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>>>env);
>>>>+        AXIS2_ERROR_SET((*env)->error, +           
>>>>AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>>>+        return NULL;
>>>>+    }
>>>>+    +   
>>>>axis2_libxml2_writer_wrapper_set_default_lang_namespace(&(writer_impl->writer),
>>>>env);
>>>>+    +    writer_impl->writer.ops =
>>>>(axis2_xml_writer_ops_t*)AXIS2_MALLOC((*env)->allocator,
>>>>+                                    sizeof(axis2_xml_writer_ops_t));
>>>>+    if(!(writer_impl->writer.ops))
>>>>+    {
>>>>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>>>env);
>>>>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>>>AXIS2_FAILURE);
>>>>+        return NULL;
>>>>+    }
>>>>+    +    /* ops */
>>>>+    writer_impl->writer.ops->free = +           
>>>>axis2_libxml2_writer_wrapper_free;
>>>>+            +    writer_impl->writer.ops->write_start_element =
>>>>+            axis2_libxml2_writer_wrapper_write_start_element;
>>>>+            +   
>>>>writer_impl->writer.ops->write_start_element_with_namespace =
>>>>+           
>>>>axis2_libxml2_writer_wrapper_write_start_element_with_namespace;
>>>>+            +   
>>>>writer_impl->writer.ops->write_start_element_with_namespace_prefix =
>>>>+           
>>>>axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix;
>>>>+    +    writer_impl->writer.ops->write_empty_element =
>>>>+            axis2_libxml2_writer_wrapper_write_empty_element;
>>>>+            +   
>>>>writer_impl->writer.ops->write_empty_element_with_namespace  =
>>>>+           
>>>>axis2_libxml2_writer_wrapper_write_empty_element_with_namespace;
>>>>+            +   
>>>>writer_impl->writer.ops->write_empty_element_with_namespace_prefix =
>>>>+           
>>>>axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix;
>>>>+    +    writer_impl->writer.ops->write_end_element = +           
>>>>axis2_libxml2_writer_wrapper_write_end_element;
>>>>+            +    writer_impl->writer.ops->write_end_document =
>>>>+            axis2_libxml2_writer_wrapper_write_end_document;
>>>>+    +    writer_impl->writer.ops->write_attribute = +           
>>>>axis2_libxml2_writer_wrapper_write_attribute;
>>>>+            +   
>>>>writer_impl->writer.ops->write_attribute_with_namespace =
>>>>+           
>>>>axis2_libxml2_writer_wrapper_write_attribute_with_namespace;
>>>>+            +   
>>>>writer_impl->writer.ops->write_attribute_with_namespace_prefix =
>>>>+           
>>>>axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix;
>>>>+            +    writer_impl->writer.ops->write_namespace =
>>>>+            axis2_libxml2_writer_wrapper_write_namespace;
>>>>+            +    writer_impl->writer.ops->write_default_namespace =
>>>>+            axis2_libxml2_writer_wrapper_write_default_namespace;
>>>>+            +    writer_impl->writer.ops->write_comment =
>>>>+            axis2_libxml2_writer_wrapper_write_comment;
>>>>+            +   
>>>>writer_impl->writer.ops->write_processing_instruction = +           
>>>>axis2_libxml2_writer_wrapper_write_processing_instruction;
>>>>+            +   
>>>>writer_impl->writer.ops->write_processing_instruction_data =
>>>>+           
>>>>axis2_libxml2_writer_wrapper_write_processing_instruction_data;
>>>>+            +    writer_impl->writer.ops->write_cdata =
>>>>+            axis2_libxml2_writer_wrapper_write_cdata;
>>>>+            +    writer_impl->writer.ops->write_dtd = +           
>>>>axis2_libxml2_writer_wrapper_write_dtd;
>>>>+            +    writer_impl->writer.ops->write_entity_ref =
>>>>+            axis2_libxml2_writer_wrapper_write_entity_ref;
>>>>+            +    writer_impl->writer.ops->write_start_document =
>>>>+            axis2_libxml2_writer_wrapper_write_start_document;
>>>>+            +   
>>>>writer_impl->writer.ops->write_start_document_with_version =
>>>>+           
>>>>axis2_libxml2_writer_wrapper_write_start_document_with_version;
>>>>+            +   
>>>>writer_impl->writer.ops->write_start_document_with_version_encoding
>>>>= +           
>>>>axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding;
>>>>
>>>>+            +    writer_impl->writer.ops->write_characters =
>>>>+            axis2_libxml2_writer_wrapper_write_characters;
>>>>+            +    writer_impl->writer.ops->get_prefix =
>>>>+            axis2_libxml2_writer_wrapper_get_prefix;
>>>>+            +    writer_impl->writer.ops->set_prefix = +           
>>>>axis2_libxml2_writer_wrapper_set_prefix;
>>>>+            +    writer_impl->writer.ops->set_default_prefix =
>>>>+            axis2_libxml2_writer_wrapper_set_default_prefix;
>>>>+            +    writer_impl->writer.ops->write_encoded =
>>>>+            axis2_libxml2_writer_wrapper_write_encoded;
>>>>+            +    writer_impl->writer.ops->get_xml =
>>>>+            axis2_libxml2_writer_wrapper_get_xml_doc;
>>>>+                             +    return &(writer_impl->writer);
>>>>+}
>>>>+
>>>>/*******************************************************************************/
>>>>
>>>>axis2_status_t AXIS2_CALL
>>>>axis2_libxml2_writer_wrapper_free(axis2_xml_writer_t *writer,
>>>>@@ -1561,6 +1742,26 @@
>>>>   return output;   }
>>>>
>>>>+void* AXIS2_CALL
>>>>+axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
>>>>+                                        axis2_env_t **env)
>>>>+{
>>>>+    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
>>>>+    writer_impl = AXIS2_INTF_TO_IMPL(writer);
>>>>+
>>>>+    if(writer_impl->xml_writer)
>>>>+    {
>>>>+        xmlFreeTextWriter(writer_impl->xml_writer);
>>>>+        writer_impl->xml_writer = NULL;
>>>>+    }
>>>>+
>>>>+    if (writer_impl->writer_type == AXIS2_LIBXML2_WRITER_DOC)
>>>>+    {
>>>>+        return (void*)writer_impl->doc;
>>>>+    }
>>>>+    return NULL;
>>>>+}
>>>>+
>>>>static axis2_status_t
>>>>axis2_libxml2_writer_wrapper_pop_context(axis2_xml_writer_t *writer,
>>>>                                        axis2_env_t **env)
>>>>Index: modules/xml/parser/libxml2/libxml2_reader_wrapper.c
>>>>===================================================================
>>>>--- modules/xml/parser/libxml2/libxml2_reader_wrapper.c    (revision
>>>>394906)
>>>>+++ modules/xml/parser/libxml2/libxml2_reader_wrapper.c    (working
>>>>copy)
>>>>@@ -555,6 +555,102 @@
>>>>                               return &(wrapper_impl->parser);
>>>>}
>>>>+
>>>>+
>>>>+/***************** create function for xmlDoc
>>>>************************/
>>>>+AXIS2_DECLARE(axis2_xml_reader_t *)
>>>>+axis2_xml_reader_create_for_xml_doc(axis2_env_t **env,
>>>>+                                    void *doc)
>>>>+{    +    axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL;
>>>>+    +    AXIS2_ENV_CHECK( env, NULL);
>>>>+        +    wrapper_impl =
>>>>(axis2_libxml2_reader_wrapper_impl_t*)AXIS2_MALLOC((*env)->allocator,
>>>>+         sizeof(axis2_libxml2_reader_wrapper_impl_t));
>>>>+    if(!wrapper_impl)
>>>>+    {
>>>>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>>>AXIS2_FAILURE);
>>>>+        return NULL;   +    }
>>>>+    wrapper_impl->close_input_callback = NULL;
>>>>+    wrapper_impl->read_input_callback = NULL;
>>>>+    wrapper_impl->ctx = NULL;
>>>>+   
>>>>+    wrapper_impl->reader =  xmlReaderWalker((xmlDocPtr)doc);
>>>>+
>>>>+    if(!(wrapper_impl->reader))
>>>>+    {
>>>>+        AXIS2_FREE((*env)->allocator, wrapper_impl);
>>>>+        AXIS2_ERROR_SET((*env)->error, +               
>>>>AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE);
>>>>+        return NULL;
>>>>+    }
>>>>+
>>>>+    /*xmlTextReaderSetErrorHandler(wrapper_impl->reader, +        
>>>>(xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler,
>>>>+         (*env));
>>>>+    */
>>>>+    wrapper_impl->current_event = -1;
>>>>+    +    axis2_libxml2_reader_wrapper_init_map(wrapper_impl);
>>>>+    +    wrapper_impl->parser.ops = NULL;
>>>>+    wrapper_impl->parser.ops =
>>>>(axis2_xml_reader_ops_t*)AXIS2_MALLOC((*env)->allocator,
>>>>+                                sizeof(axis2_xml_reader_ops_t));
>>>>+    +    if(!(wrapper_impl->parser.ops))
>>>>+    {
>>>>+        xmlFreeTextReader(wrapper_impl->reader);
>>>>+        AXIS2_FREE((*env)->allocator, wrapper_impl);
>>>>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>>>AXIS2_FAILURE);
>>>>+        return NULL;
>>>>+    }
>>>>+
>>>>+   
>>>>+    wrapper_impl->parser.ops->free =
>>>>axis2_libxml2_reader_wrapper_free;
>>>>+    wrapper_impl->parser.ops->next =
>>>>axis2_libxml2_reader_wrapper_next;
>>>>+    wrapper_impl->parser.ops->xml_free =
>>>>axis2_libxml2_reader_wrapper_xml_free;
>>>>+    +    wrapper_impl->parser.ops->get_attribute_count =
>>>>+        axis2_libxml2_reader_wrapper_get_attribute_count;
>>>>+    wrapper_impl->parser.ops->get_attribute_name_by_number =
>>>>+        axis2_libxml2_reader_wrapper_get_attribute_name_by_number;
>>>>+    wrapper_impl->parser.ops->get_attribute_value_by_number =
>>>>+        axis2_libxml2_reader_wrapper_get_attribute_value_by_number;
>>>>+    wrapper_impl->parser.ops->get_attribute_namespace_by_number =
>>>>+       
>>>>axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number;
>>>>+    wrapper_impl->parser.ops->get_attribute_prefix_by_number =
>>>>+        axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number;
>>>>+    +    wrapper_impl->parser.ops->get_value =
>>>>+        axis2_libxml2_reader_wrapper_get_value;
>>>>+    wrapper_impl->parser.ops->get_prefix =
>>>>+        axis2_libxml2_reader_wrapper_get_prefix;
>>>>+    wrapper_impl->parser.ops->get_name =
>>>>+        axis2_libxml2_reader_wrapper_get_name;
>>>>+        +        +    wrapper_impl->parser.ops->get_namespace_count =
>>>>+        axis2_libxml2_reader_wrapper_get_namespace_count;
>>>>+    wrapper_impl->parser.ops->get_namespace_prefix_by_number =
>>>>+        axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number;
>>>>+    wrapper_impl->parser.ops->get_namespace_uri_by_number =
>>>>+        axis2_libxml2_reader_wrapper_get_namespace_uri_by_number;
>>>>+        +    wrapper_impl->parser.ops->get_pi_target =
>>>>+        axis2_libxml2_reader_wrapper_get_pi_target;
>>>>+    wrapper_impl->parser.ops->get_pi_data =
>>>>+        axis2_libxml2_reader_wrapper_get_pi_data;
>>>>+        +    wrapper_impl->parser.ops->get_dtd =
>>>>+        axis2_libxml2_reader_wrapper_get_dtd;
>>>>+        +    wrapper_impl->parser.ops->get_char_set_encoding =
>>>>+        axis2_libxml2_reader_wrapper_get_char_set_encoding;
>>>>+
>>>>+    return &(wrapper_impl->parser);
>>>>+}
>>>>/****************** end create functions
>>>>***************************************/
>>>>
>>>>int AXIS2_CALL
>>>>Index: include/axis2_xml_reader.h
>>>>===================================================================
>>>>--- include/axis2_xml_reader.h    (revision 394906)
>>>>+++ include/axis2_xml_reader.h    (working copy)
>>>>@@ -355,6 +355,9 @@
>>>>                                 int size,
>>>>                                 const axis2_char_t *encoding);
>>>>
>>>>+AXIS2_DECLARE(axis2_xml_reader_t *)
>>>>+axis2_xml_reader_create_for_xml_doc(axis2_env_t **env,
>>>>+                                    void *doc);   
>>>>/**
>>>>* init function initializes the parser */
>>>>Index: include/axis2_xml_writer.h
>>>>===================================================================
>>>>--- include/axis2_xml_writer.h    (revision 394906)
>>>>+++ include/axis2_xml_writer.h    (working copy)
>>>>@@ -464,6 +464,12 @@
>>>>                                  int is_prefix_default,
>>>>                                  int compression);
>>>>
>>>>+AXIS2_DECLARE(axis2_xml_writer_t *)
>>>>+    axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
>>>>+                                   axis2_char_t *encoding,
>>>>+                                   int is_prefix_default,
>>>>+                                   int compression);
>>>>+   
>>>>/********************** start macros
>>>>*******************************************/
>>>>
>>>>#define AXIS2_XML_WRITER_FREE(writer, env) \
>>>>
>>>>
>>>>  
>>>>        
>>>>
>>>
>>> 
>>>
>>>      
>>>
>>    
>>
>
>
>  
>


Re: [Axis2] Patch - new functions to libxml2 wrapper

Posted by Sahan Gamage <sa...@wso2.com>.
Hi Nabeel,

Pls see my inline comments.

Nabeel wrote:

> Sahan Gamage wrote:
>
>> Hi Nabeel,
>>
>> What is this xmlDoc ? Is it libxml2 thing ? If so aren't we adding a
>> hard binding to Axis2C with libxml2 ?
>>  
>>
>    Yes, xmlDoc is libxml2 specific. But xmlDoc is hidden inside the
> impls of the libxml2 wrapper to prevent hard binding.  (if you have a
> look at the public interfaces axis2_xml_reader.h and
> axis2_xml_writer.h you won't find any xmlDoc pointers)

Yes. I saw that. But the problem is where are you going to use it ? At
the point you are using these functions, say foo()is something similar
to this:

void foo()
{
    xmlDoc *doc = get_by_some_way();
    axis2_xml_reader_t *reader = NULL;
    ...
    reader = axis2_xml_reader_create_for_xml_doc(env, doc);
    ...
}
This code is pretty dependent on libxml2. So if this is for code for
axis2 as soon as we change the parser (to guththila or to any other pull
parser) the code will break unless we add a hard link dependancy for
libxml2. Isn't it ?

>     Only catch is that the new functions are useful only when you are
> using libxml2. If you are using some other xml parser library,
> Guththila for example, you may not want to implement these new
> prototypes in your wrapper.

My understanding is that wrpper is an interface to the common
functionality that every library that it wraps, can provide. So if
guththila can't provide this functionality we are breaking the rules of
wrapper. And the worst thing is we are exposing these libxml2 specific
stuff to the outside world by putting it to the public headers
axis2_xml_reader.h and axis2_xml_writer.h

>
>
> thanks
> -Nabeel
>
>> IMHO the wrapper is there to hide implemention specific (in this case
>> libxml2) details. If we expose the libxml2 things in the wrapper, the
>> idea of the wrapper is not there any more. Please clarify
>>
>> - Sahan
>>
>> Nabeel wrote:
>>
>>  
>>
>>> The patch contains -
>>> a new reader that reads a xmlDoc
>>> a new writer that writes to a xmlDoc
>>>
>>> (these methods are used by the php extension to prevent double
>>> serialization when exchanging XML)
>>>
>>> Please apply to svn.
>>>
>>> thanks
>>> -Nabeel
>>>
>>> ------------------------------------------------------------------------
>>>
>>>
>>> Index: modules/xml/parser/libxml2/libxml2_writer_wrapper.c
>>> ===================================================================
>>> --- modules/xml/parser/libxml2/libxml2_writer_wrapper.c    (revision
>>> 394906)
>>> +++ modules/xml/parser/libxml2/libxml2_writer_wrapper.c    (working
>>> copy)
>>> @@ -34,6 +34,7 @@
>>>
>>> #define AXIS2_LIBXML2_WRITER_MEMORY 1
>>> #define AXIS2_LIBXML2_WRITER_FILE   2
>>> +#define AXIS2_LIBXML2_WRITER_DOC    3
>>>
>>> /************************ structures
>>> *****************************************/
>>>
>>> @@ -56,6 +57,8 @@
>>>    xmlTextWriterPtr xml_writer;
>>>       xmlBufferPtr buffer;
>>> +
>>> +    xmlDocPtr doc;
>>>       int writer_type;
>>>    @@ -262,6 +265,10 @@
>>> axis2_char_t* AXIS2_CALL
>>> axis2_libxml2_writer_wrapper_get_xml(axis2_xml_writer_t *writer,
>>>                                     axis2_env_t **env);
>>> +
>>> +void* AXIS2_CALL
>>> +axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
>>> +                                                axis2_env_t **env);
>>>                                     /*********************** static
>>> functions ************************************/
>>> static axis2_status_t
>>> @@ -658,6 +665,180 @@
>>>    return &(writer_impl->writer);
>>> }
>>>
>>> +/*********************** writer create func for file
>>> ***************************/
>>> +
>>> +AXIS2_DECLARE(axis2_xml_writer_t *)
>>> +axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
>>> +                                   axis2_char_t *encoding,
>>> +                                   int is_prefix_default,
>>> +                                   int compression)
>>> +{
>>> +    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
>>> +    AXIS2_ENV_CHECK(env, NULL);
>>> +    writer_impl = (axis2_libxml2_writer_wrapper_impl_t
>>> *)AXIS2_MALLOC((*env)->allocator,
>>> +                   sizeof(axis2_libxml2_writer_wrapper_impl_t));
>>> +    if(!writer_impl)
>>> +    {
>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>> AXIS2_FAILURE);
>>> +        return NULL;
>>> +    }
>>> +    +    writer_impl->writer.ops = NULL;
>>> +    writer_impl->encoding = NULL;
>>> +    writer_impl->buffer = NULL;
>>> +    writer_impl->in_empty_element = AXIS2_FALSE;
>>> +    writer_impl->in_start_element = AXIS2_FALSE;
>>> +    writer_impl->stack = NULL;
>>> +    writer_impl->uri_prefix_map = NULL;
>>> +    writer_impl->default_lang_namespace = NULL;
>>> +    +    writer_impl->writer_type = AXIS2_LIBXML2_WRITER_DOC;
>>> +    writer_impl->compression = compression;
>>> +    +    +    /*writer_impl->buffer = xmlBufferCreate();
>>> +    if(writer_impl->buffer == NULL)
>>> +    {
>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>> env);
>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>> AXIS2_FAILURE);
>>> +        return NULL;
>>> +    }*/
>>> +    +    writer_impl->xml_writer =
>>> /*xmlNewTextWriterMemory(writer_impl->buffer, 0);*/
>>> +                               
>>> xmlNewTextWriterDoc(&writer_impl->doc, 0);
>>> +    if(writer_impl->xml_writer == NULL)
>>> +    {
>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>> env);
>>> +        AXIS2_ERROR_SET((*env)->error,
>>> AXIS2_ERROR_CREATING_XML_STREAM_WRITER , AXIS2_FAILURE);
>>> +        return NULL;
>>> +    }
>>> +
>>> +     if(encoding)
>>> +        writer_impl->encoding = AXIS2_STRDUP(encoding , env);
>>> +    else
>>> +        writer_impl->encoding = AXIS2_STRDUP(ENCODING, env);
>>> +     +    +    writer_impl->uri_prefix_map = axis2_hash_make(env);
>>> +    if(!(writer_impl->uri_prefix_map))
>>> +    {
>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>> env);
>>> +        AXIS2_ERROR_SET((*env)->error, +           
>>> AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>> +        +        return NULL;
>>> +    }
>>> +    writer_impl->stack = axis2_stack_create(env);
>>> +    if(!(writer_impl->stack))
>>> +    {
>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>> env);
>>> +        AXIS2_ERROR_SET((*env)->error, +           
>>> AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>> +        return NULL;
>>> +    }
>>> +    +   
>>> axis2_libxml2_writer_wrapper_set_default_lang_namespace(&(writer_impl->writer),
>>> env);
>>> +    +    writer_impl->writer.ops =
>>> (axis2_xml_writer_ops_t*)AXIS2_MALLOC((*env)->allocator,
>>> +                                    sizeof(axis2_xml_writer_ops_t));
>>> +    if(!(writer_impl->writer.ops))
>>> +    {
>>> +        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer),
>>> env);
>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>> AXIS2_FAILURE);
>>> +        return NULL;
>>> +    }
>>> +    +    /* ops */
>>> +    writer_impl->writer.ops->free = +           
>>> axis2_libxml2_writer_wrapper_free;
>>> +            +    writer_impl->writer.ops->write_start_element =
>>> +            axis2_libxml2_writer_wrapper_write_start_element;
>>> +            +   
>>> writer_impl->writer.ops->write_start_element_with_namespace =
>>> +           
>>> axis2_libxml2_writer_wrapper_write_start_element_with_namespace;
>>> +            +   
>>> writer_impl->writer.ops->write_start_element_with_namespace_prefix =
>>> +           
>>> axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix;
>>> +    +    writer_impl->writer.ops->write_empty_element =
>>> +            axis2_libxml2_writer_wrapper_write_empty_element;
>>> +            +   
>>> writer_impl->writer.ops->write_empty_element_with_namespace  =
>>> +           
>>> axis2_libxml2_writer_wrapper_write_empty_element_with_namespace;
>>> +            +   
>>> writer_impl->writer.ops->write_empty_element_with_namespace_prefix =
>>> +           
>>> axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix;
>>> +    +    writer_impl->writer.ops->write_end_element = +           
>>> axis2_libxml2_writer_wrapper_write_end_element;
>>> +            +    writer_impl->writer.ops->write_end_document =
>>> +            axis2_libxml2_writer_wrapper_write_end_document;
>>> +    +    writer_impl->writer.ops->write_attribute = +           
>>> axis2_libxml2_writer_wrapper_write_attribute;
>>> +            +   
>>> writer_impl->writer.ops->write_attribute_with_namespace =
>>> +           
>>> axis2_libxml2_writer_wrapper_write_attribute_with_namespace;
>>> +            +   
>>> writer_impl->writer.ops->write_attribute_with_namespace_prefix =
>>> +           
>>> axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix;
>>> +            +    writer_impl->writer.ops->write_namespace =
>>> +            axis2_libxml2_writer_wrapper_write_namespace;
>>> +            +    writer_impl->writer.ops->write_default_namespace =
>>> +            axis2_libxml2_writer_wrapper_write_default_namespace;
>>> +            +    writer_impl->writer.ops->write_comment =
>>> +            axis2_libxml2_writer_wrapper_write_comment;
>>> +            +   
>>> writer_impl->writer.ops->write_processing_instruction = +           
>>> axis2_libxml2_writer_wrapper_write_processing_instruction;
>>> +            +   
>>> writer_impl->writer.ops->write_processing_instruction_data =
>>> +           
>>> axis2_libxml2_writer_wrapper_write_processing_instruction_data;
>>> +            +    writer_impl->writer.ops->write_cdata =
>>> +            axis2_libxml2_writer_wrapper_write_cdata;
>>> +            +    writer_impl->writer.ops->write_dtd = +           
>>> axis2_libxml2_writer_wrapper_write_dtd;
>>> +            +    writer_impl->writer.ops->write_entity_ref =
>>> +            axis2_libxml2_writer_wrapper_write_entity_ref;
>>> +            +    writer_impl->writer.ops->write_start_document =
>>> +            axis2_libxml2_writer_wrapper_write_start_document;
>>> +            +   
>>> writer_impl->writer.ops->write_start_document_with_version =
>>> +           
>>> axis2_libxml2_writer_wrapper_write_start_document_with_version;
>>> +            +   
>>> writer_impl->writer.ops->write_start_document_with_version_encoding
>>> = +           
>>> axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding;
>>>
>>> +            +    writer_impl->writer.ops->write_characters =
>>> +            axis2_libxml2_writer_wrapper_write_characters;
>>> +            +    writer_impl->writer.ops->get_prefix =
>>> +            axis2_libxml2_writer_wrapper_get_prefix;
>>> +            +    writer_impl->writer.ops->set_prefix = +           
>>> axis2_libxml2_writer_wrapper_set_prefix;
>>> +            +    writer_impl->writer.ops->set_default_prefix =
>>> +            axis2_libxml2_writer_wrapper_set_default_prefix;
>>> +            +    writer_impl->writer.ops->write_encoded =
>>> +            axis2_libxml2_writer_wrapper_write_encoded;
>>> +            +    writer_impl->writer.ops->get_xml =
>>> +            axis2_libxml2_writer_wrapper_get_xml_doc;
>>> +                             +    return &(writer_impl->writer);
>>> +}
>>> +
>>> /*******************************************************************************/
>>>
>>> axis2_status_t AXIS2_CALL
>>> axis2_libxml2_writer_wrapper_free(axis2_xml_writer_t *writer,
>>> @@ -1561,6 +1742,26 @@
>>>    return output;   }
>>>
>>> +void* AXIS2_CALL
>>> +axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
>>> +                                        axis2_env_t **env)
>>> +{
>>> +    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
>>> +    writer_impl = AXIS2_INTF_TO_IMPL(writer);
>>> +
>>> +    if(writer_impl->xml_writer)
>>> +    {
>>> +        xmlFreeTextWriter(writer_impl->xml_writer);
>>> +        writer_impl->xml_writer = NULL;
>>> +    }
>>> +
>>> +    if (writer_impl->writer_type == AXIS2_LIBXML2_WRITER_DOC)
>>> +    {
>>> +        return (void*)writer_impl->doc;
>>> +    }
>>> +    return NULL;
>>> +}
>>> +
>>> static axis2_status_t
>>> axis2_libxml2_writer_wrapper_pop_context(axis2_xml_writer_t *writer,
>>>                                         axis2_env_t **env)
>>> Index: modules/xml/parser/libxml2/libxml2_reader_wrapper.c
>>> ===================================================================
>>> --- modules/xml/parser/libxml2/libxml2_reader_wrapper.c    (revision
>>> 394906)
>>> +++ modules/xml/parser/libxml2/libxml2_reader_wrapper.c    (working
>>> copy)
>>> @@ -555,6 +555,102 @@
>>>                                return &(wrapper_impl->parser);
>>> }
>>> +
>>> +
>>> +/***************** create function for xmlDoc
>>> ************************/
>>> +AXIS2_DECLARE(axis2_xml_reader_t *)
>>> +axis2_xml_reader_create_for_xml_doc(axis2_env_t **env,
>>> +                                    void *doc)
>>> +{    +    axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL;
>>> +    +    AXIS2_ENV_CHECK( env, NULL);
>>> +        +    wrapper_impl =
>>> (axis2_libxml2_reader_wrapper_impl_t*)AXIS2_MALLOC((*env)->allocator,
>>> +         sizeof(axis2_libxml2_reader_wrapper_impl_t));
>>> +    if(!wrapper_impl)
>>> +    {
>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>> AXIS2_FAILURE);
>>> +        return NULL;   +    }
>>> +    wrapper_impl->close_input_callback = NULL;
>>> +    wrapper_impl->read_input_callback = NULL;
>>> +    wrapper_impl->ctx = NULL;
>>> +   
>>> +    wrapper_impl->reader =  xmlReaderWalker((xmlDocPtr)doc);
>>> +
>>> +    if(!(wrapper_impl->reader))
>>> +    {
>>> +        AXIS2_FREE((*env)->allocator, wrapper_impl);
>>> +        AXIS2_ERROR_SET((*env)->error, +               
>>> AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE);
>>> +        return NULL;
>>> +    }
>>> +
>>> +    /*xmlTextReaderSetErrorHandler(wrapper_impl->reader, +        
>>> (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler,
>>> +         (*env));
>>> +    */
>>> +    wrapper_impl->current_event = -1;
>>> +    +    axis2_libxml2_reader_wrapper_init_map(wrapper_impl);
>>> +    +    wrapper_impl->parser.ops = NULL;
>>> +    wrapper_impl->parser.ops =
>>> (axis2_xml_reader_ops_t*)AXIS2_MALLOC((*env)->allocator,
>>> +                                sizeof(axis2_xml_reader_ops_t));
>>> +    +    if(!(wrapper_impl->parser.ops))
>>> +    {
>>> +        xmlFreeTextReader(wrapper_impl->reader);
>>> +        AXIS2_FREE((*env)->allocator, wrapper_impl);
>>> +        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY,
>>> AXIS2_FAILURE);
>>> +        return NULL;
>>> +    }
>>> +
>>> +   
>>> +    wrapper_impl->parser.ops->free =
>>> axis2_libxml2_reader_wrapper_free;
>>> +    wrapper_impl->parser.ops->next =
>>> axis2_libxml2_reader_wrapper_next;
>>> +    wrapper_impl->parser.ops->xml_free =
>>> axis2_libxml2_reader_wrapper_xml_free;
>>> +    +    wrapper_impl->parser.ops->get_attribute_count =
>>> +        axis2_libxml2_reader_wrapper_get_attribute_count;
>>> +    wrapper_impl->parser.ops->get_attribute_name_by_number =
>>> +        axis2_libxml2_reader_wrapper_get_attribute_name_by_number;
>>> +    wrapper_impl->parser.ops->get_attribute_value_by_number =
>>> +        axis2_libxml2_reader_wrapper_get_attribute_value_by_number;
>>> +    wrapper_impl->parser.ops->get_attribute_namespace_by_number =
>>> +       
>>> axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number;
>>> +    wrapper_impl->parser.ops->get_attribute_prefix_by_number =
>>> +        axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number;
>>> +    +    wrapper_impl->parser.ops->get_value =
>>> +        axis2_libxml2_reader_wrapper_get_value;
>>> +    wrapper_impl->parser.ops->get_prefix =
>>> +        axis2_libxml2_reader_wrapper_get_prefix;
>>> +    wrapper_impl->parser.ops->get_name =
>>> +        axis2_libxml2_reader_wrapper_get_name;
>>> +        +        +    wrapper_impl->parser.ops->get_namespace_count =
>>> +        axis2_libxml2_reader_wrapper_get_namespace_count;
>>> +    wrapper_impl->parser.ops->get_namespace_prefix_by_number =
>>> +        axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number;
>>> +    wrapper_impl->parser.ops->get_namespace_uri_by_number =
>>> +        axis2_libxml2_reader_wrapper_get_namespace_uri_by_number;
>>> +        +    wrapper_impl->parser.ops->get_pi_target =
>>> +        axis2_libxml2_reader_wrapper_get_pi_target;
>>> +    wrapper_impl->parser.ops->get_pi_data =
>>> +        axis2_libxml2_reader_wrapper_get_pi_data;
>>> +        +    wrapper_impl->parser.ops->get_dtd =
>>> +        axis2_libxml2_reader_wrapper_get_dtd;
>>> +        +    wrapper_impl->parser.ops->get_char_set_encoding =
>>> +        axis2_libxml2_reader_wrapper_get_char_set_encoding;
>>> +
>>> +    return &(wrapper_impl->parser);
>>> +}
>>> /****************** end create functions
>>> ***************************************/
>>>
>>> int AXIS2_CALL
>>> Index: include/axis2_xml_reader.h
>>> ===================================================================
>>> --- include/axis2_xml_reader.h    (revision 394906)
>>> +++ include/axis2_xml_reader.h    (working copy)
>>> @@ -355,6 +355,9 @@
>>>                                  int size,
>>>                                  const axis2_char_t *encoding);
>>>
>>> +AXIS2_DECLARE(axis2_xml_reader_t *)
>>> +axis2_xml_reader_create_for_xml_doc(axis2_env_t **env,
>>> +                                    void *doc);   
>>> /**
>>> * init function initializes the parser */
>>> Index: include/axis2_xml_writer.h
>>> ===================================================================
>>> --- include/axis2_xml_writer.h    (revision 394906)
>>> +++ include/axis2_xml_writer.h    (working copy)
>>> @@ -464,6 +464,12 @@
>>>                                   int is_prefix_default,
>>>                                   int compression);
>>>
>>> +AXIS2_DECLARE(axis2_xml_writer_t *)
>>> +    axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
>>> +                                   axis2_char_t *encoding,
>>> +                                   int is_prefix_default,
>>> +                                   int compression);
>>> +   
>>> /********************** start macros
>>> *******************************************/
>>>
>>> #define AXIS2_XML_WRITER_FREE(writer, env) \
>>>
>>>
>>>   
>>
>>
>>
>>  
>>
>
>


Re: [Axis2] Improvements to fault model

Posted by Samisa Abeysinghe <sa...@gmail.com>.
Samisa Abeysinghe wrote:

> Hi All,
>    I have been some considerable amount of improvements to get the 
> SOAP fault processing correct.
>    Now the fault model seem to be almost complete, and works well with 
> the WS-Addressing interop tests with few problems here and there, 
> which I am looking into fixing.
>    There has been numerous improvements to the addressing handler as 
> well.
>
>    However, these fixes to the fault model and addressing handler 
> causes the samples not to work as they used to.
>    If you have the addressing module enabled in axis2.xml, then 
> addressing based samples would work, but not the others.
>    If you remove addressing module from axis2.xml, non addressing 
> samples such as echo and math would work.

This is fixed now, now the addressing enabled and disabled cliets can 
work simultaneously

>
>    There is a problem in the engaging and dis-engaging modules at the 
> moment and that causes the above problem. I am looking into fixing it.
> Thanks,
> Samisa...
>


[Axis2] Improvements to fault model

Posted by Samisa Abeysinghe <sa...@gmail.com>.
Hi All,
    I have been some considerable amount of improvements to get the SOAP 
fault processing correct.
    Now the fault model seem to be almost complete, and works well with 
the WS-Addressing interop tests with few problems here and there, which 
I am looking into fixing.
    There has been numerous improvements to the addressing handler as well.

    However, these fixes to the fault model and addressing handler 
causes the samples not to work as they used to.
    If you have the addressing module enabled in axis2.xml, then 
addressing based samples would work, but not the others.
    If you remove addressing module from axis2.xml, non addressing 
samples such as echo and math would work.

    There is a problem in the engaging and dis-engaging modules at the 
moment and that causes the above problem. I am looking into fixing it.
Thanks,
Samisa...

Re: [Axis2] Patch - new functions to libxml2 wrapper

Posted by Nabeel <na...@wso2.com>.
Sahan Gamage wrote:

>Hi Nabeel,
>
>What is this xmlDoc ? Is it libxml2 thing ? If so aren't we adding a
>hard binding to Axis2C with libxml2 ?
>  
>
    Yes, xmlDoc is libxml2 specific. But xmlDoc is hidden inside the 
impls of the libxml2 wrapper to prevent hard binding.  (if you have a 
look at the public interfaces axis2_xml_reader.h and axis2_xml_writer.h 
you won't find any xmlDoc pointers)
     Only catch is that the new functions are useful only when you are 
using libxml2. If you are using some other xml parser library, Guththila 
for example, you may not want to implement these new prototypes in your 
wrapper.

thanks
-Nabeel

>IMHO the wrapper is there to hide implemention specific (in this case
>libxml2) details. If we expose the libxml2 things in the wrapper, the
>idea of the wrapper is not there any more. Please clarify
>
>- Sahan
>
>Nabeel wrote:
>
>  
>
>>The patch contains -
>>a new reader that reads a xmlDoc
>>a new writer that writes to a xmlDoc
>>
>>(these methods are used by the php extension to prevent double
>>serialization when exchanging XML)
>>
>>Please apply to svn.
>>
>>thanks
>>-Nabeel
>>
>>------------------------------------------------------------------------
>>
>>Index: modules/xml/parser/libxml2/libxml2_writer_wrapper.c
>>===================================================================
>>--- modules/xml/parser/libxml2/libxml2_writer_wrapper.c	(revision 394906)
>>+++ modules/xml/parser/libxml2/libxml2_writer_wrapper.c	(working copy)
>>@@ -34,6 +34,7 @@
>>
>>#define AXIS2_LIBXML2_WRITER_MEMORY 1
>>#define AXIS2_LIBXML2_WRITER_FILE   2
>>+#define AXIS2_LIBXML2_WRITER_DOC	3
>>
>>/************************ structures *****************************************/
>>
>>@@ -56,6 +57,8 @@
>>    xmlTextWriterPtr xml_writer;
>>    
>>    xmlBufferPtr buffer;
>>+
>>+	xmlDocPtr doc;
>>    
>>    int writer_type;
>>    
>>@@ -262,6 +265,10 @@
>>axis2_char_t* AXIS2_CALL
>>axis2_libxml2_writer_wrapper_get_xml(axis2_xml_writer_t *writer,
>>                                     axis2_env_t **env);
>>+
>>+void* AXIS2_CALL
>>+axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
>>+		                                        axis2_env_t **env);
>>                                     
>>/*********************** static functions ************************************/
>>static axis2_status_t
>>@@ -658,6 +665,180 @@
>>    return &(writer_impl->writer);
>>}
>>
>>+/*********************** writer create func for file ***************************/
>>+
>>+AXIS2_DECLARE(axis2_xml_writer_t *)
>>+axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
>>+                                   axis2_char_t *encoding, 
>>+                                   int is_prefix_default,
>>+                                   int compression)
>>+{
>>+    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
>>+    AXIS2_ENV_CHECK(env, NULL);
>>+    writer_impl = (axis2_libxml2_writer_wrapper_impl_t *)AXIS2_MALLOC((*env)->allocator,
>>+                   sizeof(axis2_libxml2_writer_wrapper_impl_t));
>>+    if(!writer_impl)
>>+    {
>>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>+        return NULL;
>>+    }
>>+    
>>+    writer_impl->writer.ops = NULL;
>>+    writer_impl->encoding = NULL;
>>+    writer_impl->buffer = NULL;
>>+    writer_impl->in_empty_element = AXIS2_FALSE;
>>+    writer_impl->in_start_element = AXIS2_FALSE;
>>+    writer_impl->stack = NULL;
>>+    writer_impl->uri_prefix_map = NULL;
>>+    writer_impl->default_lang_namespace = NULL;
>>+    
>>+    writer_impl->writer_type = AXIS2_LIBXML2_WRITER_DOC;
>>+    writer_impl->compression = compression;
>>+    
>>+    
>>+    /*writer_impl->buffer = xmlBufferCreate();
>>+    if(writer_impl->buffer == NULL)
>>+    {
>>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
>>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>+        return NULL;
>>+    }*/
>>+    
>>+    writer_impl->xml_writer = /*xmlNewTextWriterMemory(writer_impl->buffer, 0);*/
>>+								xmlNewTextWriterDoc(&writer_impl->doc, 0);
>>+    if(writer_impl->xml_writer == NULL)
>>+    {
>>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
>>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_CREATING_XML_STREAM_WRITER , AXIS2_FAILURE);
>>+        return NULL;
>>+    }
>>+
>>+     if(encoding)
>>+        writer_impl->encoding = AXIS2_STRDUP(encoding , env);
>>+    else
>>+        writer_impl->encoding = AXIS2_STRDUP(ENCODING, env);
>>+     
>>+    
>>+    writer_impl->uri_prefix_map = axis2_hash_make(env);
>>+    if(!(writer_impl->uri_prefix_map))
>>+    {
>>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
>>+        AXIS2_ERROR_SET((*env)->error, 
>>+            AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>+        
>>+        return NULL;
>>+    }
>>+    writer_impl->stack = axis2_stack_create(env);
>>+    if(!(writer_impl->stack))
>>+    {
>>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
>>+        AXIS2_ERROR_SET((*env)->error, 
>>+            AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>+        return NULL;
>>+    }
>>+    
>>+    axis2_libxml2_writer_wrapper_set_default_lang_namespace(&(writer_impl->writer), env);
>>+    
>>+    writer_impl->writer.ops = (axis2_xml_writer_ops_t*)AXIS2_MALLOC((*env)->allocator,
>>+                                    sizeof(axis2_xml_writer_ops_t));
>>+    if(!(writer_impl->writer.ops))
>>+    {
>>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
>>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>+        return NULL;
>>+    }
>>+    
>>+    /* ops */
>>+    writer_impl->writer.ops->free = 
>>+            axis2_libxml2_writer_wrapper_free;
>>+            
>>+    writer_impl->writer.ops->write_start_element = 
>>+            axis2_libxml2_writer_wrapper_write_start_element;
>>+            
>>+    writer_impl->writer.ops->write_start_element_with_namespace =
>>+            axis2_libxml2_writer_wrapper_write_start_element_with_namespace;
>>+            
>>+    writer_impl->writer.ops->write_start_element_with_namespace_prefix = 
>>+            axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix;
>>+    
>>+    writer_impl->writer.ops->write_empty_element =
>>+            axis2_libxml2_writer_wrapper_write_empty_element;
>>+            
>>+    writer_impl->writer.ops->write_empty_element_with_namespace  =
>>+            axis2_libxml2_writer_wrapper_write_empty_element_with_namespace;
>>+            
>>+    writer_impl->writer.ops->write_empty_element_with_namespace_prefix =
>>+            axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix;
>>+    
>>+    writer_impl->writer.ops->write_end_element = 
>>+            axis2_libxml2_writer_wrapper_write_end_element;
>>+            
>>+    writer_impl->writer.ops->write_end_document = 
>>+            axis2_libxml2_writer_wrapper_write_end_document;
>>+    
>>+    writer_impl->writer.ops->write_attribute = 
>>+            axis2_libxml2_writer_wrapper_write_attribute;
>>+            
>>+    writer_impl->writer.ops->write_attribute_with_namespace =
>>+            axis2_libxml2_writer_wrapper_write_attribute_with_namespace;
>>+            
>>+    writer_impl->writer.ops->write_attribute_with_namespace_prefix =
>>+            axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix;
>>+            
>>+    writer_impl->writer.ops->write_namespace = 
>>+            axis2_libxml2_writer_wrapper_write_namespace;
>>+            
>>+    writer_impl->writer.ops->write_default_namespace =
>>+            axis2_libxml2_writer_wrapper_write_default_namespace;
>>+            
>>+    writer_impl->writer.ops->write_comment = 
>>+            axis2_libxml2_writer_wrapper_write_comment;
>>+            
>>+    writer_impl->writer.ops->write_processing_instruction = 
>>+            axis2_libxml2_writer_wrapper_write_processing_instruction;
>>+            
>>+    writer_impl->writer.ops->write_processing_instruction_data = 
>>+            axis2_libxml2_writer_wrapper_write_processing_instruction_data;
>>+            
>>+    writer_impl->writer.ops->write_cdata = 
>>+            axis2_libxml2_writer_wrapper_write_cdata;
>>+            
>>+    writer_impl->writer.ops->write_dtd = 
>>+            axis2_libxml2_writer_wrapper_write_dtd;
>>+            
>>+    writer_impl->writer.ops->write_entity_ref = 
>>+            axis2_libxml2_writer_wrapper_write_entity_ref;
>>+            
>>+    writer_impl->writer.ops->write_start_document = 
>>+            axis2_libxml2_writer_wrapper_write_start_document;
>>+            
>>+    writer_impl->writer.ops->write_start_document_with_version = 
>>+            axis2_libxml2_writer_wrapper_write_start_document_with_version;
>>+            
>>+    writer_impl->writer.ops->write_start_document_with_version_encoding = 
>>+            axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding;
>>+            
>>+    writer_impl->writer.ops->write_characters = 
>>+            axis2_libxml2_writer_wrapper_write_characters;
>>+            
>>+    writer_impl->writer.ops->get_prefix =
>>+            axis2_libxml2_writer_wrapper_get_prefix;
>>+            
>>+    writer_impl->writer.ops->set_prefix = 
>>+            axis2_libxml2_writer_wrapper_set_prefix;
>>+            
>>+    writer_impl->writer.ops->set_default_prefix = 
>>+            axis2_libxml2_writer_wrapper_set_default_prefix;
>>+            
>>+    writer_impl->writer.ops->write_encoded = 
>>+            axis2_libxml2_writer_wrapper_write_encoded;
>>+            
>>+    writer_impl->writer.ops->get_xml =
>>+            axis2_libxml2_writer_wrapper_get_xml_doc;
>>+                             
>>+    return &(writer_impl->writer);
>>+}
>>+
>>/*******************************************************************************/
>>axis2_status_t AXIS2_CALL 
>>axis2_libxml2_writer_wrapper_free(axis2_xml_writer_t *writer,
>>@@ -1561,6 +1742,26 @@
>>    return output;   
>>}
>>
>>+void* AXIS2_CALL
>>+axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
>>+										axis2_env_t **env)
>>+{
>>+	axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
>>+	writer_impl = AXIS2_INTF_TO_IMPL(writer);
>>+
>>+    if(writer_impl->xml_writer)
>>+    {
>>+        xmlFreeTextWriter(writer_impl->xml_writer);
>>+        writer_impl->xml_writer = NULL;
>>+    }
>>+
>>+	if (writer_impl->writer_type == AXIS2_LIBXML2_WRITER_DOC)
>>+	{
>>+		return (void*)writer_impl->doc;
>>+	}
>>+	return NULL;
>>+}
>>+
>>static axis2_status_t
>>axis2_libxml2_writer_wrapper_pop_context(axis2_xml_writer_t *writer,
>>                                         axis2_env_t **env)
>>Index: modules/xml/parser/libxml2/libxml2_reader_wrapper.c
>>===================================================================
>>--- modules/xml/parser/libxml2/libxml2_reader_wrapper.c	(revision 394906)
>>+++ modules/xml/parser/libxml2/libxml2_reader_wrapper.c	(working copy)
>>@@ -555,6 +555,102 @@
>>                            
>>	return &(wrapper_impl->parser);
>>}
>>+
>>+
>>+/***************** create function for xmlDoc ************************/
>>+AXIS2_DECLARE(axis2_xml_reader_t *)
>>+axis2_xml_reader_create_for_xml_doc(axis2_env_t **env,
>>+									void *doc)
>>+{    
>>+	axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL;
>>+    
>>+    AXIS2_ENV_CHECK( env, NULL);
>>+        
>>+    wrapper_impl = (axis2_libxml2_reader_wrapper_impl_t*)AXIS2_MALLOC((*env)->allocator,
>>+         sizeof(axis2_libxml2_reader_wrapper_impl_t));
>>+    if(!wrapper_impl)
>>+    {
>>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>+        return NULL;   
>>+    }
>>+    wrapper_impl->close_input_callback = NULL;
>>+    wrapper_impl->read_input_callback = NULL;
>>+	wrapper_impl->ctx = NULL;
>>+	
>>+    wrapper_impl->reader =  xmlReaderWalker((xmlDocPtr)doc);
>>+
>>+    if(!(wrapper_impl->reader))
>>+    {
>>+        AXIS2_FREE((*env)->allocator, wrapper_impl);
>>+        AXIS2_ERROR_SET((*env)->error, 
>>+				AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE);
>>+        return NULL;
>>+    }
>>+
>>+    /*xmlTextReaderSetErrorHandler(wrapper_impl->reader, 
>>+         (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler, 
>>+         (*env));
>>+	*/
>>+    wrapper_impl->current_event = -1;
>>+    
>>+    axis2_libxml2_reader_wrapper_init_map(wrapper_impl);
>>+    
>>+    wrapper_impl->parser.ops = NULL;
>>+    wrapper_impl->parser.ops = (axis2_xml_reader_ops_t*)AXIS2_MALLOC((*env)->allocator,
>>+                                sizeof(axis2_xml_reader_ops_t));
>>+    
>>+    if(!(wrapper_impl->parser.ops))
>>+    {
>>+        xmlFreeTextReader(wrapper_impl->reader);
>>+        AXIS2_FREE((*env)->allocator, wrapper_impl);
>>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>+        return NULL;
>>+    }
>>+
>>+	
>>+	wrapper_impl->parser.ops->free = axis2_libxml2_reader_wrapper_free;
>>+    wrapper_impl->parser.ops->next = axis2_libxml2_reader_wrapper_next;
>>+    wrapper_impl->parser.ops->xml_free = axis2_libxml2_reader_wrapper_xml_free;
>>+    
>>+    wrapper_impl->parser.ops->get_attribute_count =
>>+        axis2_libxml2_reader_wrapper_get_attribute_count;
>>+    wrapper_impl->parser.ops->get_attribute_name_by_number =
>>+        axis2_libxml2_reader_wrapper_get_attribute_name_by_number;
>>+    wrapper_impl->parser.ops->get_attribute_value_by_number = 
>>+        axis2_libxml2_reader_wrapper_get_attribute_value_by_number;
>>+    wrapper_impl->parser.ops->get_attribute_namespace_by_number =
>>+        axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number;
>>+    wrapper_impl->parser.ops->get_attribute_prefix_by_number =
>>+        axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number;
>>+    
>>+    wrapper_impl->parser.ops->get_value =
>>+        axis2_libxml2_reader_wrapper_get_value;
>>+    wrapper_impl->parser.ops->get_prefix =
>>+        axis2_libxml2_reader_wrapper_get_prefix;
>>+    wrapper_impl->parser.ops->get_name =
>>+        axis2_libxml2_reader_wrapper_get_name;
>>+        
>>+        
>>+    wrapper_impl->parser.ops->get_namespace_count =
>>+        axis2_libxml2_reader_wrapper_get_namespace_count;
>>+    wrapper_impl->parser.ops->get_namespace_prefix_by_number =
>>+        axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number;
>>+    wrapper_impl->parser.ops->get_namespace_uri_by_number =
>>+        axis2_libxml2_reader_wrapper_get_namespace_uri_by_number;
>>+        
>>+    wrapper_impl->parser.ops->get_pi_target =
>>+        axis2_libxml2_reader_wrapper_get_pi_target;
>>+    wrapper_impl->parser.ops->get_pi_data =
>>+        axis2_libxml2_reader_wrapper_get_pi_data;
>>+        
>>+    wrapper_impl->parser.ops->get_dtd =
>>+        axis2_libxml2_reader_wrapper_get_dtd;
>>+        
>>+    wrapper_impl->parser.ops->get_char_set_encoding =
>>+		axis2_libxml2_reader_wrapper_get_char_set_encoding;
>>+
>>+	return &(wrapper_impl->parser);
>>+}
>>/****************** end create functions ***************************************/
>>
>>int AXIS2_CALL
>>Index: include/axis2_xml_reader.h
>>===================================================================
>>--- include/axis2_xml_reader.h	(revision 394906)
>>+++ include/axis2_xml_reader.h	(working copy)
>>@@ -355,6 +355,9 @@
>>                                  int size,
>>                                  const axis2_char_t *encoding);
>>
>>+AXIS2_DECLARE(axis2_xml_reader_t *)
>>+axis2_xml_reader_create_for_xml_doc(axis2_env_t **env, 
>>+									void *doc);	
>>/**
>> * init function initializes the parser 
>> */
>>Index: include/axis2_xml_writer.h
>>===================================================================
>>--- include/axis2_xml_writer.h	(revision 394906)
>>+++ include/axis2_xml_writer.h	(working copy)
>>@@ -464,6 +464,12 @@
>>                                   int is_prefix_default,
>>                                   int compression);
>>
>>+AXIS2_DECLARE(axis2_xml_writer_t *)
>>+	axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
>>+                                   axis2_char_t *encoding,
>>+                                   int is_prefix_default,
>>+                                   int compression);
>>+	
>>/********************** start macros *******************************************/
>>
>>#define AXIS2_XML_WRITER_FREE(writer, env) \
>> 
>>
>>    
>>
>
>
>  
>


Re: [Axis2] Patch - new functions to libxml2 wrapper

Posted by Sahan Gamage <sa...@wso2.com>.
Hi Nabeel,

What is this xmlDoc ? Is it libxml2 thing ? If so aren't we adding a
hard binding to Axis2C with libxml2 ?
IMHO the wrapper is there to hide implemention specific (in this case
libxml2) details. If we expose the libxml2 things in the wrapper, the
idea of the wrapper is not there any more. Please clarify

- Sahan

Nabeel wrote:

> The patch contains -
> a new reader that reads a xmlDoc
> a new writer that writes to a xmlDoc
>
> (these methods are used by the php extension to prevent double
> serialization when exchanging XML)
>
> Please apply to svn.
>
> thanks
> -Nabeel
>
>------------------------------------------------------------------------
>
>Index: modules/xml/parser/libxml2/libxml2_writer_wrapper.c
>===================================================================
>--- modules/xml/parser/libxml2/libxml2_writer_wrapper.c	(revision 394906)
>+++ modules/xml/parser/libxml2/libxml2_writer_wrapper.c	(working copy)
>@@ -34,6 +34,7 @@
> 
> #define AXIS2_LIBXML2_WRITER_MEMORY 1
> #define AXIS2_LIBXML2_WRITER_FILE   2
>+#define AXIS2_LIBXML2_WRITER_DOC	3
> 
> /************************ structures *****************************************/
> 
>@@ -56,6 +57,8 @@
>     xmlTextWriterPtr xml_writer;
>     
>     xmlBufferPtr buffer;
>+
>+	xmlDocPtr doc;
>     
>     int writer_type;
>     
>@@ -262,6 +265,10 @@
> axis2_char_t* AXIS2_CALL
> axis2_libxml2_writer_wrapper_get_xml(axis2_xml_writer_t *writer,
>                                      axis2_env_t **env);
>+
>+void* AXIS2_CALL
>+axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
>+		                                        axis2_env_t **env);
>                                      
> /*********************** static functions ************************************/
> static axis2_status_t
>@@ -658,6 +665,180 @@
>     return &(writer_impl->writer);
> }
> 
>+/*********************** writer create func for file ***************************/
>+
>+AXIS2_DECLARE(axis2_xml_writer_t *)
>+axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
>+                                   axis2_char_t *encoding, 
>+                                   int is_prefix_default,
>+                                   int compression)
>+{
>+    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
>+    AXIS2_ENV_CHECK(env, NULL);
>+    writer_impl = (axis2_libxml2_writer_wrapper_impl_t *)AXIS2_MALLOC((*env)->allocator,
>+                   sizeof(axis2_libxml2_writer_wrapper_impl_t));
>+    if(!writer_impl)
>+    {
>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>+        return NULL;
>+    }
>+    
>+    writer_impl->writer.ops = NULL;
>+    writer_impl->encoding = NULL;
>+    writer_impl->buffer = NULL;
>+    writer_impl->in_empty_element = AXIS2_FALSE;
>+    writer_impl->in_start_element = AXIS2_FALSE;
>+    writer_impl->stack = NULL;
>+    writer_impl->uri_prefix_map = NULL;
>+    writer_impl->default_lang_namespace = NULL;
>+    
>+    writer_impl->writer_type = AXIS2_LIBXML2_WRITER_DOC;
>+    writer_impl->compression = compression;
>+    
>+    
>+    /*writer_impl->buffer = xmlBufferCreate();
>+    if(writer_impl->buffer == NULL)
>+    {
>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>+        return NULL;
>+    }*/
>+    
>+    writer_impl->xml_writer = /*xmlNewTextWriterMemory(writer_impl->buffer, 0);*/
>+								xmlNewTextWriterDoc(&writer_impl->doc, 0);
>+    if(writer_impl->xml_writer == NULL)
>+    {
>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_CREATING_XML_STREAM_WRITER , AXIS2_FAILURE);
>+        return NULL;
>+    }
>+
>+     if(encoding)
>+        writer_impl->encoding = AXIS2_STRDUP(encoding , env);
>+    else
>+        writer_impl->encoding = AXIS2_STRDUP(ENCODING, env);
>+     
>+    
>+    writer_impl->uri_prefix_map = axis2_hash_make(env);
>+    if(!(writer_impl->uri_prefix_map))
>+    {
>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
>+        AXIS2_ERROR_SET((*env)->error, 
>+            AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>+        
>+        return NULL;
>+    }
>+    writer_impl->stack = axis2_stack_create(env);
>+    if(!(writer_impl->stack))
>+    {
>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
>+        AXIS2_ERROR_SET((*env)->error, 
>+            AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>+        return NULL;
>+    }
>+    
>+    axis2_libxml2_writer_wrapper_set_default_lang_namespace(&(writer_impl->writer), env);
>+    
>+    writer_impl->writer.ops = (axis2_xml_writer_ops_t*)AXIS2_MALLOC((*env)->allocator,
>+                                    sizeof(axis2_xml_writer_ops_t));
>+    if(!(writer_impl->writer.ops))
>+    {
>+        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>+        return NULL;
>+    }
>+    
>+    /* ops */
>+    writer_impl->writer.ops->free = 
>+            axis2_libxml2_writer_wrapper_free;
>+            
>+    writer_impl->writer.ops->write_start_element = 
>+            axis2_libxml2_writer_wrapper_write_start_element;
>+            
>+    writer_impl->writer.ops->write_start_element_with_namespace =
>+            axis2_libxml2_writer_wrapper_write_start_element_with_namespace;
>+            
>+    writer_impl->writer.ops->write_start_element_with_namespace_prefix = 
>+            axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix;
>+    
>+    writer_impl->writer.ops->write_empty_element =
>+            axis2_libxml2_writer_wrapper_write_empty_element;
>+            
>+    writer_impl->writer.ops->write_empty_element_with_namespace  =
>+            axis2_libxml2_writer_wrapper_write_empty_element_with_namespace;
>+            
>+    writer_impl->writer.ops->write_empty_element_with_namespace_prefix =
>+            axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix;
>+    
>+    writer_impl->writer.ops->write_end_element = 
>+            axis2_libxml2_writer_wrapper_write_end_element;
>+            
>+    writer_impl->writer.ops->write_end_document = 
>+            axis2_libxml2_writer_wrapper_write_end_document;
>+    
>+    writer_impl->writer.ops->write_attribute = 
>+            axis2_libxml2_writer_wrapper_write_attribute;
>+            
>+    writer_impl->writer.ops->write_attribute_with_namespace =
>+            axis2_libxml2_writer_wrapper_write_attribute_with_namespace;
>+            
>+    writer_impl->writer.ops->write_attribute_with_namespace_prefix =
>+            axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix;
>+            
>+    writer_impl->writer.ops->write_namespace = 
>+            axis2_libxml2_writer_wrapper_write_namespace;
>+            
>+    writer_impl->writer.ops->write_default_namespace =
>+            axis2_libxml2_writer_wrapper_write_default_namespace;
>+            
>+    writer_impl->writer.ops->write_comment = 
>+            axis2_libxml2_writer_wrapper_write_comment;
>+            
>+    writer_impl->writer.ops->write_processing_instruction = 
>+            axis2_libxml2_writer_wrapper_write_processing_instruction;
>+            
>+    writer_impl->writer.ops->write_processing_instruction_data = 
>+            axis2_libxml2_writer_wrapper_write_processing_instruction_data;
>+            
>+    writer_impl->writer.ops->write_cdata = 
>+            axis2_libxml2_writer_wrapper_write_cdata;
>+            
>+    writer_impl->writer.ops->write_dtd = 
>+            axis2_libxml2_writer_wrapper_write_dtd;
>+            
>+    writer_impl->writer.ops->write_entity_ref = 
>+            axis2_libxml2_writer_wrapper_write_entity_ref;
>+            
>+    writer_impl->writer.ops->write_start_document = 
>+            axis2_libxml2_writer_wrapper_write_start_document;
>+            
>+    writer_impl->writer.ops->write_start_document_with_version = 
>+            axis2_libxml2_writer_wrapper_write_start_document_with_version;
>+            
>+    writer_impl->writer.ops->write_start_document_with_version_encoding = 
>+            axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding;
>+            
>+    writer_impl->writer.ops->write_characters = 
>+            axis2_libxml2_writer_wrapper_write_characters;
>+            
>+    writer_impl->writer.ops->get_prefix =
>+            axis2_libxml2_writer_wrapper_get_prefix;
>+            
>+    writer_impl->writer.ops->set_prefix = 
>+            axis2_libxml2_writer_wrapper_set_prefix;
>+            
>+    writer_impl->writer.ops->set_default_prefix = 
>+            axis2_libxml2_writer_wrapper_set_default_prefix;
>+            
>+    writer_impl->writer.ops->write_encoded = 
>+            axis2_libxml2_writer_wrapper_write_encoded;
>+            
>+    writer_impl->writer.ops->get_xml =
>+            axis2_libxml2_writer_wrapper_get_xml_doc;
>+                             
>+    return &(writer_impl->writer);
>+}
>+
> /*******************************************************************************/
> axis2_status_t AXIS2_CALL 
> axis2_libxml2_writer_wrapper_free(axis2_xml_writer_t *writer,
>@@ -1561,6 +1742,26 @@
>     return output;   
> }
> 
>+void* AXIS2_CALL
>+axis2_libxml2_writer_wrapper_get_xml_doc(axis2_xml_writer_t *writer,
>+										axis2_env_t **env)
>+{
>+	axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
>+	writer_impl = AXIS2_INTF_TO_IMPL(writer);
>+
>+    if(writer_impl->xml_writer)
>+    {
>+        xmlFreeTextWriter(writer_impl->xml_writer);
>+        writer_impl->xml_writer = NULL;
>+    }
>+
>+	if (writer_impl->writer_type == AXIS2_LIBXML2_WRITER_DOC)
>+	{
>+		return (void*)writer_impl->doc;
>+	}
>+	return NULL;
>+}
>+
> static axis2_status_t
> axis2_libxml2_writer_wrapper_pop_context(axis2_xml_writer_t *writer,
>                                          axis2_env_t **env)
>Index: modules/xml/parser/libxml2/libxml2_reader_wrapper.c
>===================================================================
>--- modules/xml/parser/libxml2/libxml2_reader_wrapper.c	(revision 394906)
>+++ modules/xml/parser/libxml2/libxml2_reader_wrapper.c	(working copy)
>@@ -555,6 +555,102 @@
>                             
> 	return &(wrapper_impl->parser);
> }
>+
>+
>+/***************** create function for xmlDoc ************************/
>+AXIS2_DECLARE(axis2_xml_reader_t *)
>+axis2_xml_reader_create_for_xml_doc(axis2_env_t **env,
>+									void *doc)
>+{    
>+	axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL;
>+    
>+    AXIS2_ENV_CHECK( env, NULL);
>+        
>+    wrapper_impl = (axis2_libxml2_reader_wrapper_impl_t*)AXIS2_MALLOC((*env)->allocator,
>+         sizeof(axis2_libxml2_reader_wrapper_impl_t));
>+    if(!wrapper_impl)
>+    {
>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>+        return NULL;   
>+    }
>+    wrapper_impl->close_input_callback = NULL;
>+    wrapper_impl->read_input_callback = NULL;
>+	wrapper_impl->ctx = NULL;
>+	
>+    wrapper_impl->reader =  xmlReaderWalker((xmlDocPtr)doc);
>+
>+    if(!(wrapper_impl->reader))
>+    {
>+        AXIS2_FREE((*env)->allocator, wrapper_impl);
>+        AXIS2_ERROR_SET((*env)->error, 
>+				AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE);
>+        return NULL;
>+    }
>+
>+    /*xmlTextReaderSetErrorHandler(wrapper_impl->reader, 
>+         (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler, 
>+         (*env));
>+	*/
>+    wrapper_impl->current_event = -1;
>+    
>+    axis2_libxml2_reader_wrapper_init_map(wrapper_impl);
>+    
>+    wrapper_impl->parser.ops = NULL;
>+    wrapper_impl->parser.ops = (axis2_xml_reader_ops_t*)AXIS2_MALLOC((*env)->allocator,
>+                                sizeof(axis2_xml_reader_ops_t));
>+    
>+    if(!(wrapper_impl->parser.ops))
>+    {
>+        xmlFreeTextReader(wrapper_impl->reader);
>+        AXIS2_FREE((*env)->allocator, wrapper_impl);
>+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>+        return NULL;
>+    }
>+
>+	
>+	wrapper_impl->parser.ops->free = axis2_libxml2_reader_wrapper_free;
>+    wrapper_impl->parser.ops->next = axis2_libxml2_reader_wrapper_next;
>+    wrapper_impl->parser.ops->xml_free = axis2_libxml2_reader_wrapper_xml_free;
>+    
>+    wrapper_impl->parser.ops->get_attribute_count =
>+        axis2_libxml2_reader_wrapper_get_attribute_count;
>+    wrapper_impl->parser.ops->get_attribute_name_by_number =
>+        axis2_libxml2_reader_wrapper_get_attribute_name_by_number;
>+    wrapper_impl->parser.ops->get_attribute_value_by_number = 
>+        axis2_libxml2_reader_wrapper_get_attribute_value_by_number;
>+    wrapper_impl->parser.ops->get_attribute_namespace_by_number =
>+        axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number;
>+    wrapper_impl->parser.ops->get_attribute_prefix_by_number =
>+        axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number;
>+    
>+    wrapper_impl->parser.ops->get_value =
>+        axis2_libxml2_reader_wrapper_get_value;
>+    wrapper_impl->parser.ops->get_prefix =
>+        axis2_libxml2_reader_wrapper_get_prefix;
>+    wrapper_impl->parser.ops->get_name =
>+        axis2_libxml2_reader_wrapper_get_name;
>+        
>+        
>+    wrapper_impl->parser.ops->get_namespace_count =
>+        axis2_libxml2_reader_wrapper_get_namespace_count;
>+    wrapper_impl->parser.ops->get_namespace_prefix_by_number =
>+        axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number;
>+    wrapper_impl->parser.ops->get_namespace_uri_by_number =
>+        axis2_libxml2_reader_wrapper_get_namespace_uri_by_number;
>+        
>+    wrapper_impl->parser.ops->get_pi_target =
>+        axis2_libxml2_reader_wrapper_get_pi_target;
>+    wrapper_impl->parser.ops->get_pi_data =
>+        axis2_libxml2_reader_wrapper_get_pi_data;
>+        
>+    wrapper_impl->parser.ops->get_dtd =
>+        axis2_libxml2_reader_wrapper_get_dtd;
>+        
>+    wrapper_impl->parser.ops->get_char_set_encoding =
>+		axis2_libxml2_reader_wrapper_get_char_set_encoding;
>+
>+	return &(wrapper_impl->parser);
>+}
> /****************** end create functions ***************************************/
> 
> int AXIS2_CALL
>Index: include/axis2_xml_reader.h
>===================================================================
>--- include/axis2_xml_reader.h	(revision 394906)
>+++ include/axis2_xml_reader.h	(working copy)
>@@ -355,6 +355,9 @@
>                                   int size,
>                                   const axis2_char_t *encoding);
> 
>+AXIS2_DECLARE(axis2_xml_reader_t *)
>+axis2_xml_reader_create_for_xml_doc(axis2_env_t **env, 
>+									void *doc);	
> /**
>  * init function initializes the parser 
>  */
>Index: include/axis2_xml_writer.h
>===================================================================
>--- include/axis2_xml_writer.h	(revision 394906)
>+++ include/axis2_xml_writer.h	(working copy)
>@@ -464,6 +464,12 @@
>                                    int is_prefix_default,
>                                    int compression);
> 
>+AXIS2_DECLARE(axis2_xml_writer_t *)
>+	axis2_xml_writer_create_for_xml_doc(axis2_env_t **env,
>+                                   axis2_char_t *encoding,
>+                                   int is_prefix_default,
>+                                   int compression);
>+	
> /********************** start macros *******************************************/
> 
> #define AXIS2_XML_WRITER_FREE(writer, env) \
>  
>