Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 21680 invoked from network); 25 Jul 2007 11:20:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Jul 2007 11:20:13 -0000 Received: (qmail 48149 invoked by uid 500); 25 Jul 2007 11:20:11 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 48090 invoked by uid 500); 25 Jul 2007 11:20:11 -0000 Mailing-List: contact axis-dev-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-dev@ws.apache.org Received: (qmail 48067 invoked by uid 99); 25 Jul 2007 11:20:11 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Jul 2007 04:20:11 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of amilasuriarachchi@gmail.com designates 72.14.214.235 as permitted sender) Received: from [72.14.214.235] (HELO hu-out-0506.google.com) (72.14.214.235) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Jul 2007 04:20:09 -0700 Received: by hu-out-0506.google.com with SMTP id 23so1880978huc for ; Wed, 25 Jul 2007 04:19:47 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=tn+67Qfzqa9gWs3IOzT8vB9Me4fL5rCj04/shUtMxGjLtSnYqc9jJHlDV1z9F/XNkAuOECPasOOFYuesf/e615Rk2DojhhWum573aTDDZ1Td3d/cj7UrjbbyVF/4louBaFND0IalqA+CZuK2vMxhz1aoQf+zVxVz27VeeOh9LG8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=cXbESh2bJdcNYmGvA2962MLXTezMfzrjaeugGb/Fdi6MvcZz66f2b5ls3DydCcmkrFYjUsd69Ulh8Qy9zuIR/CpJigKf6GRD52tLEt3dRa1n3d17WyNdiFkdoafiw8EYPAkTnxlxHPnRxnOh8L+eHg3jQ+L3nhnWIsx7AxlafWQ= Received: by 10.82.158.12 with SMTP id g12mr325644bue.1185362384912; Wed, 25 Jul 2007 04:19:44 -0700 (PDT) Received: by 10.82.172.13 with HTTP; Wed, 25 Jul 2007 04:19:44 -0700 (PDT) Message-ID: <60708f4b0707250419s510ef84ma1a6c2d79350b2f5@mail.gmail.com> Date: Wed, 25 Jul 2007 16:49:44 +0530 From: "Amila Suriarachchi" To: axis-dev@ws.apache.org, commons-dev@ws.apache.org Subject: [Axis2][Axiom]Re: ADBDataSource getReader() method implementation. In-Reply-To: <60708f4b0707240536q72d95881h5733d7648d2db5c@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_123996_29782541.1185362384877" References: <60708f4b0707240536q72d95881h5733d7648d2db5c@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_123996_29782541.1185362384877 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline hi, 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 XMLStreamException; 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, OMAbstractFactory.getOMFactory()); omText.internalSerializeAndConsume(this.xmlStreamWriter); } 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); currentOMElement.addChild(omText); } so that it sets the omText correctly. And the ADBDataSource class is look like this, public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException{ MTOMAwareXMLStreamWriter mtomAwareXMLStreamWriter = new MTOMAwareXMLSerializer(xmlWriter); serialize(mtomAwareXMLStreamWriter); } 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(); serialize(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 http://wso2.org/library/236 (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. thanks, Amila. 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] https://svn.apache.org/repos/asf/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMElementStreamWriter.java > > > > -- > Amila Suriarachchi, > WSO2 Inc. -- Amila Suriarachchi, WSO2 Inc. ------=_Part_123996_29782541.1185362384877 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline hi,

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 XMLStreamException;

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, OMAbstractFactory.getOMFactory());
        omText.internalSerializeAndConsume (this.xmlStreamWriter);
    }

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);
        currentOMElement.addChild(omText);
    }

so that it sets the omText correctly.

And the ADBDataSource class is look like this,

   public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException{
        MTOMAwareXMLStreamWriter mtomAwareXMLStreamWriter = new MTOMAwareXMLSerializer(xmlWriter);
        serialize(mtomAwareXMLStreamWriter);
    }

    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();
        serialize(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
http://wso2.org/library/236 (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.

thanks,
Amila.








On 7/24/07, Amila Suriarachchi <amilasuriarachchi@gmail.com> 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] https://svn.apache.org/repos/asf/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMElementStreamWriter.java


--
Amila Suriarachchi,
WSO2 Inc.



--
Amila Suriarachchi,
WSO2 Inc. ------=_Part_123996_29782541.1185362384877--