Presentation is loading. Please wait.

Presentation is loading. Please wait.

Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake

Similar presentations


Presentation on theme: "Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake"— Presentation transcript:

1 Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake kwickramanayake@virtusa.com

2 creating competitive advantage JavaBeans vs Enterprise JavaBeans l Enterprise JavaBeans is a framework for building and deploying server-side Java components l JavaBeans is a framework for client-side Java components l Conceptually related because both are components l The specifications are different l The specifications do not build on each other or rely on each other

3 creating competitive advantage What’s in the EJB Specification ~200 Pages of technical material for EJB vendors l Goals for the Release l Roles and Scenarios l Fundamentals (Scope of EJB) l Session and Entity Beans l Transactions, Exceptions, Distribution l EJB Bean and Container Responsibilities l API Reference EJB Vendors Have to do all the WORK

4 creating competitive advantage Enterprise EJB Scenario ClientsWeb Server EJB Application Server Existing Enterprise Middleware CICS Programs SAP Modules Browser Application Servlet Shopping Cart Credit Card Inventory EJB Server EJB Container Databases

5 creating competitive advantage l Bean Class is written by the developer l EJBHome and EJBObject interfaces and classes control access to the Bean class l Deployment Descriptor and MANIFEST describe security and transactional characteristics of the Bean Written by Developer Generated at Deployment Generated at Development EJB Server EJB Container EJBHome Interface EJBHome Interface Deployment Descriptor EJBObject Interface EJBObject Interface EJBHome Class EJBHome Class EJBObject Class EJBObject Class EJB Class Manifest An inside look at the various components of EJB

6 creating competitive advantage EJB Server EJB Container EJBHome Interface EJBHome Interface EJBHome Class EJBHome Class EJBHome Interface and Class l Used to get a reference to a bean’s remote interface l Provides bean creation services –myFoo = fooHome.create() instead of myFoo = new foo() –Supports multiple signatures to create EJB instances l May be generated by tools that come with an EJB server l Also manages EJB: –querying (Entity Bean) –deleting (Entity Bean)

7 creating competitive advantage Interface javax.ejb.EJBHome l Home objects must implement this interface l Returns a reference to a bean by creating or finding it l Every bean has a EJBHome interface that provides methods for getting references to one or more beans –create methods are used to create new beans –there can be many create methods, similar to a class having many constructors l Provides a bean removal interface also l The EJBHome Class implementation is provided by the EJB Server Provider

8 creating competitive advantage Sample EJBHome Interface public interface CustomerHome extends EJBHome { public abstract Customer create(String id, String name) throws RemoteException, CreateException; public abstract Enumeration findByName(String val) throws RemoteException, FinderException; public abstract RemoteEnumeration findStateByName(String val) throws RemoteException, FinderException; public abstract Customer findByPrimaryKey(CustomerKey pkey) throws RemoteException, FinderException; public abstract Customer findByPrimaryKey(CustomerKey pkey, int findSource) throws RemoteException, FinderException; public abstract CustomerState findStateByPrimaryKey(CustomerKey pkey, int findSource) throws RemoteException, FinderException; }

9 creating competitive advantage Clients EJB Server EJB Container EJBHome Class create() Client makes invocation to EJBHome Class via the EJBHome Interface l Client calls one of the create() methods on the EJBHome Class. The EJBHome class can have multiple create() signatures.

10 creating competitive advantage Clients EJB Server EJB Container EJBHome Class EJB Class EJB Class EJBHome Class instantiates the Bean Class l When the create() method is called in the EJBHome Class, it is responsible for instantiating the Bean class.

11 creating competitive advantage EJB Server EJB Container EJBObject Interface EJBObject Interface EJBObje ct Class EJBObje ct Class EJBObject Interface and Class l Intercepts calls to the EJB Class to add support for: –transactions –security –threading l EJBObject class has the same methods as the bean and delegates to the bean as the bean and delegates to the bean for actual behavior l EJBObject class checks security and sets up transaction before delegating method call to the bean l Clients can never get a reference to a bean’s EJB Class, only the EJBObject interface

