5. Components of an Enterprise Bean Components of an enterprise bean The bean class The EJB object The Remote interface Deployment Descriptors The Home Interface The EJB-jar file The Home object The Local Interface The LocalHome Interface
6. The Bean class Well-defined interface The Bean Bound Communicates to the client through the interface Container Works in any container with the help of these interfaces public interface javax. ejb. EnterpriseBean extends java.io.Serializable { } Once the above interface is implemented, the bean class is confirmed
7. The EJB Object Client Code EJB Container/Server 1 .Calls a method 4.Returns method to client The container is the middleman between the client and the bean. It manifests itself as a single network-aware object. This network-aware object is called the EJB Object Home Object EJB Object 3. Returns the Method Enterprise Bean Instance 2. Delegates method to bean
8. The Remote Interface Remote Interfaces derived from javax.ejb.EJBObject Business Methods Define Perform Functionality of the bean javax.ejb.EJBObject public interface java.rmi.RemoteInterface extends javax.ejb.EJBObject { public abstract javax.ejb.EJBHome getEJBHome() throws java.rmi.RemoteException; }
11. The Home Interface Home Interface Find EJB Objects Create EJB Objects Destroy EJB Objects EJB specifies certain methods that the home interface has to support. These methods are defined in the javax.ejb.EJBHome public interface javax.ejb.EJBHome extends java.rmi.Remote { public abstract EJBMetaData getEJBMetaData() throws java.rmi.RemoteException; }
12. The Methods in EJB Home getEJBMetaData(): It is this method that gets information about the beans that are being worked on remove(): This method destroys an EJB object The methods that fall under the EJB Home are
13. The Home Object Client Code Home Object EJB Object Enterprise Beans EJB Container/Server 1. Requests new EJB Object 3. Returns the objects 2. Creates new object
14. Deployment Descriptors Deployment Descriptors Life cycle requirements and Bean management Persistence Requirements Transaction Requirements Security Management Classes that form the bean Home Interface Remote Interface EJB Server
15.
16.
17. Writing a Session Bean The six methods to be followed while writing a session bean setSessionContext(SessionContext ctx) ejbCreate() ejbPassivate() Business methods ejbRemove() ejbActivate()
18. The setSessionContext (SessionContext ctx) Container setSessionContext() Bean public class theBean implements SessionBean { private SessionContext ctx; public void setSessionContext(SessionContext ctx) { this.ctx=ctx; } . . . . . . . } Session Context (Gateway) Associates
19.
20. Using JNDI to lookup Home Objects Home Object Enterprise beans EJB Object Client JNDI Naming Service 1. Retrieve Home Object 3. Creates an EJB Object 5. Return Object reference 6. Invokes business methods EJB Container/Server 4. Create EJB Object 2. Returns reference to the home object 7. Delegates request to bean
21. Steps in accessing Home Objects The steps followed by the client code to get a reference The setting up of the Environment Destroying the EJB Object Calling a Method Creating an Object Retrieving the home objects The Initial Context
25. Creating the jar file Welcome.class Deployment Descriptors Welcome.jar Welcomebean.class Welcomehome.class A jar file is created to package the three java files, namely the bean class, the home interface and the remote interface . The XML files Namely ejb-jar.xml and jboss.xml are also present in the jar file.
26.
27. Accessing from Client side Possible Clients JNDI lookup create() Ordinary JavaBean Enterprise JavaBean JSP Page Servlet Applet Enterprise JavaBean Home Object EJB Object Business Methods