Creating a New EJB3 Control

Enterprise JavaBean (EJB) controls make it easy for you to use an existing, deployed session EJB from within an application. To create an EJB3 control, you must first make sure that the EJB's (local or remote) business interfaces are available to your application.

Making EJB Interfaces Available to Your Application

Before you can create a EJB3 control, the EJB's local or remote interfaces must be known in your application. If the EJB is not part of the application, you make it available by adding the EJB's JAR file to your Workshop application. While the complete EJB JAR file allows Workshop to access the EJB's interfaces, the only classes actually required are the EJB's remote interface classes and any other classes used externally by the EJB (for example, as method parameters or method return types). The EJB compiler ejbc is capable of producing a client JAR that will serve this purpose.

Creating a New EJB3 Control

To create a new EJB3 control:

  1. Locate or create the package (folder) where you want to create the EJB3 control. This can be a
    package in a utility project, dynamic web project, or web service project.
  2. Right-click the package and choose New > Interface.
  3. Assuming that you name the control class MyCtrl, then copy and paste the following code into the interface file:
        import org.apache.beehive.controls.api.bean.ControlExtension;
        import com.bea.control.SessionEJB3Control.EJBLookup;
      	  
        @ControlExtension
        @EJBLookup(jndiName="some_value")
        public interface MyCtrl extends <EJB3_business_intf>, com.bea.control.SessionEJB3Control
        {
        }

To insert the EJB3 control into a web service, web application or another control, see Using an EJB3 Control.

Modifying EJB3 Controls

Notice that the control simply extends the EJB's interfaces. Unlike some other controls, the EJB3 control's class definition does not contain method declarations that invoke the EJB's methods. In other words, the EJB3 control only serves to reference the EJB and to expose its methods, and cannot be used to limit access to, or modify, these methods.

To see the EJB methods exposed by the EJB3 control, insert an EJB3 control in a web service or page flow.

When you modify the EJB's methods or add additional methods to the interfaces that the EJB3 control references, you do not need to modify the EJB3 control (but you must rebuild the EJB). When you modify the name of the used interfaces, the JNDI name (if the EJB3 control uses the jndi name), or the bean name or EJB JAR name (if the EJB3 control uses a ejb-link), you must modify the EJB3 control to reflect these changes.


Still need help? Post a question on the Workshop newsgroup.