ServicesTabVWPEjbConsumer

Visual Web Consumer of Enterprise Java Beans from Services Tab

Modification History
Winston Prakash: Feb, 8 2007


Note: This is just sample or a starter document to start the discussion based on Services Tab Architecture. Does not correctly reflect the implementation details. Need to be re-written by the Service Type implementor. - Winston

This document applies only to VWP designer - Winston


Contents



Introduction

This document explains how the Visual Web Pack Service Consumer would consume a EJB (or a EJB Method) once it is Drag and Dropped from a EJBs Node in the Sevices Tab. VWP web page designer (here after just designer) is the primary receiving agent of the Drag and Drop. It could consume it directly or delegate the task to a Helper.

EJB Consumer

VWP web page designer could extract the EJB info from the DnD using the public Contract defined in the Enterprise Java Beans Public Contracts document. Instead it delegates the actual consumption task to a helper module. For EJB consumption the task is delegated to the raveejb module, which we would refer as EJB Consumer Helper.

Let us see an example on how the designer would consume the EJB dropped on to it. The only consumable object designer understands is BeanCreateInfoSet (a generic definition of consumable object holder defined by the VWP Design Time System). The designer could implement the required code to convert the DnD to an BeanCreateInfoSet. That means designer needs to understand the DnD contract defined by EJB Manager.

However, the preferred solution would be to use the Consumer Helper and pass on the DnD Transferable to it. The Consumer Helper would take the DnD and creates the BeanCreateInfoSet and gives it back to the designer. The advantage of this approach is, designer need not have to know about the DnD Contract nor the Service Meta data Contract to convert the DnD Transferable to a consumable object, but relies on the Consumer Helper to do the job.


EJB Consumer Helper

Since there can be multiple Consumer Helper modules to help consume DnD from Nodes of different Services in the Services Tab, designer need to interact with each of these Helpers, thus creating module dependencies. Since VWP Design Time System defines a single wrapper consumable object, designer could provide a public SPI for these helpers and then relies on NB lookup mechanism to get the implementors of this SPI. Out of the several possible Helpers, only one will understand the DnD transferable corresponding to EJB. One such Helper would be implemented in the raveejb module

Here is an Example interface that could be defined by the VWP designer

public interface DesignTimeTransferDataCreator {
    /** Gets <code>DisplayItem</code> for specified <code>Transferable</code>
     * @return <code>DisplayItem</code> or <code>null</code> */
    public DisplayItem getDisplayItem(Transferable transferable);
}

Note: DisplayItem is a super interface of BeanCreateInfoSet.

The raveejb Module can implement the VWP specific Service Helper and register it



  public final class EjbTransferDataCreator implements DesignTimeTransferDataCreator{
     public DisplayItem getDisplayItem(Transferable transferable){
       // Use the DnD contract to get the info about EJB Service
       // If the transferable is not understood (may not be a EJB service DnD)
       // return null
       // Use the Service Meta data contract to get EJB info
       DataFlavor supportedFlavor = EjbMetaDataTransfer.EJB_FLAVOR;
       if (transferable.isDataFlavorSupported(supportedFlavor)){
            transferData = transferable.getTransferData(supportedFlavor);
            EjbMetaDataTransfer.EjbInfo wsInfo =  
                (EjbMetaDataTransfer.EjbInfo) transferData;
            // Obtain the EJB descriptor  
            EjbDescriptor wsDesc = 
                (EjbDescriptor)wsInfo.getEjbDescriptor();
            // Now use EjbDescriptor as create the BeanCreateInfoSet
            return new return new EJBBeanCreateInfoSet(wsDesc);
        }
     }
   }


Note that, this Consumer Helper get the EJB information via the EJB Metadata Contract published by the EJB manager.


Adding EJB to project

An EJB can be added to a page bean, a session bean or an application bean by drag and drop the W/S or W/S method on to the designer or corresponding scoped bean in the application outline. When the very first EJB from a set is dropped into a web project, all the client jars and the wrapper jar in this EJB set will be added into the project navigator. But removing all the EJBs from the project will not cause the jars to be removed from the project automatically. The user can remove the jar manually from the project navigator if he or she wants.

When an EJB is dropped in the web application, an instance of the EJB wrapper class is created in the backing bean.

Access EJBs in backing beans

The web application uses the bean wrapper class to access the EJB's business methods.

  • For read-only data, the user can use the binding dialogs provided by the components to bind appropriate data providers to the JSF components.
  • For updating/deleting data, the user has to manually make calls to the business methods in the backing beans. Of course, the user can still manually call the business methods to retrieve data if that's what he or she wishes.

Binding EJB methods to components

Other than dragging and dropping an EJB into a web application, the user can also drag and drop methods which have read-only data providers associated it. We'll call those methods bindable methods since they can potentially be bind to JSF components. When the user drops the method on the designer canvas, an instance of the wrapper class and data provider for the method will be created in the backing bean. Just like dropping EJBs to the web application, the methods can also be dropped in different scope (i.e. Request, session and application). If the user drops the method onto a JSF component, then VWP will try to bind the data provider instance for the method to the JSF component.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo