EJB
1.1 UNDERSTANDING THE EJB ARCHITECTURE
There should be a tight coupling between the Web Tier and the EJB Tier.
This is accomplished by the IService and the ServiceImpl.
All the EJB calls must be in the IService interface. These methods in the Interface must be implemented in the ServiceImpl class.
The constructor of the ServiceImpl, gets the handle to the remote through the BusinessServiceFactory and the ServiceLocator classes. The ServiceLocator gets the handle through the JNDI name. ServiceLocator looks up and reads the services-config.xml file and retrieves the JNDI Name of the Services corresponding to the name. From the JNDI name it gives the handle to the EJB. If the handle is in cache, then it is returned from cache. Otherwise, a new handle is created. This handle is used by the rest of all methods to contact the EJB Tier (Façade). Façade gives the handle to the FacadeEJB.
The EJBHelper will help to create handles to the LocalEJBs. There can be more than one LocalEJB. Every ‘LocalEJB’ will have its corresponding ‘Local’. The EJBHelper gets a handle to the Local which in turn gives a call to the LocalEJB. Every method in the FacadeEJB gets the handle to the appropriate Local via the EJBHelper. And then corresponding call is made with this handle. There can also be many Helper classes for every LocalEJB so that the functionalities are split up and diversified.
When the number of EJB methods is finite or limited, we need not go for LocalEJB. The functionalities can b accomplished by having one EJB. In that case, the Façade becomes the Remote and all the functionalities are implemented in the EJB(only one created).
The LocalEJBs and the Helper classes can have private methods for simplification of the work to be performed. These private methods are explicitly for those classes that implement.
Flow is like this.
IService à ServiceImpl à Façade à FacadeEJB à Local à LocalEJB à Helper Classes (if any)
Façade pattern is followed when the redirection of EJB calls are required.
There can be more than one LocalEJb. Different calls can be in different Ejbs. Different LocalEJBs can be created for different purposes. From FacadeEJB, the calls can be made to the appropriate EJB.
There can be many EJB calls. Instead of mounting all the EJB calls, in one Local EJB, they can be split and more LocalEJBs and helper classes can be created.
1.2 CREATION OF ISERVICE
Create a new Java interface in util package named as I
Ex.
public interface IWorkFlowService
extends IService
{
}
1.3 CREATION OF SERVICEIMPL
Create a new Java class in web package named as
Ex. Text written in
public WorkFlowServiceImpl()
{
//Get the instance of Service Locator
_serviceLocator = ServiceLocator.getInstance();
//Initialize the service Locator
try
{
_serviceLocator.init();
}
catch (ServiceLocatorException e2)
{
e2.printStackTrace();
}
try
{
//Get the handle to the Home
_workflowHome =
(WorkFlowFacadeHome) _serviceLocator
.getRemoteHome(WorkFlowServiceImpl.SERVICE_NAME,
WorkFlowFacadeHome.class);
}
catch (ServiceLocatorException e1)
{
if (_log.isDebugEnabled())
{
_log.debug("Service Exception: Service" +
" not located");
}
e1.printStackTrace();
}//handle Exception
//Obtain the Remote Interface from the Home Reference
try
{
_workflowRemote = _workflowHome.create();
}
catch (RemoteException e)
{
// e.printStackTrace();
//To be Replaced with Logging Code
}
catch (CreateException e)
{
// e.printStackTrace();
//To be replaced with Logging code
}
}
1.4 CREATION OF FACADE
Create a new Java class in the ejb package named as
Copy the code from the existing UserFacade and paste it in the newly created class. Change the name of the class. Except for the EJB methods, remove all the other methods.
All your methods in Facade must throw RemoteException.
Ex.
public ProcessTO fetchAllSteps()
throws RemoteException,WorkFlowException;
1.5 CREATION OF FAÇADE EJB
Create a new Java class in the ejb package named as
If you need to create LocalEJBs, then do the following. If you need to go for ServiceDelegates go to section 1.10.
1.6 CREATION OF LOCAL
Create a new Java class in the ejb package named as
Copy the existing code from the UserLocal to the newly created class. Change the name of the class. Remove all the methods.
1.7 CREATION OF LOCAL EJBs
Create a new class in the ejb package named as
1.8 CREATION OF FAÇADE HOME
Create a new class in the ejb package named as
Ex.
public WorkFlowFacade create()
throws RemoteException, CreateException;
1.9 CREATION OF EJBHELPER
Create the Java class in the ejb package named as
Copy the code from UserEJBHelper and paste it. Change the name of the newly created class. Modify the existing method appropriately.
Ex.
localHome = (WorkFlowLocalHome)
ServiceLocator.getInstance()
getLocalHome(WorkFlowConstants.
WORKFLOW_LOCAL_SERVICE);
Note: WorkFlowConstants is a constants file created in util package.
1.10 CREATION OF META-INF, ejb-jar.xml and weblogic-jar.xml
Create a new folder under the ejb package “META-INF”.
Create a new XML file named as weblogic-jar.xml.
Copy the code in weblogic-jar.xml of ejb package of User module.
Paste it in the newly created xml file. Change the entries in the xml file, for the EJB being created by replacing the UserLocalEJB entries and remove the entries for TeamLocalEJB.
Ex.
FACADEEJB
WorkFlowFacadeEJB
WorkFlowFacadeEJB
LOCALEJB
WorkFlowLocalEJB
WorkFlowLocalEJB
Create a new XML file named as ejb-jar.xml
Copy the code in ejb-jar.xml of ejb package of User module.
Paste it in the newly created xml file. Change the entries in the xml file, for the EJB being created by replacing the UserLocalEJB entries and remove the entries for TeamLocalEJB.
Create 2 new
Ex.
FACADEEJB
WorkFlowFacadeEJB
com.gm.pqms.domain.workflow.ejb.WorkFlowFacadeHome
com.gm.pqms.domain.workflow.ejb.WorkFlowFacade
com.gm.pqms.domain.workflow.ejb.WorkFlowFacadeEJB
Stateless
Bean
LOCALEJB
WorkFlowLocalEJB
com.gm.pqms.domain.workflow.ejb.WorkFlowLocalHome
com.gm.pqms.domain.workflow.ejb.WorkFlowLocal
com.gm.pqms.domain.workflow.ejb.WorkFlowLocalEJB
Stateless
Bean
Open the BusinessServiceFactory.java in arch.util package for editing. Add a new constant to the existing constants for
Ex.
public static final String WORKFLOW_SERVICE = "WORKFLOW_SERVICE";
Add a new entry in the file for ServiceImpl as follows .
Ex.
classMap.put(BusinessServiceFactory.WORKFLOW_SERVICE, "com.gm.pqms.domain.workflow.web.WorkFlowServiceImpl");
1.11 MODIFICATION OF EXISTING XML FILES
Open build.xml in WebRoot/WEB-INF package for editing.
Add a new
Ex.
Open application.xml in the same package for editing.
Add a new entry
Ex.
Open service-config.xml file in the arch.util package for editing.
Add a new entry for the ejb created.
Ex.
-- END --
P.S : Every method in the FacadeEJB must be included in IService, ServiceImpl, Façade, FacadeEJB, Local and LocalEJB.
Tuesday, November 6, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment