Rich Scheuerle
IBM Web Services
Apache Axis2 ([EMAIL PROTECTED])
512-838-5115 (IBM TL 678-5115)
"Amila Suriarachchi" <[EMAIL PROTECTED]> wrote on 08/13/2007
09:10:10 AM:
>
> On 8/10/07, R J Scheuerle Jr <[EMAIL PROTECTED]> wrote:
> Rich Scheuerle
> IBM Web Services
> Apache Axis2 ([EMAIL PROTECTED])
> 512-838-5115 (IBM TL 678-5115)
>
> "Amila Suriarachchi" <[EMAIL PROTECTED]> wrote on
> 08/09/2007 11:02:18 PM:
>
> Thanks for the questions, Amila.
> > hi,
> > what type of object you expect in the
> > public Object getObject();
> >
> > method in OMDataSourceExt interface.
>
> The getObject() allows access to the object backed by the
OMDataSourceExt.
> See the new CharArrayDataSouce as an example. It returns the char[].
>
> >
> > When building the OMElement currently OMDataSource calls to
> > getReader() to get the XmlStreamReader and creates the
> >
> > OMElement from it. Can I directly send the OMElement (already build)
> > using that interface?
>
> Is this the scenario ?
> 1) There is a OMSourcedElement backed by an OMDataSource.
> 2) A query is made on the OMSourcedElement that causes a
> forceExpand. (For example, getFirstChild() is called on the
> OMSourcedElement.)
> 3) The OMSoucedElementImpl.forceExpand() method calls
> OMDataSource.getREader() and uses it to build the OM sub-tree.
>
> yes.
>
> I believe your suggestion is:
> A) During forceExpand() invoke OMDataSourceExt.getObject().
>
> A1) If the returned Object is an OMElement, then
> * Add the attributes/namespace of the OMElement to the
OMSoucedElement.
> * Add the children of the OMElement to the OMSoucedElement.
> (This effectively eliminates the XMLStreamReader parse).
>
> A2) If the returned Object is not an OMElement, then fallback to
> the old logic.
>
> I think this would be a valuable follow-on to the original
> contribution. Comments ?
>
> I am not much familiar with the Axiom inside but I think this is what I
need.
>
> Let me explain this a bit.
>
> ADBDatasource class is like this.
>
> public abstract class ADBDataSource implements OMDataSource {
> protected QName parentQName;
> private ADBBean bean;
>
>
> protected ADBDataSource(ADBBean bean, QName parentQName) {
> this.bean = bean;
> this.parentQName = parentQName;
> }
>
> public void serialize(OutputStream output, OMOutputFormat
> format) throws XMLStreamException {
> XMLStreamWriter xmlStreamWriter = StAXUtils.
> createXMLStreamWriter(output);
> serialize(xmlStreamWriter);
> xmlStreamWriter.flush();
> }
>
> public void serialize(Writer writer, OMOutputFormat format)
> throws XMLStreamException {
> serialize(StAXUtils.createXMLStreamWriter(writer));
> }
>
> 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();
> }
>
> }
>
> getReader method expect an XMLStreamReader. So what ADBDataSouce
> does is it creates an OMElement using the MTOMAwareOMBuilder and
> serialize method. Then gets the XMLStreamReader from this.
>
> So In this process Two OMElements are created (1. OMElement axiom
> created using Xmlstream reader and intermediate OMElement created by
> ADBDataSource. So if I can pass the created OMElement directly we
> have to create only one OMElement.
So there seems to be two patterns here:
1) Some OMDataSources build a complete OM tree as a side effect of
getReader() (e.g. ADBDataSource)
2) Some DataSources don't require an intermediate OM Tree (e.g.
ByteArrayDataSource)
One solution is to add a new method to OMDataSourceExt.
/**
* Returns either an XMLStreamReader or fully built OMElement.
* For some OMDataSource implementations, it is more efficient for the
datasource to return
* an XMLStreamReader. In other OMDataSourceImplementations it is
faster to return
* a fully built OM tree.
* @return XMLStreamReader or OMElement
*/
public Object read();
Then change OMSourcedElement.forceExpand() to handle either the
XMLStreamReader or OMElement case.
(For the OMElement case, the children and attributes would be copied to the
OMSourcedElement tree)
Your ADBDataSource would be coded as:
public Object getReader() throws XMLStreamException {
MTOMAwareOMBuilder mtomAwareOMBuilder = new MTOMAwareOMBuilder();
serialize(mtomAwareOMBuilder);
return mtomAwareOMBuilder.getOMElement();
}
>
> Amila.
>
> >
> > Amila.
>
> >
>
> > On 8/9/07, R J Scheuerle Jr < [EMAIL PROTECTED]> wrote:
> > I have added some much needed upgrades to
OMDataSource/OMSourcedElement.
> >
> > Here is the JIRA with the discussion and code/test patch.
> > https://issues.apache.org/jira/browse/WSCOMMONS-232
> >
> > These changes will make it easier for users to access and plug in
> > OMDataSource objects.
> > It also provides a public interface for OMSourcedElement.
> >
> > The changes will not affect any existing code that relies on
> > OMDataSource or OMSourcedElement.
> >
> > Please reply with your comments. I will commit this code to Axiomon
Friday.
> >
> > Thanks,
> >
> > Rich Scheuerle
> > IBM Web Services
> > Apache Axis2 ([EMAIL PROTECTED])
> > 512-838-5115 (IBM TL 678-5115)
> >
> >
> >
> > --
> > Amila Suriarachchi,
> > WSO2 Inc.
>
>
>
> --
> Amila Suriarachchi,
> WSO2 Inc.