What are the ways to manipulate complex JAVA object returned from a JAVA service

hi,

i have a JAVA service which will return a complex JAVA object (the object has String, List, as well as other custom JAVA Objects)…

What are the best way to manipulate this type of object in the flow service ?

HTH.

chiew

This is how i did it:

  1. Defines an XML schema that matchs the complex JAVA object.

  2. Create a Document type based on the XML schema created in 1.

  3. Specifies the document type created in 2 as the output for the JAVA service.

  4. In the Java service, writes all the mapping code from the JAVA object to the document. (quite complicated…but managable)

  5. Now…which ever flow service that invokes this Java service will manipulate the document instead of the original JAVA object.

HTH.

chiew

P.S. Using documentToXMLString, i can easily convert the document to an XML string <– pretty handy.

Chiew,

To actually manipulate your complex objects you would need to add code to your java service to traverse your object hierarchy and construct an IData (document) that your service would put onto the pipeline. Then your Flow services could manipulate this data or transform it into other formats.

One technique that I have used in the past is to build methods that walk one of the objects (say a java List of customer objects) and convert that object into an Idata (document).

I put these helper services into “Source” area of the “Shared” tab in the java service editor. In the main part of the java service I use these helper services to process each part of the complex object and then assemble the resulting document or document lists into a single Idata document that can be returned for further processing.

In the past I tried to construct the IData to match the structure that I eventually wanted to return to my trading partner, but I think an easier approach it to make your document structure resemble the java object hierarchy and then perform any additional structural transformation using Flow. I guess the correct approach depends on how much java code you want to write to produce the document.

The WmSamples package contains some useful examples for walking and creating IData documents.

Mark

hi Mark,

Thanks for your input.

your comment -
>>To actually manipulate your complex objects you would need to add code >>to your java service to traverse your object hierarchy and construct an >>IData (document) that your service would put onto the pipeline. Then >>your Flow services could manipulate this data or transform it into other >>formats.

This is exactly what i did.

fyi…my JAVA service is just a wrapper…it invokes an external JAVA component (which i wrote and has a few thousands line of code).

But i find that defining an XML schema to represent the complex JAVA object is really the way to go.

HTH.

chiew

I agree that simple is best. So using JAXB, Castor, JDO or whatever have an easy way to convert to/from java/XML. Then import the auto-generated schema into IS and then you can use usually a simple java method such as ‘marshall/unmarshall’ to get the java object into XML. Then do a stringToDocument to get the IData rather than building up an IData object in java yourself.

Hmmm. I like this approach. Can you provide a code snippet?

In my case, I needed to use another java service to perform some additional processing on the java object to apply some business rules before handing it back to IS for transformation, so a schema representation would not have worked.

Mark

I use Castor to marshall a complex Java object into a XML representation. I create a wM document type from example XML (I would like to create a schema but I do not know how to create it with Castor) and use ‘xmlStringToDocument’ in order to fill the document with the data.

I am not sure if this solution is the best but it works for now.

We use databases which are accessed with a Java object-relational mapping tool (db tables are mapped to Java objects). I rather access data via the mapping layer than to hard-code JDBC-adapter-services in webMethods. The big problem is to get the data from Java objects into webMethods documents. I would love to have a build in webMethods service that does this for me. Integration of IData with standard Java applications is too complicated out of the box.

Does anyone know a good solution for this problem?

Ulf

Mark - I don’t see why the schema approach wouldn’t work in your case. In my mind the end result of applying all the business rules is to have an object with a number of values set. The schema would represent the ‘data object’. Usually the base class is auto-generated and then you can extend it to add your business rules.

Sorry I don’t have any code for this.

For Ulf - all I can suggest at this point if you just have an XML file is to use XMLSPY to generate a schema and then tweak the schema for things as repeated elements, etc. But there should be dbxml tools out there that would generate these schemas for you.

Will, you might be right. This was for a project I worked on for a customer last year. Another tool for the toolbag for the next time 'round.

-mdc