Enterprise Java Beans - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Enterprise Java Beans

Description:

Normally servlets and JSP's will ... Contain the business logic of the application. Session Beans ... is packaged into a jar file before deployment ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 23
Provided by: chme3
Category:
Tags: ajar | beans | enterprise | java

less

Transcript and Presenter's Notes

Title: Enterprise Java Beans


1
Enterprise Java Beans
  • Server Side Java Application Programming

2
Overall structure
Database
Java Application
Middle Tier Server
Web Browser
File System
Mobile Phone
Legacy Application
3
J2EE Server
J2EE Server
EJB Container Stateless Session Bean Stateful
Session Bean Entity Bean
Clients
Back end services
Web Container Servlet JSP Html/ Images
4
Interacting with EJBs
  • Normally servlets and JSPs will interact with
    EJBs
  • However a client application can also directly
    interact with EJBs

5
J2EE Services
  • EJB container provides
  • Transaction Management
  • Security
  • Remote Client Connectivity
  • Life Cycle Management
  • Database Connection Pooling

6
Enterprise Java Beans
  • Contain the business logic of the application
  • Session Beans
  • Stateless Session Beans
  • Stateful Session Beans
  • Entity Beans
  • Container Managed Persistence
  • Bean Managed Persistence (Ejb 3 has no BMP)

7
Session vs Entity Beans
8
Session and Entity Use Example
J2EE Server
EJB Container
Database
Entity Bean
Entity Bean
Session Bean
Web Container
Web Browser
Servlet
9
Structure of a J2EE Application
J2EE Application
J2EE App DD
.ear file
Web Component
Enterpries Bean
Web Comp DD JSP file Servlet class GIF/jpeg
File HTML File
EJB DD EJB class Remote class Local class
.jar file
.war file
10
Standard Deployment Descriptors
  • Enterprise Archive (ear) file
  • application.xml inside the META-INF directory
  • Java Archive (jar) file
  • ejb-jar.xml inside the META-INF directory
  • Web Archive (war) file
  • web.xml inside the WEB-INF directory

11
Application Server
  • Netbeans 6 uses the Glassfish V2 Application
    Server
  • Others can be used if wanted
  • To deploy a J2EE application on Glassfish V2 we
    need to add several vendor deployment descriptors
  • sun-web.xml inside the WEB-INF directory
  • sun-ejb-jar.xml inside the META-INF directory

12
Enterprise Beans
  • All enterprise beans need
  • Bean Class
  • Implementation of the bean
  • Local Interface
  • Allows Clients to Connect in the same Virtual
    Machine, very efficient
  • Remote Interface
  • Allows Clients to connect using RMI/ IIOP, used
    when client in different virtual machine.

13
Session Beans
  • Bean Class
  • Implements the business method of the bean
  • Local Interface
  • Defines the business methods that a local client
    can call.
  • Remote Interface
  • Defines the business methods that a remote client
    can call.
  • NOTE the business methods are implemented in the
    Bean Class

14
Session Bean Class
  • Implements the SessionBean Interface
  • Must define
  • One or more ejbCreate methods
  • ejbRemove()
  • ejbActivate()
  • ejbPassivate()
  • setSessionContext(SessionContext sc)
  • In Ejb3 implemented via _at_Stateless of
    _at_Stateful annotation
  • Can define additional business methods
  • Must Implement any Local and Remote Interfaces

15
Session Bean Class Business Methods
  • Addition business methods can be defined in the
    Session Bean Class
  • public double convertL(double dollars)
  • return dollars 1.95
  • public double convertR(double dollars)
  • return dollars 1.95

16
Session Bean Local Interface
  • Local Interface defines any business methods that
    a local client may invoke
  • These methods signatures must match exactly those
    business methods defined in the Session Bean
    Class
  • public double convertL(double dollars)

17
Session Bean Remote Interface
  • Remote Interface defines any business methods
    that a remote client may invoke
  • These methods signatures must match exactly those
    business methods defined in the Session Bean
    Class
  • public double convertR(double dollars)

18
Packaging the Session Bean
  • The Session Bean is packaged into a jar file
    before deployment
  • The Netbeans IDE packages the bean including any
    deployment descriptors
  • ejb-jar.xml
  • sun-ejb-jar.xml

19
Accessing and using the Session Bean (from a
Servlet)
  • Declare the Session Bean using the _at_EJB
    annotation
  • _at_EJB
  • private sbConvLocal sbConvBean
  • Use the Session Bean in the servlet code
  • sbConvBean.convL(100)

20
Stateful Session Bean Lifecycle
21
Stateless Session Bean Lifecycle
22
Summary
  • Main points to remember
  • J2EE Application server
  • EJB container
  • Entity and Session Beans
  • Session Bean details
  • Bean Class
  • Home Interface
  • Remote Interface
Write a Comment
User Comments (0)
About PowerShow.com