Boka_Banana
Boka_Banana

Reputation: 31

TIBCO BW : XML To Java Palette

I am trying to understand the concept of XML To Java. I am not understanding when or why is it actually needed in my process definition.
Does it have anything to do with an element being in the repeatable state in my schema or no?

This is the error I keep facing in the input tab.

BW-JAVA-100056 configuration error the java class [javax.xml.namespace.QName] does not contain a default constructor or a constructor with no argument.
For XML to JAVA conversion operation, the [Process.DemoBillSVC.objects.maintainTestCase] java class must be comprise only of classes with default constructors

Thanks in advance :)

Upvotes: 1

Views: 1809

Answers (1)

BusinessWorker
BusinessWorker

Reputation: 21

The XML To Java activity is used to convert XML documents to Java Objects. For a Java class to be compatible with this activity, the class has to

  • have a default constructor with no arguments
  • implement the java.io.Serializable interface

BusinessWorks will then parse the class to identify the various fields based on the getter and setter methods available in the class. These fields will then appear in the Input tab of the activities properties tab. The Schema to handle the XML are automatically created and can be found in the projects Schemas folder.

It is useful if you want to pass data you have in your process to a Java method that accepts a Java Object that does not map well to a primitive type like a String. For e.g. if you have a Java method that you wish to call from BusinessWorks called addPerson:

public void addPerson(Person person){....}

Then you would also have a Person class that might look something like

package org.initrode
public class Person implements java.io.Serializable{
  //Needs to implement Serializable
  String name;
  String address;
  public Person(){
    //Public default constructor without arguments
  }
  public void setName(String name){
    this.name = name;
  }
  public String getName(){
    return this.name;
  }
  public void setAddress(String address){
    this.address= address;
  }
  public void getAddress(){
    return this.address;
  }
}

Now you could use the Java To XML activity with the Person class above to initialize a Person object with values you might have retrieved from other activities in the process (REST, JDBC, File, etc.,). And then map the output of this activity to the input of the Java Invoke activity.

If you have existing code you don't wish to rewrite in BW, this is a good way to do it. If your classes don't have default constructors or implement Serializable, it is sometimes easier and faster to write wrapper objects and methods than rewrite entire the applications business logic. Hope this helps.

Upvotes: 2

Related Questions