12 creating competitive advantage Interface javax.ejb.EJBObject public interface javax.ejb.EJBObject extends java.rmi.Remote { EJBHome getEJBHome() throws RemoteException; Handle getHandle() throws RemoteException; Object getPrimaryKey() throws RemoteException; boolean isIdentical(EJBObject obj) throws RemoteException; void remove() throws RemoteException, RemoveException; } l Represents a specific bean instance l Remote objects must implement this interface l Primary key is an object that represents the primary key for a specific instance of a bean l The EJBObject Class implementation is provided by the EJB Server Provider

13 creating competitive advantage Sample EJBObject Interface public interface Customer extends EJBObject { public abstract String getId() throws RemoteException; public abstract String getName() throws RemoteException; public abstract void setName(String val) throws RemoteException; public abstract boolean getNameNull() throws RemoteException; public abstract boolean getIdNull() throws RemoteException; public abstract Enumeration getAccounts() throws RemoteException; public abstract void addToAccounts(Account relInst) throws RemoteException; public abstract void removeFromAccounts(Account relInst) throws RemoteException; }

14 creating competitive advantage Clients EJB Server EJB Container Passes ref of Bean Client now has reference to the EJBObject Class. NOT A REFERENCE TO THE BEAN ITSELF!!!! EJBHome Class EJB Class EJB Class EJBHome Class After the EJBHome Class instantiates the Bean... l The EJBHome Class will instantiate the EJBObject Class, initializing it with the remote object reference to the Bean Class. l The Client will now communicate to the EJBObject Class. The EJBObject Class will delegate the call to the Bean.

15 creating competitive advantage Clients EJB Server EJB Container EJBHome Class EJB Class EJB Class EJBHome Class Client communicates to the Bean class via the EJBObject Class l Client never has a direct reference to the Bean. l The EJBObject Interface is the interface for the Bean, so the EJBObject Class “delegates” the calls to the Bean. l The EJBObject Class implementation will be generated using vendor tools.

16 creating competitive advantage EJB Class l A bean has a single Java class at its core –This class is written by a developer if it’s a session bean –This class is sometimes generated by a tool if it’s an entity bean l Implements application-specific business logic l Implements one of the following contracts: –javax.ejb.EntityBean –javax.ejb.SessionBean l These contracts provide for consistent behavior when activating beans, passivating beans, reading data, writing data l Every container can expect these methods in every bean

17 creating competitive advantage Deployment Descriptor EJB Container EJB Server Deployment Descriptor l Allows you to declare transaction and security attributes, NO PROGRAMMING REQUIRED!!! l An EJB Deployment Descriptor describes the classes, interfaces and declarative behavior of an EJB l Deployment Descriptor format is serialized objects: –javax.ejb.deployment.ControlDescriptor –javax.ejb.deployment.DeploymentDescriptor –javax.ejb.deployment.EntityDescriptor –javax.ejb.deployment.SessionDescriptor l The deployment descriptor is generated by server tools l The deployment descriptor classes are defined in the EJB specification

18 creating competitive advantage Let’s look at the value of the Deployment Descriptor l Step #1 - Write your Bean implementation. l Step #2 - Compile this Java source into Java bytecode l Step #3 - Developer is responsible for creating a serialized deployment descriptor for the bean. Most likely using a tool from the vendor. EJB tools will use Reflection API on the compiled EJB Bean to determine: –name of Bean class –methods –parameters –return values l Step #4 - The EJB Tool will use the above information to generate a Deployment Descriptor file and an editor with which to set transaction and security attributes.

19 creating competitive advantage Manifest EJB Container EJB Server Enterprise JavaBean Packaging l Enterprise JavaBeans are comprised of many Java files l These files are put in a JAR file –A JAR file is a ZIP file with a MANIFEST that describes the contents of the file –A MANIFEST is a simple text file Name: bank/AccountDeployment.ser Enterprise-Bean: True Name: bank/AccountDeployment.ser Enterprise-Bean: True l A JAR file can contain more than one Enterprise JavaBean

20 creating competitive advantage Written by Developer Generated at Development Generated at Deployment EJB Server EJB Container EJBHome Interface EJBHome Interface Deployment Descriptor EJBObject Interface EJBObject Interface EJBHome Class EJBHome Class EJBObject Class EJBObject Class EJB Class Manifest Summary: Bean Development Process l Implement the EJB Class l Specify the remote interface l Specify the home interface l Specify security and transactional characteristics using vendor tools (DeploymentDescriptor) l Use vendor tools to generate supporting code and package components in EJB-jar l Iterate...


Download ppt "Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake"

Similar presentations


Ads by Google