axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Amila Suriarachchi" <>
Subject [Axis2][Axiom]Re: ADBDataSource getReader() method implementation.
Date Wed, 25 Jul 2007 11:19:44 GMT

I did the following to solve the second problem. I have already commited
this to trunk.

I created a new interface called MTOMAwareXMLStreamWriter which extends the
XMLStreamWriter and
have a special method called
 public void writeDataHandler(DataHandler dataHandler) throws

to support mtom handling.

ADB is an mtom aware data binding. So now ADB takes the
MTOMAwareStreamWriter to serilize the adb beans. And if the variable type is
DataHandler it calls for the writeDataHandler method in the bean class and
the MTOMAwareStreamWriter implementation will handle it properly.

There are two MTOMAwareXMLStreamWriter implementation classes.
1. MTOMAwareXMLSerializer
this is used in the normal stream serialization and it has basically wrapped
the existing XMLStreamwriter and has implemented the writeDataHandler method
as follows.

public void writeDataHandler(DataHandler dataHandler) throws
XMLStreamException {
        OMTextImpl omText = new OMTextImpl(dataHandler,

So that it handle the mtom serailization correctly.

2. MTOMAwareOMBuilder
this will creates an OMElement using the writter and has implements the
writeDataHandler method as follows,

public void writeDataHandler(DataHandler dataHandler) throws
XMLStreamException {
        OMText omText = omFactory.createOMText(dataHandler, true);

so that it sets the omText correctly.

And the ADBDataSource class is look like this,

   public void serialize(XMLStreamWriter xmlWriter) throws
        MTOMAwareXMLStreamWriter mtomAwareXMLStreamWriter = new

    public abstract void serialize(MTOMAwareXMLStreamWriter xmlWriter)
throws XMLStreamException;

    public XMLStreamReader getReader() throws XMLStreamException {
        // since only ADBBeans related to elements can be serialized
        // we are safe in passing null here.
        MTOMAwareOMBuilder mtomAwareOMBuilder = new MTOMAwareOMBuilder();
        return mtomAwareOMBuilder.getOMElement().getXMLStreamReader();

This way we can build the OMElement using the existing serialize method and
I think this is an optimal solution than what we had. But still performance
problem is there and can be solve by using the either way I have proposed.
So can someone have better axiom knowledge help in this?

in this article ajith has describe how ADB supports the binary (thanks ajith for writing this article which
help me a lot to understand this stuff)

So we can use the same technique to the Reader as well by defining a
MTOMAwareXMLStreamReader to ADB.
In this way we can introduce a much smoother interface to ADB and handle
Mtom specific code in MTOMAwareXMLStreamReader reader implementaion class.


On 7/24/07, Amila Suriarachchi <> wrote:
> ADB databinding in axis2 uses the ADBDatasource to return the OMElement.
> Currently ADBDatasource getReader and serialize methods are like this.
> public abstract void serialize(XMLStreamWriter xmlWriter)
>             throws XMLStreamException;
> public XMLStreamReader getReader() throws XMLStreamException {
>             return bean.getPullParser(parentQName);
> }
> When we want to serialize the xml stream directly to transport we use
> serialize method and the getReader is used in building the OMElemnet.
> Specially Rampart module always build the OMElement and hence call for
> getReader() method.
> The serialize method is worked fine and it is the well tested method in
> ADB and the getReader method which uses the ADBXmlStremReader has some issue
> regarding extension and binary handling.
> To solve this problem I wrote OMElmentStreamWriter [1] which build the
> OMElement from the writer.
> So now the getReader method looks like this. It use the serialize method
> to create the OMElement.
>  public XMLStreamReader getReader() throws XMLStreamException {
>         OMElementStreamWriter omElementStreamWriter = new
> OMElementStreamWriter();
>         serialize(omElementStreamWriter);
>         return omElementStreamWriter.getOMElement().getXMLStreamReader();
>     }
> this method perfectly works except the following two problems.
> 1. It is bit in efficient
> OMElementStreamWriter first creates the OMElement and then it is used to
> get the reader and again buid the OMElement.
> To solve that either we can introduce a method to OMDataSource to directly
> return the OMElement or AXIOM it self can use the above writer to build the
> OMElement using the serilize method.
> 2. problems with the MTOM
> This writer is not aware mtom. so it always serialize it as base64binary.
> To fix this problem we can test for this pirticular writer in ADB
> generated code (using instanceof or using a property) and set the data
> handler
> to the element using a special method.
> So this way we can create an OMElement which has a datahandler object in
> it.
> in ADB bean class
> if (writer instanceof OMElementStreamWriter){
>    (OMElementStreamWriter)writer).setDataHandler(dataHandler);
> }
> in OMElementStreamWriter
>  public void setDataHandler(DataHandler dataHandler){
>         OMText omText = omFactory.createOMText(dataHandler,true);
>         currentOMElement.addChild(omText);
>     }
> would this solve our problem?
> And can someone has a better knowledge with Axiom comment on these?
> The main advantage ADB has from this is to use the well tested serialize
> method and hence keep one method to serailize the bean.
> thanks,
> Amila.
> [1]
> --
> Amila Suriarachchi,
> WSO2 Inc.

Amila Suriarachchi,
WSO2 Inc.

View raw message