File name: tsca_sdo_use_helpercontext_sca.html
Accessing default HelperContext objects in SCA applications
A Service Component Architecture (SCA) application can
access a Service Data Objects (SDO) 2.1.1 HelperContext object using
a DefaultHelperContext annotation.
Before you begin
Install Feature Pack for SCA Version 1.0.1 and enable SDO.
Instructions on enabling the SDO feature are in the installation topics
for your operating system.
Read SDO data binding for SCA applications to
better understand how to work with SDO in SCA Java clients and implementations.
Develop
one or more SCA composites that use SDO following a top-down or bottom-up
approach.
About this task
This topic describes how to create and access SDO HelperContext
in SCA applications. For information about accessing SDO HelperContext
in non-SCA applications, see Creating
and accessing SDO HelperContext objects.
Because the
SCA run time manages the HelperContext objects and identifiers when
using SDO in SCA applications, the method used to create and access
SDO HelperContext in SCA applications is different from that used
in non-SCA applications. An SCA application can access SDO HelperContext
using a DefaultHelperContext annotation, @DefaultHelperContext.
You
can access the default HelperContext programmatically in a Java™ or Java Platform, Enterprise
Edition (Java EE) component implementation type. You cannot access
the default HelperContext programmatically in a Spring component implementation
type.
Procedure
- Add a public or protected field or setter method of type commonj.sdo.helper.HelperContext to
your Java implementation class.
The method can either
be a Java component implementation, such as <implementation.java>,
or a Java EE implementation class, such as an EJB implementation class.
- Annotate the field or setter method with @com.ibm.websphere.soa.sca.sdo.DefaultHelperContext.
The following example shows a field annotation:
@DefaultHelperContext
protected HelperContext myDefaultHC;
The following example
shows an annotation of a setter method:
private HelperContext helperContext;
@DefaultHelperContext
public void setHelperContext(HelperContext hc) {
this.helperContext = hc;
}
- Use the injected HelperContext in your implementation logic.
When your component starts, the container will inject this
field, or call this setter, with the default HelperContext instance
for this component so you can use it in your implementation.
import com.ibm.websphere.soa.sca.sdo.DefaultHelperContext;
import commonj.sdo.helper.HelperContext;
import org.osoa.sca.annotations.Service;
…
// This is a Java implementation of an SCA component
@Service(AccountService.class)
public class AccountServiceImpl implements AccountService {
private HelperContext helperContext;
@DefaultHelperContext
public void setHelperContext(HelperContext hc) {
this.helperContext = hc;
}
@Override
public DataObject accountMethod(DataObject account, String name) {
// ….
// Get dataFactory to create return object
DataFactory dataFactory = this.helperContext.getDataFactory();
DataObject retVal = dataFactory.create("http://myns", "Response");
retVal.set(..) // … Set properties on return object
return retVal;
}
Results
You have written code that accesses the default HelperContext.
What to do next
Develop one or more SCA composites that use SDO following
a bottom-up or top-down approach.
In this information ...
| IBM Redbooks, demos, education, and more(Index)
Most of the following links will take you to information that is not part of the formal product documentation and is provided "as is." Some of these links go to non-IBM Web sites and are provided for your convenience only and do not in any manner serve as an endorsement by IBM of those Web sites, the material thereon, or the owner thereof.
|
|
