How to pass Java object references between two Java code activities.
book
Article ID: KB0088517
calendar_today
Updated On:
Products
Versions
TIBCO ActiveMatrix BusinessWorks
-
Not Applicable
-
Description
Resolution: Description =========== If you want to pass a Java object between two activities, you can use the Object Reference type. For example, you may need to pass a Java object in following scenarios:
- Java Code activity to Java code activity. - XML to Java activity to Java code activity. - Java to XML activity to XML to Java activity.
Environment =========== All
Resolution ========== You need to create the Java object in the first activity which has an output parameter of object type. The second activity should have an input parameter of object type. Then you can drag and drop the output from the first activity to the input of the second activity.
The following is an example using Java code to Java code. The source code defines a Customer class with some attributes. The source code is:
Customer.java
package source;
import java.util.*;
public class Customer implements java.io.Serializable { int id; String name; int age; public Customer(){ } public void setId(int id) { this.id = id; } public void setAge(int age) { this.age = age; }
public void setName(String name) { this.name = name; } public int getId(){ return this.id; } public int getAge() { return this.age; } public String getName(){ return this.name; } }
The first Java code creates an instance of the Customer class. The code looks like:
Customer customer_obj = new Customer(); //create an instance customer_obj.setName("This is your name"); //set name for this customer instance out_obj = customer_obj; //the instance object is outputed
customer_obj is passed to the second Java code. It displays the customer's name. The code is:
Customer customer = (Customer)in_obj; //convert the input object to Customer type System.out.println("customer name is: " + customer.getName());
To run the example, you need to compile Customer.java in jdk, create a jar file and place it in BW and designer claspath. Project and the JAR file are attached. (Filenames: ObjectReference.zip, customer.jar).
Issue/Introduction
How to pass Java object references between two Java code activities.
Attachments
How to pass Java object references between two Java code activities.
get_app
How to pass Java object references between two Java code activities.
get_app