Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop SCA composites > Use existing Java EE modules and components as SCA implementations > Use SCA enhanced Java EE applications as SCA component implementations


Use SCA annotations with session beans

Use Java annotations for Service Component Architecture (SCA) to identify existing Java EE components, such as session beans, as SCA components that are a part of an SCA composite.

Identify and obtain the session beans that represent your business logic to enable within an SCA environment.

The SCA programming model supports Java EE integration. As a result, you can take advantage of SCA annotations to enable Java EE web components such as session beans to consume SCA services. By using Java annotations that apply to SCA, you can enable existing session beans to be recognized as an SCA component and participate in an SCA composite. Within Java EE environments, sessions beans encapsulate business logic to manage security, transactions, and remotable interfaces. Because service components within SCA environments play a similar role, you can take advantage of the capability to use session beans as a service component implementation in a Java EE environment.

Any session bean that serves as the implementation type of an SCA service component can use annotations to obtain an interface to the SCA services that are wired to the component by the SCA assembly. We can also use annotations when to obtain the value of a property using the @Property annotation, to inject a handle to the SCA component context using the @Context annotation or to obtain the component name using the @ComponentName annotation. When using SCA annotations, you must apply the injection using annotations after the session bean instance is created, but before invoking business methods on the bean instance.

For a list of supported annotations for session beans, see the SCA specifications and APIs documentation.


Procedure

  1. Add SCA annotations to the components that you want within your session beans to enable the component to be recognized as an SCA component. Based on your needs, use the supported annotations to inject SCA information such as context or component name into your session beans.
  2. Edit the application.composite in the META-INF directory of the Java EE JAR file.

    Define a component within the application.composite file whose implementation is defined by an implementation.ejb element and specifies a session bean within the module. We can define multiple components, each with an implementation.ejb link that points to a session bean.

    Because message-driven beans and session beans are enterprise beans, you can uniquely refer to both bean types in an ejb-link element.

    The implementation.ejb element is used to declare a service component that is implemented by the session bean component. The component contains information for the annotations.

    To configure this component implementation, use the following schema:

    <implementation.ejb ejb-link="
    <ejb_link_name>"/>
    

    The enterprise bean that serves as the component implementation is uniquely identified by the <ejb_link_name> attribute. The format of the <ejb_link_name> attribute is identical to the format of the ejb-link element in a Java EE deployment descriptor.

    If the Java EE archive that contains the composite file is an application EAR file, multiple session beans might have the same name. In this case, the value of the ejb-link element must be composed of a path name. The path name specifies the ejb-jar that contains the referenced enterprise bean with the value of the ejb-name of the referenced enterprise bean appended and separated from the path name with the # symbol. The path name is relative to the root of the EAR file. For the case where the Java EE archive is a JAR file for the EJB module, omit the path name.

    For example, you can have a JAR module that has the following component defined in the application.composite file:

    <component name="AnnotationTest">
    <implementation.ejb ejb-link="SCA_JEE_Injection.jar#AnnotationTest"/>  
    <property name="property" type="xsd:string">Right
    </property>
    
    
    <reference name="getServerDateReference" target="GetServerDateServiceComponent">
    <interface.java interface="sca.injection.test.GetServerDateService"/>
    
    </reference>
    
    </component> 

    In this example, the session bean, AnnotationTest, is consuming an SCA service exposed by the GetServerDataServiceComponent reference.

    The AnnotationTest session bean includes the @Property, @Reference, @ComponentName, and @Context annotations:

    import javax.ejb.Stateless;
    
    import org.osoa.sca.ComponentContext;
    import org.osoa.sca.annotations.ComponentName;
    import org.osoa.sca.annotations.Context;
    import org.osoa.sca.annotations.Property;
    import org.osoa.sca.annotations.Reference;
    
    import sca.injection.test.GetServerDateService;
    /**
    * Session Bean implementation class AnnotationTest
    */
    @Stateless
    public class AnnotationTest implements AnnotationTestRemote, AnnotationTestLocal {
    
    
    @Context protected ComponentContext myContext;
    @ComponentName String myCompName;
    @Property protected String property;
    @Reference GetServerDateService getServerDateReference;
    
    @Reference
    GetServerDateService referenceDefault;
    
    /**
    * Default constructor.
    */
    public AnnotationTest() {
    // TODO Auto-generated constructor stub
    }
    
    public String getServString(){
    GetServerDateService svc = myContext.getService(GetServerDateService.class, "getServerDateReference");
    return svc.getString();
    }
    
    public String getProperty(){
    return property;
    }
    public String getComponentName(){
    return myCompName;
    }
    public String getReferenceDefault() {
    if ( referenceDefault == null )
    return null;
    else
    return referenceDefault.getString();
    }
    
    }
    


Results

You now have SCA-enabled Java EE session beans that take advantage of the SCA programming model.


What to do next

Deploy the components to a business-level application.
Ways to install enterprise applications or modules
Create SCA business-level applications
Start business-level applications
Use SCA annotations with message-driven beans
Use existing Java EE modules and components as SCA implementations


Related


SCA annotations
Service Component Architecture specifications and APIs

+

Search Tips   |   Advanced Search