Invoking a Reference Operation

When you add a reference to a Spring component, TIBCO Business Studio adds following a field and accessor methods to the abstract component implementation. TIBCO ActiveMatrix injects the referenced object into the component implementation.

TIBCO Business Studio adds the following elements to the abstract component implementation:
  • SCA reference annotation import
  • A field that declares the referenced object
  • Accessor methods
The TIBCO ActiveMatrix platform injects the referenced object into the component implementation. For example, if you add a reference to port type DateManagerPT, the following code is added:
import org.osoa.sca.annotations.Reference;
@Reference(name = "DateManagerPT")
public void setDateManagerPT(DateManagerPT DateManagerPT) {
	this.DateManagerPT = DateManagerPT;
}

public DateManagerPT getDateManagerPT() {
	return this.DateManagerPT;
}
Note: When you pass an XMLBeans document object to a reference invocation, the object is passed by reference. Since the state of an object is not guaranteed across reference invocations, you cannot access the object after the reference invocation. If you need to access the object after the invocation, make a deep copy of the object using the copy method before you invoke the reference. For example, if you needed to access the req object after the call to getCurrentTime, make a deep copy of req as follows:
TimeRequestDocument req = TimeRequestDocument.Factory.newInstance();
req.setTimeRequest("America/Los_Angeles");
TimeRequestDocument reqcopy = (TimeRequestDocument)req.copy();
TimeResponseDocument time = getDateManagerPT().getCurrentTime(req);
System.out.println("The time in " + reqcopy.getTimeRequest() + " is " + 
  time.getTimeResponse());

Procedure

  • Add the statement getportType().operation. If the reference is configured for dynamic wiring, you must define a method to create an endpoint reference (see Creating an Endpoint Reference) and call the method before invoking the reference object. For information on wiring, see Static and Dynamic Wiring in Composite Development.

Example

The following code snippet demonstrates how to invoke the getCurrentTime operation on the reference configured for dynamic wiring with port type DateManagerPT:
setEPR(targetURI);
String time = currentTime.getTimeResponse();

resp.setHelloResponse(getJavaGreeting() + " " + name + "! "
	+ "The current time is " + time + ".");
return resp;