Anda di halaman 1dari 93

{  


     

  

w w 

   
     $
 $ 
 !"w #


 


|   

|   
   |     

 

   
1. Learning objectives
 
       
&   w% ' '  
 

  ( 
)   
* &  '   
 
+  ! , ( ( -. w
/  !
% , 
0  ! 

  ,  '  


%%   
1 
%!  
  

 
  !w % .  2
 

 $%    %%%  ! 


&  ! % .
   

 
  2
 
) 
  


 

   
R. About the Author
|      
Worked in fortune 100 Corporates in Client Server Technologies

Specializes in
Architecture, Designing, Development & Managing day-to-day activities.

Presently doing a PhD at Queens Uty, U.K in Adaptable Software specific to


Component Technologies and has a M.B.A (Computer Applications) from an U.S. Uty.

Business domain strengths are in Investment banking & Insurance.


J
{ Process improvement strengths are in 6 - Sigma and CMM.
J J

His present & past working experiences in various global locations are in corporates like
Pramerica (Prudential U.S), J P Morgan Chase, A B N Amro Bank & SGS.

He was a part time visiting faculty in affiliates of Sydney University, Australia and All India Management
Institute teaching I.T, Project Management & Statistics. He has given some presentations on Project
Management and TQM at various venues. He has won few Talent/STAR performance awards and plays
almost all the sports what are under the Sun.

He hails from Vizag/ Hyderabad ± India. His 3rd party tested Temperament Sorter results are below
https://www.advisorteam.com/temperament_sorter/testresult.asp?TID=740R 1673499&PID=15 00
https://www.advisorteam.com/temperament_sorter/testresultc.asp?TID=740R 166R156&PID=13606

If you liked his presentation, tell others and if you have a comment, tell him. He can be reached at
Kanti.Prasad@Pramerica.ie or Kanti1@donegal.net
 

   
3. Thank you note
 -    3  '   ,  '   .   !  % 3
 '  3  -    
 -    3  |   !   ,  |-  - ('  
  %     .    
 -    3   '  , ''   ,     . 4 '
5 ' -   ('       % 
   


   3            '   

 !"
#
$"  

 .
     5w    !    .'
 

w
 

   
4. Component Technology


   
 6 '  
(
6'   (     
‡   
 
(    %   % % 
 ,


   ( 
‡ 
   6  ( 
    '  '   4,77,4!
‡ 
   % 8'   9  

  % -3 %


(    
‡ 
    '    ( :   !   9
 '   - %
 6'
'    
 

 

   
5. Component Characteristics

      '

´ 
  ´  ' 6

´
  ´   6

´ (  ´ 6' 6

´ 
 6 ´  %  

´  %  


 

   
6. Component P O E


 ' (     % 2


´ 
 

´
 

´ ( 

 

   
7. Deployable Components


   
 
 %

‡  - 
‡  ' 
 
‡  

  ( 
‡   -3
  '

 

   
. Reusable Components


  (  6 '   
%
6'  %  
 

 

   
9. Shareable Components

w% '
     '  
 
 '  ',  
 -
(
  8' % (     

 

   
10. Distributable Components


 '
(  (   
'   

 
 !  
$w 
 !

$ 
$w   
6  $w 
  
$w 

 
$w 

 

   
11. SelfContained Components


 '    
  
   ( 

w% ' '  ( '6 ;  6


  2 ' ( 

 

   
1R. Standard Infrastructure Needs

  % ' '  (  ' 

‡   ( 


‡ 6'      
‡  '   
‡  '     
‡       
‡  ' 
< !  =
‡    %
‡ $ !   
‡  '   

 

   
13. Applicatoin Servers



  ( 
(  % ' ' 
 ( ' 
 >

 

  ( 
'    

? &  %'


&
'
6  
<,', < , 
'
 ,  = 4! ,@  =

 

   
14. Object Pooling



  (      
%6  6; 
  6 '   !-  8'    

 ( 

 !  
 !
 !
 !

$w  
 !  ! !
-3
$w   !

 

   
15. Directory of Application Servers


  ( 
(    %-  
 

  '  ( 

2
  ' - 6 ( , ?  (    6   ( 


' 

  (   A
‡ w! 6
 
‡ ! 6$
‡ ' (  

  ( /2
‡ 6
 %'-(      (  6  

A>>--- (2  >  
 > >+&+0

A>>---; (     >   > ( 

 

   
16. Container
     '(( ' -  .
  A 

%#   ! '(( '    

‡
(   ( -  6  2 ' 
‡       6; 
‡      ! 6;  Implicit Middleware
gained through declaration
‡   (' 6   
   &"' .
 $  ! 
&"
   
(   ( 3
       '     

 ( 
 !  
 !
 !  !
  
-3  

!
 8' 
$w 

  3-- , '  6  (  


   
%
 

   
17. JREE Overview

 
  
<=

 6 ( w
 
Enterprise Components


  ( 
w
  services standards component-based

  6  w
  &
 
  '    > ( 
    ( 
JREE Interfaces Deploy
Tools
6'  '  Management Services
 (  Deployment/Configuration
   JRSE Language/Interfaces
 (  Data
JRSE Runtime

  
w
  Operating System Platform
 -  w
 
Hardware Platform
 

   
1 . JREE 1.4 APIs
& %    % ( 
 '? ,- 66  ,
 
 

 -6'  
 

  w>
 6    !  
   > ww 
  (   !


 
 (  5w 
:?  (   :?  (  
 
&                
 
:  !  :   ! :  !  :   !
   
   w     w 

   & &


   >

w )w
 

w>
w
:?    ww 
 
   

: ! : ! !
 
  
& &w
  

  w % 


A>>; ( '  >;& >)> >' > > 2 
 

   
19. Enterprise JavaBeans Model
 !' &   ,( ? ' ,
 
 
    ' 
(

‡  %6'    -    ' 


 '
  
‡    (  2
   <6 ?   =(  ( %  !
 ( <   ?   =
‡ 4  '    
 6
‡ :$( 
   %' 

 
 ( !  ( ! 
 !     !     
 !  
 6  
  !   ( 
 
 
 !    6 %   
  

 !    - '  ' 


 !  6  www   w   ! (  M     

 

   
R0. EJB Overview
 !
% 6'  ( 

± ( 
 !
  
± %  >$    >$  % 
±         
±      ' >%   > 6 3

EJB Client EJB Impl


$  $  create timeout
Client Process create invoke remove passivate
remove find activate
find invoke load
 store
STUB STUB
create
remove
EJB find
Client   Network
 !
Delegate 
Delegate
Delegate
invoke Delegate

 

   
JREE EJB Container/Server
R1. When to use EJB

w% %   8' %'

 

‡  

  '6   6  6' 6


‡   -6  8'  '    
‡  

 - (  (  %  

 

   
RR.
(   
 w % < w=
w
(    9 - %  '  6' 
( 
    (  
‡  
‡ w
‡ $
‡ :*
w
  6 ; ( 2 
3     
3  
6 -
; ( 2 w  2  
  ! ( 
‡ 6B      - 6; 
‡ 3'
B % 6; (  

 

   
R3. EJB Specification

  !
%  %  % 6 - 

‡   !    
‡       

  ( 
‡         

 

   
R4. EJB Roles

 ( .( 

(  ( ,      -6' %  
 !(  

  6 
   ! 
   6 

% 
?6' ! 


 
 



 '     ' ' 

'

  6'

  


(  

  6  
     
 
 

'

 

  ( 
 ( 
 !

 !(  

  ( ( 

 

   
R5. EJB Design Approaches
 !  6   6   

  %
6'6'  
  
    ( 

   ?  

 
   6; 

  w
  %   % 
  ' 4    !
  !
% 
(    
    !     ( 6 
  %' !  ! 

!   !     ( ! 



  w % 
  w % 
  w %

; ( 2 ;6!  ; ( 2 ;6 !  ; ( 2 ;6   ( ! 


2  2  2 

; ( 2 ;6 
 !  %
2 

w  3 w % ; (   9 6       2  


      -w %     ( 
w
 
  9     6  (%6 w % 
 !6' 6 

 

   
R6. EJB Architecture
 ( ' 
&         ( 
 '
$
 4w
 ( ! 

 ( 
 w
w  2 0  !  
    6; 
w % < =  w
 
) *
  !
+    !
<!' $  =

6;
w>ww  1   
   ! 6; 
'6


  / w % <

=      8' 
   !
6;
'6 

-  ( - 
  
 > '      % w % 
 --        w ,w ,w. $w 5

 

   
R7. EJB Flow Chart
  

(3  6'  


3 w ( %   6;   +
'  '6

w (  ' %% '6 &    w ( 


/    ! 6; 

3 %  ! 6;  
  w %  -

0  8'  !   
   ! 6;  )

 ' %   %  '6   (   8' %


* 1

 

 

   
R . Client View of EJB
 w!   3     
          

 ( 
 !  
 !  
 !$   !  ‡! 3  
  ‡   '9 

 ! 6; 
 !$  6;  !  


  w>   ‡! 3 '6  


  ww 
‡'    

      (  


!   ‡ 3     
‡3%-   

w !   3 4!  


   6' 
     

5w4 !  (       

w%  
    

  (  - ' 


 !$ < 6; . = %   %   
 
$  % 
6   !< 6; > =
64$
 

      %  ('6,3  , -3 %  


R9. EJB Client

 !  

'9    (    w % < w=3'

%  %     % 

'      ! % '9   !?6  


%'  

 

   
30. EJB Home Interface

 !  %  2 ; ( 2 ;6 !

 !  % 
( 
 %  
‡    !
‡  (  !
‡ %   !   % 6; 
‡  ( '6
  w  '

 

   
31. EJB Remote

 !   %  2 ; ( 2 ;6 ! 6; 

 !   % 
‡
( 6' ?
% %'  %  !
‡    w   %

 

   
3R. EJB Implementation

 !
  

 -  ! ( 


   6'  
 %  6  
  % <= 
(  

  
% 

‡ 6'  ( 


‡  
‡  ( 
‡ %
‡ ( 
‡
( ,  6   
‡   6   
 

   
33. Session Context

       %    6 

 6   -   '  2 


‡   (   % 
‡       6' 
‡ 6  ' 6'

    2 ' %  6 


6'    2

 

   
34. Stateless Session EJB
     ! (  %-6  ('

‡
(   '  (
‡     6  %%   
‡    ( ( 
‡ '((  ! (    
‡ -  %       !

   -   
‡    6   6 '
   

 

   
35. Stateless Session EJBs View
EJB Client Stateless Session
$  $  Logic
Client Process

EJB  input

Client  Network output


EJB Pool

JREE EJB Container/Server


 !w
 ( 
4 -
 !  8'       
 
    (  '
   ( 

 !  ( 
4 -
  ,'   

 !  4 -

'  % 
'
   8' 
3>-
   
% -
 6   ( ' %  
+$%   %
+$%    %
     ! 
    
( % 
   ! 
Client called remove()
on the EJB object
(or the client times out)
Container decided it Bean Instance
needs more instances does not exiist
in the pool to service clients
Class.newInstance()

ejbRemove()
   2<=

;6  <=

Pool of equivalent
method ready instances
Client called another
Transactional business method
on the EJB Object.    
!'  
37. Stateful
Stateful Session EJBs View
Stateful Session
EJB Client
$  $  Logic
Client Process
x
EJB  input

Client   Network output


EJB Pool

JREE EJB Container/Server


 !w
 ( 
4 -
 !  8'       
 
    (  '
   ( 

 !  ( 
4 -
  ,'   

 !  4 -

'  % 
'
   8' 
3>-
   
0$%   %
0$%    %
  %'  ! 
    
w( % 
   ! 
Client called remove()
on the EJB object
(or the client times out)
Bean Instance
Client called create(args) does not exiist
on the home Interface.

Class.newInstance() Container¶s limit of


instantiated beans
are reached, so it must
ejbRemove() swap your bean out.
   2<=
Client times out
Client called a
non-transactional business ;6  < =
method on the EJBObject
Non-Transactional ejbPassivate()
Business Method Bean instance is ready
Bean instance is in
to service method calls
the passive state
Client called a transactional ejbActivate()
business method on the
EJB Object beforeCompletion() Client called a method
on a passivated bean, so
afterCompletion(true) afterCompletion(false) Container must swap your
afterBegin() Bean back in
If transaction ended
in a commit..
Bean instance is within
a transaction and ready We need to write all
to service method calls the methods that If transaction ended
Client called another in an abort.
are there in the
Transactional business method
on the EJB Object.     Implemented class
!'  

w%- 
  ( 2 ;6  9  -  
-    
39. Stateful vs Stateless
  %'!     ! 
  %'6     (          6   (    6 -  
           

      3  '          3  ' 


   <=,   <w,=    <=
   6     '          6  '      

 
 ! '9
6 %    ! 63 %       (   
 !   3 %  3 6(  - 6 

 6  
 6   !& 2  
A>>---(  69>
&

 

   
40. Entity Bean

!   %-6  ('

‡     
   %
  
‡   '((    
‡ '
    6 ' ! 
   
  
‡   !      
%    

 
‡    3 3    6   

 

   
41. BMP Entity EJBs
<!! ?      =

EJB Client Entity Bean (BMP)


$  $ 
Hand
Client Process Coded
Logic
EJB 
  Network EJB Pool V 
Client
 
JREE EJB Container/Server
  6; <(  ? = data

 !w
 ( 
4 -

'     %    '  6; 

  6; ?   

<%  !=

   ,   ,8'   '
  
 !  ( 
4 -
  ,%,'
    (  6; 
 !  4 -

      '  %  
4R.  3   

‡ 

 6  6 


â 8' %%         
 !
â   '6    ( ' 
w?ww 
â w
 ; (   9 6 
â   6 '6 
'6
â w'
   <=  8' <= 
â  
 ; (   

 

   
43. Shared Entity Bean

  '
        !  
‡  (   -  
‡    '   
‡    (     9 

{%

  

 (
#!
 

 

   
))$%   %
))$%    %!
!!
! 
    
w( % 
   ! 

Container decided it
Container decided it Does not exiist doesn¶t need the
needs another
Entity Bean instance
Entity Bean insinstance
anymore
newInstance() unsetEntityContext()

setEntityContext() JVM will garbage


collectt and call finalize()
Client called instance
independent ejbHome() Client called a finder
Business method Method on the home
interface
ejbHome() Pooled ;6<=

Client called create() on


the home interface (this will
Create new database data) Activates the Bean Passivates the Bean Client called remove()
on the EJB object
(this will destroy
ejbCreate() ejbActivate() ejbStore()\ ejbRemove() Database data)
Container determined
that the database is out of
synch with the bean. The ejbPostCreate() ejbLoad() ejbPassivate()
Bean needs to load the
new Database data.
Container determined
Ready that the database is out of
ejbLoad() ejbStore() synch with the bean. The
Client called a business Bean needs to store its
method on a EJBObject Data into the Database
!'  
45. CMP Entity EJBs
<  ?      =

EJB Client Entity Bean (CMP)


$  $ 
Client Process Generated
Logic

EJB 
  Network EJB Pool V 
Client
 
JREE EJB Container/Server
  6; <(     ( = Persistence
data DDs

 !w
 ( 
4 -

% %       

% 8'  (  !?"$
' 
  6; ( -
%    ( -
 !  ( 
4 -
  ,%,'
    (  6; 
 !  4 -

      '  %  
)+$%   %
)+$%    %
!
! 
    
w( %  A!  ;6  <=
   ! 

Container decided it
Container decided it does not exiist doesn¶t need the
needs another
Entity Bean instance
Entity Bean in
anymore
newInstance() unsetEntityContext()

Client called a finder


setEntityContext() JVM will garbage method on the home
collectt and call finalize() Interface, or bean
Client called instance
independent ejbHome() called its own
Business method ejbSelect()
method to locate
Database data
ejbHome() Pooled ;6<= ;6  <=

Client called create() on


the home interface (this will
create new database data) Activates the Bean Passivates the Bean Client called remove()
on the EJB object
(this will destroy
ejbCreate() ejbActivate() ejbStore()\ ejbRemove() Database data)
Container determined
that the database is out of
Synch with the bean. The ejbPostCreate() ejbLoad() ejbPassivate()
Bean needs to load the
new Database data.
Container determined
Ready that the database is out of
ejbLoad() ejbStore() Synch with the bean. The
Client called a business Bean needs to store its
method on a EJBObject Data into the Database
!'  
 ;6  <=
47. BMP vs CMP

!              


!%%    

      

  ( 
 3   % 
  4  3   % ( 6' ? !

 '    

!'     8'   - 


 9 '  ( 
 
 9 
%    ( 
8'    3   %
 '    ( 
  6 , '  -  8'  3 % 
  6 , 3 '? 6 ,  
 6 
    9  -  6    -  -  9   -        
-
 %    
  <
%  '       =, -     6 
%   !

 6  
 6   !& 2  
A>>---(  69>
&

 

   
4 . Message Driven Bean

!  %-6  ('


‡ w   
‡     
‡ -       (   
   <= 2 ' 
‡  '((  ! (    
‡
(   ?'  (
‡   ( ( 
‡  6   B  % 

 

   
49. Message Driven EJBs
 V 

 V
× $
Handler Logic
à 
à x V 

©  × $ V
     × $
Message
à  w Listener EJB Pool
JREE EJB Container/Server

 '  


 !w
 ( 
4 -
    8' (   
  ?
%  %
    (  '
   ( 
 !  ( 
4 -
     
.  6   (

% 
 '   
  ' 
 !  4 -

'  % 
  (   
*$%   %
*$%    % 
   (  ! 
    
w( % 
   ! 

Container decided it
needs another Does not exiist
Message DrivenBean
Instance
newInstance()
ejbRemove()
    (  2<=

ejbCreate()

Pooled

   <=
51. Deployment


 ((  3  ! 
 6  

‡   :$   6   !


‡
3   6  :$  
‡        % %  !
‡ %' 

 %  ! ( 

  -'
  
 

   6     :$%  

! (     


   -   (  8'  $  w  
! (   6 -   '
%  $%      ,   ,    '

 

   
5R. Other interfaces and classes
â $  %   ' % - (   2
â ; ( 2 ;6 !$  A
‡w  
  
â ; ( 2 ;6 !$  6;  ‡ ( ( 

â w % %  9 ! %   


â    ?  %    !
â   ?  %    ! 6; 

â  !     % 
(      
%  6' 6 
â  %    ! 6; 
â  , 
  %  
 3    
â %'     6 

 

   
53. Exceptions

â   2
  '  3  

    
  ; (    2

â 

  2
    3  

    
      %; (  2

â  !?
%  2
 '  2
,
  2
,  2
< ; ( 2 ;6

3  =
â !'   2
      % 
 ! ( 


 

   
:$
$!

 

   
54. Steps to Develop an EJB

 

%' ' ! ( 


 ; ( % % ! ,   !   
 
  %    
  ! %
*

&
  
   
  ' !    
+ %     
  ! % 

   %  
  % 
 ' !6-  
/  ; ( %  
  '
  '     ! 
%   &.%  )



  -   

  ( %-  %  3


(   %       

 

   
55. Hello World Object Model using RMI
 -

 
 (' %-  
 '  3 '
'% !
2


  w %   - ( & %


; (    ; (   9 6

  w %   - !6'


( 2 ;6 
 ! 
( 2 ;6 ! 6;  ( 2 ;6 !
( 2 ;6 ! 

'

 6 ! ( > ( 


> -- 
 ! 
a


 -  w % 


V

  w % w
   

5    %'6   ( 


A 6; 
  
4 
%     

   
 - ! 6;     6;   6; %   
 6; %     

 

   
56. Hello World Object Model using LOCAL
w%  
    

  (  - '  !$ < 6; . = % 


  %   
 $  % 
6   !< 6; > =-  

 ('   ' --
64$   %   2  (     
(  %  '6,3  , -3 %%  (  %  6'  -6 3%'
   $  %  -    6   

No Network so   w %   - ( & %


LOCAL IMROVES ; (    ; (   9 6
PERFORMANCE

  w %   - !6'


( 2 ;6 
 ! 
( 2 ;6 !$  6;  ( 2 ;6 !$ 
( 2 ;6 ! 

'

 6 ! ( > ( 


> -- 
 ! 
 -$ w % a





 $ V

 w % w
   

5    %'6   ( 


A 6; 
  
4 
%     

   
 - !$  6;   $  6;   6; %   
 6; %     

 

   
57. HelloBean Home Interface
EJB Example requirement :
When the client interacts with the EJB we need to return a ³Hello World´ greeting.
To provide an EJB with the above requirement we have to create Remote & Home
Interfaces , Bean Business logic class and a deployment descriptor. For clarity please
see the previous slide Hello World Object Model using RMI.
This is the Home Interface for the Home EJB (HelloBean).


3   2
 C Rules of Java says package declaration should be at the beginning and ends with a semi colon


; (   9 6 C

; (    2
C Importing the required files


; ( 2 ;6  2
C

; ( 2 ;6 ! C

'6  %    2 ; ( 2 ;6 !
Our interface HelloHome is extending EJBHome means it has all the behaviour of EJBHome
D
    <=-; (    2
,
; ( 2 ;6  2
C  
  
 

V 

V

This method creates/manufactures the EJBObject and returns it . This create() method corresponds to the
ejbCreate() method in HelloBean.
As for every Interface we need implementation,Note
so Container
In Home will implement
Interface we are(autogenerate code) for Remote
throwing R exceptions this Home Interface
and Create .for us, which is the EJBHome Object
E
©


 

 
  
that 
 


V  V



V
V

 
V  

 

   
5 . HelloLocalHome Interface
So now lets code the HelloLocalHome Interface

This is the LocalHome Interface for the Home EJB (HelloBean).


3   2
 C Rules of Java says package declaration should be at the beginning and ends with a semi colon

; ( 2 ;6 !$  C

; ( 2 ;6  2
C

; ( 2 ;6 2
C

; ( ' C
Our interface HelloLocalHome is extending EJBLocalHome means it has all the behaviour of EJBLocalHome


'6  %  $   2 ; ( 2 ;6 !$ 
D
 $    <=-; ( 2 ;6  2
C
This methodsocreates/manufactures
As for every Interface we need implementation, the EJBLocal
Container will implement Objectcode)
(autogenerate and
returns
this itLocal


for . This create() method
 
 

V
Home for us, corresponds
which to the Object


V

is the LocalHome
ejbCreate() method in HelloBean.
Note In LocalHome
©


 

 
 Interface

that we are throwing only Create and not

 


V Remote exception as there is
V 
V



V
V

 no network 

E
 

   
59. HelloBean Remote Interface

So lets code the Remote Interface

Clients interact with the EJB Object through this Remote interface that is why we need to write this interface


3   2
 C Rules of Java says package declaration should be at the beginning and ends with a semi colon

; ( 'FC

; ( 2 ;6 ! 6; C Importing the required files


; (    2
C

'6  %   2 ; ( 2 ;6 ! 6; 
D Our interface Hello is extending EJBObject means it has all the behaviour of EJBObject


'6  <=-; (    2
C
E As our requirement wants a business logic to greet Hello World a single method would be sufficient .
 
  
 

V 

V

As Remote interface is used to interact with the Bean we need to mirror all the method signatures what
are there in a Bean class so that is why we are writing only one method in this Remote interface.
Note EJB specification states that all remote calls should throw RemoteException so we are throwing it.
As for every Interface we need implementation, so Container will implement (autogenerate code) for this Remote Interface for us, which is the EJBObject
©


 

 
  
that 
 


V  V



V
V

 
V  

 

   
60. HelloLocal Interface

Clients interact with the EJB Object through this Local interface when there is no network involved.


3   2
 C Rules of Java says package declaration should be at the beginning and ends with a semi colon

; ( 2 ;6 !$  6; C

'6  %  $  2 ; ( 2 ;6 !$  6; 
Our interface Hello is extending EJBLocalObject means it has all the behaviour of EJBLocalObject
D

'6  <=C  
  
 

V 

V

As our requirement wants a business logic to greet Hello World a single method would be sufficient .
E As Local interface is used to interact with the Bean we need to mirror all the method signatures what
are there in a Bean class so that is why we are writing only one method in this Local interface.
Note As there is no remote calls no Remote Exception is thrown

As for every Interface we need implementation, so Container will implement (autogenerate code) for this Local Interface for us, which is the EJB Local Object

©


 

 
  
that 
 


V  V



V
V

 
V  

 

   
61. The Bean Class
So now lets code the actual EJB Class

This is where we will code our Business logic


3   2
 C Rules of Java says package declaration should be at the beginning and ends with a semi colon

; ( 'FC
Importing the required files

; ( 2 ;6FC

'6    ! 
 ; ( 2 ;6 ! 
NOTE : Note
If it is: Entity
this isBean
a class
we and
will not
implement
an Interface
javax.ejb.EntityBean
like the other two
and
(Home
if it is /Message
Remote).driven
This isbean
implementing
we will implement
SessionBean
javax.ejb.MessagedrivenBean
so it is a Session Bean
D As per the below note in red we need to write all the methods what are in javax.ejb.SessionBean .


(    2 2C This ejbCreate() corresponds to the Homeobject Create(). NOTE : in Stateless Bean no arguments are sent

'6 ( ;6  <=D '
<G ;6  <=H=CE

'6 ( ;6 ( <=D '
<G ;6 ( <=H=CE There is nothing much to clean up.
These are called
Management or

'6 ( ;6 (  <=D '
<G ;6 (  <=H=CE In Statelss Bean ejbActivate
Call back methods
and ejbPassivate Do not apply

'6 ( ;6 (  <=D '
<G ;6 (  <=H=CE

'6 (   2<; ( 2 ;6  2 2=D
Storing the Context in a variable so that it can be queried later .
 2 2CE NOTE : Because it is a Session Bean we are using setSessionContext for Entity Bean we
use setEntityContext and for Message Driven Bean we use setMessageDrivenContext.

'6  <=D '
<G <=H=C
 'G GCE
Our Business method which matches
E our Remote Interface method signature Java does not support multiple inheritance so you can extend only one class. To overcome
this they had given us the Implementation option . So when we use implement we need to
implement or write all the methods what are there in the interface we implemented.
 

   
6R. The Deployment descriptor
 
 $w

So now lets complete our EJB by writing the deployment descriptor. w 
 

As a Bean provider we need to specify the Middleware needs through this descriptor.

Ë  ;6?; !$wG?>>'  ,w >> 


  ( ! &>>
 GG
A>>; ( '  > ;6?; I&IHJ XML Standard requirement
Ë ;6?; J
Ë  
 ?6 J
Ë J
The nickname for this particular Bean
Ë ;6? J Ë> ;6? J
Ë J 2
   Ë> J The fully qualified name of the Home Interface
Ë  J 2
  Ë>  J The fully qualified name of the Remote Interface
Ë ? J 2
  $  Ë> ? J
The fully qualified name of the Local HomeInterface
Ë J 2
  $ Ë> J The fully qualified name of the Local Interface
Ë ;6?  J 2
  ! Ë> ;6?  J The fully qualified name of the EJB Class
Ë ?
J   Ë> ?
J Whether the session bean is stateful or stateless
Ë  ?
J  Ë>  ?
J
Ë> J
Ë>  
 ?6 J
Ë> ;6?; J

 

   
63. The Client
So now lets code our Client to access our simple stateless session bean.


3   2
 C Rules of Java says package declaration should be at the beginning and ends with a semi colon

; ( 2  2C

; ( 2 w  2C importing the necessary files


; ( '
 C

'6     D As there is static key word this main method executes first before any other method in that class


'6   ( <KL =-2
D

 

  
 <=C Assigning props variable with properties information for JNDI initialization
 2 2 -w  2<

=C Obtaining the JNDI initial context is the starting point for connection to a JNDI tree
By passing environment properties we will choose our JNDI driver,network
6; 6; 23'
<G  H=C Get a reference
location to the Home
of the server etc. Object- the factory for Hello EJB Objects.

   <  =; ( 2  6   6;  -<


6;,    =C
      <=C Use the factory to create the Hello EJB Object. We are then calling the hello() method
We are casting HelloHome here, as Home Objects are RMI-IIOP objects and so we
On the EJB Object. The EJB object will delegate the call to the Bean,receive the
Need to use a special RMI-IIOP cast.
 '
<  <==C Results and return it to us . We then print it on the screen.

  ( <=CEE Once we are done with the EJB Object, we can remove it.

NOTE : To call Local Interface you need not cast with the PortableRemoteObject. So the
block in red will be changed to
Object obj = ctx.lookup(³java:comp/env/HelloLocalHome´); ( to get a ref to LocalHome Object)
 

    HelloLocalHome home = (HelloLocalHome)obj;


64. EJB Jar File
The folder structure within the Ejb-jar file is
META-INF/MANIFEST.MF
META-INF/ejb-jar.xml
examples/HelloBean.class
examples/HelloLocalHome.class
examples/HelloLocal.class
examples/Hello.class


    >$ 
 w %

 $   
 
w % !     %


  
  
  % 

$ 

 ' 'ANJ  % ; F

%  Mw 


 % ?%  %  '     6  '

    
 ' 
( 6 

  (  4 


%

 

   
65. EJB Application Assembler


 
  
   

%


 

w4<; =
!w4<- =
 !? :$
  !:$
   
  ( $
 ! 
< =  ( 
<

 :$=

 

   
:$&
$!

 

   
Stateful Session Remote Interface
package declaration should be in the beginning

3  
  ;6  %'
  ;6C


; ( 'FC

; ( 2 ;6 ! 6; C Importing the required classes

; (    2
C


  ;6  %'
 !32
C
Remote Cart is extending EJBObject means Cart has all the behaviour of it

'6  %   2  ! 6;  Our bean class CartBean methods are mirrored here
D


'6 ( !3< =-  2
C


'6 ( ( !3< =-!32
,  2
C


'6 4   <=-  2
C
E
EJB spec says all remote interface methods need to throw remote exception
There will not be any implementation in Interfaces

 

   
Stateful Session Home Interface

package declaration should be in the beginning



3  
  ;6  %'
  ;6C


; (   9 6 C

; (    2
C
Importing the required classes

; ( 2 ;6  2
C

; ( 2 ;6 ! C

CartHome is extending EJBHome means CartHome has all the behaviour of it



'6  %    2  ! D

In a Stateful Bean you can have more than one create method taking arguments
    <
=-  2
,  2
C

In our bean class CartBean these represent


ejbCreate(String person) & ejbCreate(String person, String id)

    <
,=-  2
,
  2
C
E EJB spec says all Home interface methods need to throw remote & create exceptions
There will not be any implementation in Interfaces
 

   
Stateful Session Bean Class


3  
  ;6  %'
  ;6C package declaration should be in the beginning


; ( 'FC

; ( 2 ;6FC


  ;6  %'
 !32
C Importing the required classes


  ;6  %'
 w4 % C


'6    ! 
  ! D
CartBean Class is implementing sessionbean means this bean class is a session bean
 '  C
 ' wC
4   C We definedThis
this also
method in the Cart
represents the remote interface. person) method
Home create(String

'6 ( ;6  <
=-  2
D
%<
'=D
- -  2
<O '
 - O=C
E  D
'  
C
E

' wOOC
  -4 <=C as this is the Bean class we will implement the business logic here
E

NOTE : AS we are implementing and not extending we need to write all the methods that are there in the Sessionbean

 

   
Stateful Session Bean Class

'6 ( ;6  <
,=-  2
D
Werepresents
%<
'=D This also defined this
themethod
Home in the Cart remote
create(String interface
person, String id) method we defined
- -  2
<O '
 - O=C
E  D
'  
C
E
The new operator is instantiating the instance of a class
w4 %  3  -w4 % <=C
%< 3 (   <==D
' wC We are calling the validate(id) method from the class ID Verifier
E  D
- -  2
<Ow( AO7=C
E
>>6 3 '

6'  - 4 %   

  -4 <=C


E
We defined this method in the Cart remote interface

'6 ( !3< =D
   < =C
E
We defined this method in the Cart remote interface

'6 ( ( !3< =-!32
D
6  '   (  < =C
%< '%  =D We defined contents as a vector
- -!32
< 7O O=C
E
E

 

   
Stateful Session Bean Class
We defined this method in the Cart remote interface

'6 4   <=D
 '  C
E


'6  ! <=DE Bean class constructor


'6 ( ;6 ( <=DE We need to write these methods as we are implementing SessionBean


'6 ( ;6 (  <=DE


'6 ( ;6 (  <=DE


'6 (   2<  2 =DE

E

Rules of implement states we need to implement all methods that are there in the implemented interface

 

   
Stateful Deployment Descriptor
 
 $w
Ë#2 ( OO  O?0O#J 
Ë?? w 

&)'  ,w   (   
  w> w w$ '6;     
??J
Ë ;6?; ( O&O2 O
A>>; ( '  >2 >>;& O2 A2O
A>>---->&>:$  ?
  O2A  $ O
A>>; ( '  >2 >>;& 
A>>; ( '  >2 >>;& > ;6?; I&I2OJ
Ë
 ? J  Ë>
 ? J
Ë  
 ?6 J required by any XML document
Ë J
Ë
 ? J  !Ë>
 ? J
The nickname for this particular Bean
Ë ;6? J  !Ë> ;6? J
Ë J
  ;6  %'
  ;6  Ë> J The fully qualified name of the Home Interface
Ë  J
  ;6  %'
  ;6 Ë>  J The fully qualified name of the Remote Interface
Ë ;6?  J
  ;6  %'
  ;6 ! Ë> ;6?  J The fully qualified name of the EJB Class
Ë ?
J  %'Ë> ?
J
Ë  ?
J  Ë>  ?
J
Bean type is mentioned here
Ë '? J
Ë' ?  ? >J
Ë> '? J
Ë> J Closing session and ejb
Ë>  
 ?6 J

 

   
Stateful Deployment Descriptor
Ë  6?  
J
Ë   ?  J
Ë J
Ë ;6? J  !Ë> ;6? J
Ë ?%J  Ë> ?%J Passing Bean class methods and parameter info
Ë ? J  Ë> ? J
Ë> J
Ë ? 6' J 8' Ë> ? 6' J
Ë>   ?  J
Ë   ?  J
Ë J
Ë ;6? J  !Ë> ;6? J
Ë ?%J  Ë> ?%J
Ë ? J ( !3Ë> ? J Passing Bean class methods and parameter info
Ë ?
 J
Ë ?
 J; (  Ë> ?
 J
Ë> ?
 J
Ë> J
Ë ? 6' J '

 Ë> ? 6' J


Ë>   ?  J

 

   
Stateful Deployment Descriptor
Ë   ?  J
Ë J
Ë ;6? J  !Ë> ;6? J
Ë ?%J  Ë> ?%J
Ë ? J !3Ë> ? J Passing Bean class methods and parameter info
Ë ?
 J
Ë ?
 J; (  Ë> ?
 J
Ë> ?
 J
Ë> J
Ë ? 6' J 8' Ë> ? 6' J
Ë>   ?  J
Ë>  6?  
J
Ë> ;6?; J

 

   
Stateful Session Client

3  
  ;6  %'
  ;6C
package declaration should be in the beginning

; ( 'FC

; ( 2  2C
Importing the required classes

; ( 2 w  2C

; ( 2  6   6; C


'6     D Client class


'6   ( <KL =D
As static is there this main method will execute first
D
 2  -w  2<=C The new operator is instantiating the instance of a class
6; 6; % 3'
<O; ( A 
> (> ;6>
  O=C
Looking into JNDI
   
<  = 6   6;  -<6; %,
    =C Casting with a suitable RMI IIOP object

 

     <O'3   O,O&O=C Creating the object




  !3<O     O=C




  !3<O&


  O=C adding books to the object


  !3<O $ % % 3 O=C

4 63$ -4 <=C


63$

   <=C Invoking the bean class method through remote interface Cart

 

   
Stateful Session Client
'   ' 63$  <=C
We defined booklist as a vector
- < '    <==D
 <= '  2 <=C
After storing in the variable ³title´ we are printing it
 '
< =C
E



  ( !3<O   O=C




  ( <=C Removing a particular book using the bean class method removeBook through
remote interface Cart ±as we defined it this way
  2<=C Cart shoppingCart = home.create("Duke DeEarl","1R3");

E  <!32
 2=D
  
<O ' !32
AO7 2    <==C
  2<=C We had written a new class BookException and using its method to catch any errors
E  <2
 2=D
  
<O ' ' 2
  2
O=C
2
 3 <=C
  2<=C
E
E
E

 

   
Book Exception

3  
  ;6  %'
 C


'6   !32
 2 2
D

>FF
F % ' ' 
F>

'6 !32
<=D
E

>FF
F' - Ë  JË  J  
  
F
     ,  6  2

F>

'6 !32
< =D
'
< =C
E
E

 

   
ID Verifier


3  
  ;6  %'
 C


'6   w4 % D

>FF
F % ' ' 
F>

'6 w4 % <=D
E


'6 6 (   <=D
6  '' C
%<CË <=C77=D
%<   <  <==%  =
 '%  C
E
 ' 'C
E
E

 

   
$$:$
 ! 

A>>---- 6   > > 2
 > ;6> 3  ? 2
  ;6 

A>>  2
  >P
 >; ( >  

A>>; ( '  > ( 
>  >! > !' >

A>> ( 
'  >
 >; ( >;  > %   >  > 6  

 

   
66. Component Comparison

 6' 6
 !
 
    $ w %

 ( :
  %   ' %   -  
(  8'     
  '  
'  
  

 !
! 3 ' %5w   
 
% w

 

   
67. Component Comparison

 
(  %  % %
 

 !
2

 '  w %

 ( :
2

    %

 !
2
 'w % 


 

   
6 . Component Comparison
 %B   
 
 !
  ;       ,  6     ,
 ',6' 6   '  6  (   
6 
( 
 %

 (   !
( 

 ( :
  ,  6     ,     ( 6   
  %  
  '
  6   %
$   6   '

 !
 ! (  ( %%  w ! (  6  
  
  - ! (   '

 6  !


 

   
69. Component Comparison

 
(  %  % %
 

 !

    2
  2
 6' 6 
  3 ' 
 

 ( :
2

    %

 !

  2
  2
 6' 6 
  3 ' 6' 

 

   
70. Component Comparison

 
(  %  % %( 

 !
( '

 ' -   


( ! 

 ( :
2
(    %

 !
( '

 '(  ( 6' 


6  2
 

 

   
71. Component Comparison

  ' 6

 !
w 
    %  ! 6 
-- A
‡ 6 (  - !'   ( % 
 !     

‡ 6-  !    %  
2 

  - % (   6(  ( 



2 ' % 26

 

   
7R. Component Comparison

  ' 6

 ( :
w 
    %  ( : 6 
-- A

‡ 6 (  - ( :'   ( % 


 ( :    

‡ 6   

 
 6  '  '6    
  ( 
 

 

   
73. Component Comparison

  ' 6

 !
(  !6;   ( - % 
 %

 !6;  '   ( %  6; 

   %    6;  ' 


  '

 ,'

 

   
74. Component Comparison

   6
 !


  (  3  '
   % ! 6;  
 2 6  %%     2%%  

% ! % ( %  6

 ( :
'  %QB
 >'?%?
    ' % 
'
  ( : 
    
 

 !
! 3  '
   % !6;    2 
  6 !6' 6  ( %%  6  '
( 
w
  
 

   
75. Conclusion
 ' %' 
   ' ! 3  -  ! % - 
%%  
% !     -   !

 
$ w % -  '      ! - 
 
 !
 ,  w % , ! 6; ,$  6; ,$ w % ,  6;  3 
w 
   
     %  !B  3  ! 
     --        &%%  ! 
2
  - -      63-     2
       
'    %  w % , . 2
  ,'  

  2
  %      !     %

  ( 
6'
   '   % - ;' 

 ( 
 
  
- 63 '-   %  '%' %

 5$w 
-'3- w%' (    

   
     
 '    |     ,|       
3-% !  3  '% 6 3

 

   
76. References


  ( w% , ! '  .'   %'  

Notes on Deploying on different Application Servers.


The Art of EJB Deployment http://www.javaworld.com/javaworld/jw-0 -R001/jw-0 03-ejb.html

Most of EJB¶s related information can be seen at http://www.volantec.biz/ejb.htm


http://www.theserverside.com/ Mastering Enterprise Java Beans
by Ed Roman , Scott Ambler & Tyler Jewel.
EJB Documentation http://java.sun.com/products/ejb/javadoc-R_0-fr/
http://my.execpc.com/~gopalan/java/java_tutorial.html

  ( - % %     %  (  +  ( 
For !  Open Source go to http://www.jboss.org/downloads/index
http://www.kevinboone.com/jboss_tut_1.html
SUN¶s downloads and examples
http://developers.sun.com/prodtech/javatools/jsstandard/reference/docs/s1s5/partsuppliers.html
http://java.sun.com/jRse/1.4.R/download.html ,http://java.sun.com/jRee/1.4/docs/tutorial/doc/
http://java.sun.com/developer/onlineTraining/EJBIntro/EJBIntro.html
BEA WebLogic downloads and examples ( 
http://commerce.bea.com/index.jsp , http://www.weblogic.com/docs/examples/index.html 1R% 
|
http://devRdev.bea.com/codelibrary/code/examples_ejbR0.jsp
WebSphere downloads and examples
http://www-306.ibm.com/software/webservers/appserv/doc/vR0dcadv/doc/howto/ep001.html
REDHAT Application Server and Examples
http://www.redhat.com/docs/manuals/rhaps/jonas-guide/