IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  inserting a JDOM-Object

    Posted Tue October 18, 2005 03:58 PM

    Hello out there,
    I have some questions about, how to inserting JDOM-Objects from servlets into the database. First I created a JDOM-Object:

    import org.jdom.*;
    Document mydoc = new Document ( new Element ("Anwender") );
    Element root   = mydoc.getRootElement();
    Element erstesElement = new Element ("vorname").setText(vorname);
    root.addContent( erstesElement );
    Element zweitesElement = new Element ("nachname").setText(nachname);
    root.addContent( zweitesElement );
    Element drittesElement = new Element ("wohnort").setText(wohnort);
    root.addContent( drittesElement );

    Then I buildet a connection to a database ( this works, no need to dump here ) and a accessor-Object.

    TXMLObjectAccessor xmlObjectAccessor = connection.newXMLObjectAccessor(
    TAccessLocation.newInstance( "ino:etc" ),
    TJDOMObjectModel.getInstance() );

    But when I try to fill this accessor with my JDOM-Object…

    xmlObjectAccessor.insert( mydoc );


    it doesn’t work.
    Do I have to build a TXML-Object first and commit it to the accessor?
    How to do this?

    Gruss Christian


    #webMethods-Tamino-XML-Server-APIs
    #API-Management
    #webMethods


  • 2.  RE: inserting a JDOM-Object

    Posted Wed October 19, 2005 10:42 AM

    It doesn’t work you mean it can’t even compile?
    TXMLObjectAccessor.insert(TXMLObject)

    Yes you should use a TXMLObject. Read it from a File, URL, Stream, Reader, etc. In the following example I get a TXMLObject instance and then read it from a stream(piped). Using this way I know for sure what model is used.

    
    PipedInputStream pin=new PipedInputStream();
    PipedOutputStream pout=new PipedOutputStream(pin);
    //Write your document to pout using a thread....
    TXMLObject xmlOb = TXMLObject.newInstance(TJDOMObjectModel.getInstance());
    xmlOb.readFrom(pin);
    //Remember to close streams

    The wrong thing about the API4J is that all the documents always come from a stream or similar. So doesn’t matter wich technique you use to build your document, you should also care about TXMLObjectModel. It doesn’t reuse your data.

    Can some one explain big differences using different XMLObjectModels and consecuences on XMLObjects.


    #webMethods-Tamino-XML-Server-APIs
    #webMethods
    #API-Management


  • 3.  RE: inserting a JDOM-Object

    Posted Fri October 21, 2005 08:54 PM

    Yes this works now, thank you.

    I made this: create a JDOM-Object:

    Document mydoc = new Document ( new Element ("Anwender") );
    Element root   = mydoc.getRootElement();
    Element erstesElement = new Element ("vorname").setText(vorname);
    root.addContent( erstesElement );
    Element zweitesElement = new Element ("nachname").setText(nachname);
    root.addContent( zweitesElement );
    Element drittesElement = new Element ("wohnort").setText(wohnort);
    root.addContent( drittesElement );

    then created a TXMLObject and fill it with the JDOM.

    TXMLObject tobj = TXMLObject.newInstance ( mydoc);

    … and give this object the accessor:

    xmlObjectAccessor.insert( tobj );

    But this is a littles bit “pedestrian”! I would prefer a possibility where I can create a TXMLObject and fill it with elements.

    Gruss Christian


    #API-Management
    #webMethods-Tamino-XML-Server-APIs
    #webMethods


  • 4.  RE: inserting a JDOM-Object

    Posted Mon October 24, 2005 02:07 PM

    I haven’t found a way to do so. As I say that’s one of the bad things in the API4J in Tamino. There is no way to access the underlaying Stream,DOM,JDOM behind the XMLObject.
    XMLObject is only for the transaction not for data manupulating.


    #webMethods
    #webMethods-Tamino-XML-Server-APIs
    #API-Management


  • 5.  RE: inserting a JDOM-Object

    Posted Wed October 26, 2005 02:43 PM

    I just discover that you can ‘reuse’ your DOM or JDOM. There’s a way to create a TXMLObject. I don’t know if you can still edit the JDOM or DOM, in fact I think no.
    Use Method TXMLObject.newInstance(Object object)
    As described in JavaDoc
    Factory method, creates a TXMLObject instance from the given object instance. The type of the input object determines the object model for the TXMLObject instance returned. For example, if the input object is an instance of org.w3c.dom.Element or org.w3c.dom.Document, the DOM object model is taken. If the input element is an instance of org.jdom.Element or org.jdom.Document, the JDOM object model is taken. The XML content of the input object is taken as the XML content of the TXMLObject instance.

    Parameters:
    object - an object representing the XML document. 
    Returns:
    TXMLObject that wraps the given object.
    

    #webMethods-Tamino-XML-Server-APIs
    #webMethods
    #API-Management