Professional Documents
Culture Documents
Patrones de Diseño JEE
Patrones de Diseño JEE
TM
Java EE Patterns
SL-314
TM
Java EE Patterns
SL-314-EE5
SL-500-EE5
Java EE Patterns
Copyright 2008 Sun Microsystems, In. 4150 Network Circle, Santa Clary, California 95054, U.S.A. All rights reserved.
This product or document is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation. No part of this product or document may
be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any.
Third-party software, including font technology, is copyrighted and licensed from Sun supplier.
Sun, Sun Microsystems, the Sun logo, EJB, Enterprise Javanese, J2EE, J2ME, Java, Java Center, Javanese, Juvenal, Java Script, Java Server, Java Server Pages, JDBC, JDK, Java Naming and
Directory Interface, JSP, Sailors, J2SE, JVM, and are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC
trademarks are based upon an architecture developed by Sun Microsystems, Inc.
UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open Company, Ltd.
The OPEN LOOK and Sun Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching
and developing the concept of visual or graphical user interfaces for the computer industry. Sun holds a non-exclusive license from Xerox to the Xerox Graphical User Interface, which
license also covers Suns licensees who implement OPEN LOOK GUIs and otherwise comply with Suns written license agreements.
U.S. Government approval might be required when exporting the product.
RESTRICTED RIGHTS: Use, duplication, or disclosure by the U.S. Government is subject to restrictions of FAR 52.227-14(g)(2)(6/87) and FAR 52.227-19(6/87), or DFAR 252.227-7015
(b)(6/95) and DFAR 227.7202-3(a).
DOCUMENTATION IS PROVIDED AS IS AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS, AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE
HELD TO BE LEGALLY INVALID.
Copyright 2008 Sun Microsystems Inc. 4150 Network Circle, Santa Clara, California 95054, Etats-Unis. Tous droits rservs.
Ce produit ou document est protg par un copyright et distribu avec des licences qui en restreignent lutilisation, la copie, la distribution, et la dcompilation. Aucune partie de ce
produit ou document ne peut tre reproduite sous aucune forme, par quelque moyen que ce soit, sans lautorisation pralable et crite de Sun et de ses bailleurs de licence, sil y en a.
Le logiciel dtenu par des tiers, et qui comprend la technologie relative aux polices de caractres, est protg par un copyright et licenci par des fournisseurs de Sun.
Sun, Sun Microsystems, le logo Sun, EJB, Enterprise JavaBeans, J2EE, J2ME, Java, Java Center, JavaBeans, JavaMail, JavaScript, JavaServer, JavaServer Pages, JDBC, JDK, Java Naming
and Directory Interface, JSP, Solaris, J2SE, JVM, and SunTone are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
Toutes les marques SPARC sont utilises sous licence sont des marques de fabrique ou des marques dposes de SPARC International, Inc. aux Etats-Unis et dans dautres pays. Les
produits portant les marques SPARC sont bass sur une architecture dveloppe par Sun Microsystems, Inc.
UNIX est une marques dpose aux Etats-Unis et dans dautres pays et licencie exclusivement par X/Open Company, Ltd.
Linterfaces dutilisation graphique OPEN LOOK et Sun a t dveloppe par Sun Microsystems, Inc. pour ses utilisateurs et licencis. Sun reconnat les efforts de pionniers de Xerox
pour larecherche et le dveloppement du concept des interfaces dutilisation visuelle ou graphique pour lindustrie de linformatique. Sun dtient une licence non exclusive de Xerox sur
linterface dutilisation graphique Xerox, cette licence couvrant galement les licencis de Sun qui mettent en place linterface dutilisation graphique OPEN LOOK et qui en outre se
conforment aux licences crites de Sun.
Laccord du gouvernement amricain est requis avant lexportation du produit.
LA DOCUMENTATION EST FOURNIE EN LETAT ET TOUTES AUTRES CONDITIONS, DECLARATIONS ET GARANTIES EXPRESSES OU TACITES SONT FORMELLEMENT
EXCLUES, DANS LA MESURE AUTORISEE PAR LA LOI APPLICABLE, Y COMPRIS NOTAMMENT TOUTE GARANTIE IMPLICITE RELATIVE A LA QUALITE MARCHANDE, A
LAPTITUDE A UNE UTILISATION PARTICULIERE OU A LABSENCE DE CONTREFAON.
Table of Contents
About This Course ............................................................................................................ Preface-i
Course Goals................................................................................................................................. Preface-ii
Course Map..................................................................................................................................Preface- iii
Topics Not Covered ....................................................................................................................Preface-iv
How Prepared Are You?.............................................................................................................. Preface-v
Introductions ...............................................................................................................................Preface-vii
Icons ........................................................................................................................................... Preface-viii
Typographical Conventions ...................................................................................................... Preface-ix
Additional Conventions............................................................................................................... Preface-x
Java EE Patterns
2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
2-16
2-17
2-19
2-20
2-21
2-22
2-24
2-25
2-26
2-27
2-28
2-29
2-31
2-33
2-34
2-35
2-36
2-37
2-42
2-43
2-45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
3-4
3-5
3-6
3-7
3-8
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
6-2
6-3
6-4
6-5
6-6
6-7
6-8
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
10
Summary ................................................................................................................................................ 9- 60
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
11
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
12
11-22
11-23
11-24
11-25
11-26
11-30
11-32
11-33
11-34
11-35
11-36
11-37
11-40
11-41
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
13
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
14
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
15
Table of Contents
Quick Reference for UML ........................................................................................A-1
J2EE Technology Review ........................................................................................B-1
Objectives ..................................................................................................................................................B-2
Reviewing the J2EE Platform ................................................................................................................B-3
Multi-Tier J2EE Architecture Basics ..................................................................................................... B-6
Understanding Java Remote Method Invocation............................................................................... B-7
Understanding the Java IDL API ........................................................................................................B-15
Understanding the JAX-RPC API .......................................................................................................B-17
Understanding the Java Naming and Directory Interface (JNDI) API .....................................B-24
JNDI API Class ...................................................................................................................................... B-25
Understanding Servlets........................................................................................................................ B-27
Servlet Class ...........................................................................................................................................B-28
Understanding JavaServer Pages Technology ..............................................................................B-32
JSP Page Flow ........................................................................................................................................B-33
HTML Form Processed by a JSP Page ................................................................................................B-34
JSP Page ..................................................................................................................................................B-35
Understanding the Java Message Service (JMS) API .......................................................................B-38
Understanding the JMS API ................................................................................................................B-39
Understanding the JMS API ................................................................................................................B-40
Understanding the JMS API ................................................................................................................B-41
Understanding Enterprise JavaBeans Technology Components ............................................... B-48
Overall Enterprise JavaBeans Architecture........................................................................................B-49
Overall Enterprise JavaBeans Architecture: Parts of an EJB Component .....................................B-50
Three Types of EJB Components ........................................................................................................B-54
Java EE Patterns
2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
16
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
17
Preface
About This Course
Preface
Preface
About The Course
Java EE Patterns
Course Goals
Upon completion of this course, you should be able to:
Describe the fundamentals of design patterns,
including key Gang of Four patterns
Apply appropriate patterns in the tiers (Integration,
Business, and Presentation) of a Java 2 Platform,
Enterprise Edition (Java EE platform) application
Use patterns to apply best practices in a Java EE
platform environment
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Preface, slide 2 of 10
Using
Presentation
Tier Patterns
More Presentation
Tier Patterns
Using
Intra-Business
Tier Patterns
Introducing
Java EE Patterns
Using
Presentation-to-Business
Tier Patterns
Using Architectural
Building Blocks
Applying
Java EE BluePrints
Design Guidelines
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Exploring AntiPatterns
Preface, slide 3 of 10
Using
Integration
Tier Patterns
Exploring Object-Oriented
Design Principles and
Design Patterns
Pattern Fundamentals
Course Map
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Preface, slide 4 of 10
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Preface, slide 5 of 10
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Preface, slide 6 of 10
Introductions
Name
Company affiliation
Title, function, and job responsibility
Experience related to topics presented in this course
Reasons for enrolling in this course
Expectations for this course
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Preface, slide 7 of 10
Icons
Additional resources
1
2
3
Demonstration
Discussion
Note
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Preface, slide 8 of 10
Typographical Conventions
Courier is used for the names of commands, files,
directories, programming code, programming
constructs, and on-screen computer output.
Courier bold is used for characters and numbers
that you type, and for each line of programming code
that is referenced in a textual description.
Courier italics is used for variables and
command-line placeholders that are replaced with a
real name or value.
Courier italics bold is used to represent
variables whose values are to be entered by the student
as part of an activity.
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Preface, slide 9 of 10
Additional Conventions
Java programming language examples use the following
additional conventions:
Courier is used for the class names, methods,
and keywords.
Methods are not followed by parentheses unless a
formal or actual parameter list is shown.
Line breaks occur where there are separations,
conjunctions, or white space in the code.
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Preface, slide 10 of 10
Module 1
Module 1
Developing
a View Component
Module
1
Exploring
Exploring
Object-Oriented
ObjectPrinciples
Orientedand
Design
Design
Principles And
Design
Patterns
Design Patterns
Java EE Patterns
Objectives
Describe the fundamental object-oriented
design concepts
Describe the fundamental object-oriented
design principles
Describe the characteristics of design patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 2 of 38
Adaptability
Extensibility
Maintainability
Reusability
Performance
Scalability
Reliability
Development efficiency
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 3 of 38
Course Flow
The course presents the following topics to reach these goals:
Object-Oriented Design Principles
Architectural Patterns
Anti-Patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 4 of 38
Cohesion
Encapsulation
Coupling
Implementation
inheritance
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Composition
Interface inheritance
Polymorphism
Module 1, slide 5 of 38
Cohesion
Cohesion is the degree to which the methods and
attributes of a class focus on only one purpose
in the system
Advantages of high cohesion:
Avoids the side affects of changing unrelated code
within the same class
Improves readability by clarifying the class role
Facilitates the creation of small reusable components
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 6 of 38
High Cohesion
SystemServices
LoginService
+deleteDepartment()
+deleteEmployee()
+login()
+logout()
+makeDepartment()
+makeEmployee()
+retrieveDeptByID()
+retrieveEmpByName()
+login()
+logout()
EmployeeService
+deleteEmployee()
+makeEmployee()
+retrieveEmpByName()
DepartmentService
+deleteDepartment()
+makeDepartment()
+retrieveDeptByID()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 7 of 38
Encapsulation
The internal structure and behavior of an object should
not be exposed
Information hiding is key to proper encapsulation:
Data should be kept private
Accessor and mutator methods should provide an
abstract interface to the data
Advantages:
Implementation of a class can vary without
changing its interface
Developers can use the class without knowing all of
its implementation details
Inappropriate attribute modifications are prevented
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 8 of 38
Encapsulation Example
Classes
Objects
Engineer
-fname:String
-lname:String
-salary:Money
:Engineer
fname="Fred"
lname="Cartz"
salary=US$47,000
+getFirstName():String
+getLastName():String
+setFirstName(:String)
+increaseSalary(amt)
+analyzeReq()
+designSoftware()
+implementCode()
main
Stack
employee
department
name = employee.fname;
name = employee.getFirstName();
employee.fname = "Samantha";
employee.setFirstName("Samantha");
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 9 of 38
Encapsulation Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Engineer {
private String fname;
private String lname;
private Money salary;
public String getFirstName() {
return fname;
}
public String getLastName() {
return lname;
}
public void setFirstName(String fn) {
fname = fn;
}
...
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 10 of 38
Coupling
Coupling is a measure of how dependant classes are on
other classes
To reduce coupling:
Hide the implementation of the classes
Couple to the abstract interface of a class
Reduce the number of methods in the interface
of the class
Consider the coupling of the entire system rather than
just between individual classes
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 11 of 38
Looser Coupling
Client
Service
Client
<<interface>>
Service
No Coupling
Client
Service
ServiceImpl
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 12 of 38
Implementation Inheritance
Implementation inheritance is inheriting shared attributes
and methods from a superclass
Advantages:
Avoids duplication of code that is common to subtypes
Organizes classes according to inheritance
Disadvantages:
Forces subclass to inherit everything from
its superclass
Changes to the superclass might affect the subclass
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 13 of 38
class Employee
{
. . .
}
class Manager extends Employee
{
. . .
}
Employee
-fname : String
-lname : String
-salary : Money
+getFname() : String
+getLname() : String
+getSalary() : Money
+increaseSalary( : int )
+setFname( fname : String )
+setLname( lname : String )
+setSalary( salary : Money )
Manager
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
-quarterlyBonus : Money
+increaseBonus()
+playGolfWithClient()
Engineer
-education : String
-hardware : String
+analyzeReq()
+designSoftware()
+getEducation()
+getHardware()
+implementCode()
Module 1, slide 14 of 38
Composition
Builds complex objects from simpler objects
Forms a looser coupling than
implementation inheritance
Department
1
2
3
4
Employee
class Department {
private Employee worker;
.. .
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 15 of 38
Interface Inheritance
Interface inheritance is the separation of an interface
definition from its implementation:
Similar to hardware devices that implement a
common interface
Can make a class extensible without being modified
Java technology-based interfaces (Java interfaces)
provide pure interface inheritance; abstract classes
allow a mixture of implementation and
interface inheritance
This course uses interfaces whenever possible and
leaves it to the attendee to determine whether an
abstract class or interface is more appropriate for them
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 16 of 38
<<interface>>
Schedulable
+cancelActivity()
+notifyAboutActivity()
Employee
1
2
3
4
5
6
7
8
Equipment
ConferenceRoom
interface Schedulable {
public void cancelActivity();
public void notifyAboutActivity();
}
class Equipment implements Scheduable {
public void cancelActivity() {//implementation}
public void notifyAboutActivity() {//implementation}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 17 of 38
Polymorphism
Polymorphism allows invocation of operations of
specific objects through generic references
Aspects of polymorphism:
A variable can be assigned different types at runtime
Method implementation is determined by the object
type, not the reference type
Advantages:
Enables you to write generic code that does not depend
upon a specific subclass
Allows you to code fewer methods because a supertype
can be specified as the parameter type
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 18 of 38
Polymorphism Example
Classes
Objects
Employee
Kathy:Manager
Fred:Engineer
Manager
Engineer
Samantha:Engineer
Stack
main
:List
employee
list
List list = getProjectTeam();
for ( int i=0; i<list.size(); i++ ) {
Employee employee = (Employee) list.get(i);
employee.increaseSalary(0.10); //10%
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 19 of 38
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 20 of 38
Favoring Composition
Favor object composition over [implementation]
inheritance. (Gamma, Helm, Johnson, and Vlissides,
Design Patterns: Elements of Reusable Object-Oriented
Software)
Reuse functionality through composition instead of
implementation inheritance:
Implementation inheritance is white-box reuse
Composition is black-box reuse
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 21 of 38
Favoring Composition
Composition
Implementation Inheritance
ArrayList
-elementData : Object
-size : int
...
+add( o : Object ) : boolean
+ArrayList( initialCapacity : int )
+clear()
+get( index : int ) : Object
+remove( index : int )
+size() : int
...
DepartmentEmployeeList
-departmentName : String
+addEmployee( e : Employee ) : boolean
+fireEmployee( e : Employee )
+getDepartmentName() : String
+getEmployee( ssn : String ) : Employee
+getNumEmployees() : int
+setDeptName( deptName : String )
...
ArrayList
-elementData : Object
-size : int
...
+add( o : Object ) : boolean
+clear()
+get( index : int ) : Object
+remove( index : int )
+size() : int
...
DepartmentEmployeeList
-departmentName : String
+getDepartmentName() : String
+setDeptName( deptName ) : String
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 22 of 38
Programming to an Interface
Program to an interface, not an implementation. (Gamma,
Helm, Johnson, and Vlissides, Design Patterns: Elements of
Reusable Object-Oriented Software)
DepartmentEmployeeList
-departmentName : String
<<interface>>
Collection
ArrayList
-elementData
-size : int
...
+add( o : Object ) : boolean
+ArrayList( initialCapacity : int )
+clear()
+get( index : int ) : Object
+remove( index : int )
+size() : int
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 23 of 38
Programming to an Interface
Programming to the ArrayList Implementation:
1
2
3
4
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 24 of 38
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 25 of 38
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 26 of 38
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 27 of 38
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 28 of 38
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 29 of 38
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 30 of 38
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 31 of 38
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 32 of 38
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 33 of 38
Schedule
creates
+addActivity(
: Schedulable )
Role names
Association
<<interface>>
Schedulable
Multiplicity
Realization
(implements)
Interface
0..* -scheduleItems
+cancelActivity()
+notifyAboutActivity()
Abstract class
private String
fname;
Equipment
Employee
{abstract}
ConferenceRoom
Generalization
(extends)
-fname : String
-lname : String
-numEmployees : int
-salary : Money
public String
getFname()
+getFname() : String
+increaseSalary( : int )
+setFname( fname : String )
...
Manager
-quarterlyBonus : Money
+increaseBonus()
+increaseSalary( : int )
+playGolfWithClient()
Engineer
-education : String
-hardware : String
+analyzeReq()
+designSoftware()
+increaseSalary( : int )
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 34 of 38
Creation of object
notifyAboutActivity
method calls
notifyObservers method
in the same class
: Scheduler
1: create()
: Schedule
2: create()
projector : Equipment
3: addActivity( projector )
3.1: notifyAboutActivity
Method call or
some form of
communication
3.1.1: notifyObservers
4:create()
Activation bar
shows when the
object is actively
working or waiting
for a response
fifthFloor : ConferenceRoom
5: addActivity( fifthFloor )
5.1:notifyAboutActivity
5.1.1:notifyObservers
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 35 of 38
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 36 of 38
Summary
The following object-oriented concepts
can help you focus on improving
Java EE designs:
Cohesion
Encapsulation
Implementation inheritance
Interface inheritance
Polymorphism
Coupling
Composition
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Structural
Architectural Patterns
Anti-Patterns
Module 1, slide 37 of 38
Summary
The following GoF principles can help you achieve the Java
EE platform design goals:
Favoring composition
Programming to an interface
Designing for change
Design patterns will help you reuse the experience of other
designers to improve your Java EE platform software
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 1, slide 38 of 38
Module 2
Module 2
Using Gang
Module
2 of Four Behavioral Patterns
Using Gang of Four
Behavioral
Patterns
Using Gang
Of Four
Behavioral Patterns
Java EE Patterns
Objectives
Describe the basic characteristics of the
Behavioral patterns
Apply the Strategy pattern
Apply the Command pattern
Apply the Iterator pattern
Apply the Observer pattern
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 2 of 45
Primary Function
Encapsulates a family of algorithms for
interchangeable use
Encapsulates requests in objects for execution
by another object
Traverses any collection in a loosely coupled
way
Provides notification of events without
polling
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 3 of 45
//perform search
//perform merge sort
return list;
+search() : ArrayList
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 4 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 5 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 6 of 45
strategy.doTask();
Client
<<interface>>
Strategy
-strategy
doTask()
+task()
ConcreteStrategy1
ConcreteStrategy2
ConcreteStrategy3
doTask()
doTask()
doTask()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 7 of 45
CatalogSearchEngine
+search() : ArrayList
<<interface>>
SortStrategy
-sorter
+sort(
: ArrayList )
//perform search
sorter.sort(list);
return list;
QuickSort
+sort(
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
: ArrayList )
MergeSort
+sort(
: ArrayList )
Module 2, slide 8 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 9 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 10 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 11 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 12 of 45
Client
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 13 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 14 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 15 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 16 of 45
Client
Invoker
<<interface>>
Command
+doCommand( c : Command )
create
+execute()
SpecificCommand1
SpecificCommand2
+execute()
+execute()
create
implementation of action
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 17 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 18 of 45
lastCommand++;
if (lastCommand < history.size()
history.get(lastCommand).execute();
LibraryCommandInvoker
-lastCommand : int
history
+executeCommand( lc : Command )
+redoNextCommand()
+undoLastCommand()
<<interface>>
Command
0..* +execute()
+undo()
CheckOutCommand
history.get(lastCommand).undo();
lastCommand--;
item = r;
thePatron = p;
-item : Resource
-thePatron : Patron
+CheckOutCommand( p : Patron, r : Resource )
+execute()
+undo()
CheckInCommand
check out the resource
-item : Resource
-thePatron : Patron
create
Client
PutOnHoldCommand
create
-item : Resource
-thePatron : Patron
+execute()
+PutOnHoldCommand( r : Resource, p : Patron )
+undo()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 19 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 20 of 45
RoutingLogic
1: Command
( InitialState )
<<SessionBean>>
Invoker
remote:Command
Business Objects
local : Command
2: doCommand
( local:Command )
2.1: doCommand
( remote:Command )
2.1.1: execute
2.1.1.1: doWork
return
return
return
return
3: getResults
return
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 21 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 22 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 23 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 24 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 25 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 26 of 45
<<interface>>
Aggregate
Client
+createIterator() : Iterator
+hasNext() : boolean
+next() : Object
create
ConcreteAggregate
<<interface>>
Iterator
ConcreteIterator
-data
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 27 of 45
Client
<<interface>>
CatalogIterator
+getIterator() : CatalogIterator
ResultSetWrapper
+currentElement()
+hasMoreElements()
+nextElement()
+previousElement()
ResultSetIterator
creates
+getIterator() : CatalogIterator
LegacyDataSource
creates
LegacyIterator
+getIterator() : CatalogIterator
TestIFileSource
creates
TestFileIterator
+getIterator() : CatalogIterator
return new
ResultSetIterator();
return new
TestFileIterator();
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
return new
LegacyIterator();
Module 2, slide 28 of 45
<<interface>>
Iterator
+iterator() : Iterator
+hasNext() : boolean
+next()
+remove() : void
...
Set
<<interface>>
List
<<interface>>
ListIterator
+listIterator() : ListIterator
+add( o ) : void
+hasNext() : boolean
+hasPrevious() : boolean
+next()
+nextIndex() : int
+previous()
+previousIndex() : int
+remove() : void
+set( o ) : void
...
HashSet
LinkedList
Vector
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
ArrayList
Module 2, slide 29 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 30 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 31 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 32 of 45
FaultMessageGenerator
+faultOccurred( faultType : int, faultMsg : String )
-eMailer
FaultEMailer
logger.log(faultType, faultMsg);
eMailer.sendEMail(faultType, faultMsg);
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 33 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 34 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 35 of 45
Subject
{abstract}
add o to observers
-observes
+attach( o : Observer )
+detach( o : Observer )
+notify()
0..*
<<interface>>
Observer
+update()
ConcreteSubject -subject
1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
ConcreteObserver
+update()
Module 2, slide 36 of 45
-listeners
while (listener.hasNext())
listeners.next().handleFault(faultType, faultMsg);
0..*
FaultListener
FaultLogger
FaultPager
FaultEMailer
+handleFault( faultType : int, faultMsg : String )
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 37 of 45
import java.util.*;
public class FaultMessageGenerator {
private ArrayList listeners = new ArrayList();
public void addFaultListener(FaultListener listener) {
listeners.add(listener);
}
public void faultOccurred(int faultType, String faultMsg) {
Iterator listenersI = listeners.iterator();
while(listenersI.hasNext()) {
FaultListener fl = (FaultListener) listenersI.next();
fl.handleFault(faultType,faultMsg);
} }
public void removeFaultListener(FaultListener listener) {
listeners.remove(listener);
}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 38 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 39 of 45
import java.util.logging.*;
public class FaultLogger implements FaultListener{
private static Logger logger = Logger.getLogger("");
public FaultLogger(FaultMessageGenerator fmg) {
fmg.addFaultListener(this);
}
public void handleFault(int faultType, String faultMsg) {
logger.log(Level.WARNING,
"A " + faultType + " occurred: " + faultMsg);
}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 40 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 41 of 45
Handler
{abstract}
handlers.remove(handler);
ConsoleHandler
FileHandler
SocketHandler
...
...
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 42 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 43 of 45
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 44 of 45
Summary
Behavioral patterns focus on algorithms
and the distribution of responsibilities
between classes:
Structural
Architectural Patterns
Anti-Patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 2, slide 45 of 45
Module 3
Module 3
Using
Gang
of
Four
Creational
Patterns
Module 3
Using Gang of Four
Creational
Patterns
Using
Gang
Of Four
Creational Patterns
Java EE Patterns
Objectives
Describe the basic characteristics of the
Creational patterns
Apply the Factory Method pattern
Apply the Abstract Factory pattern
Apply the Singleton pattern
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 2 of 23
Primary Function
Creates objects of a class or its
subclasses through a method call
Creates a family of objects
through a single interface
Restricts a class to one globally
accessible instance
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 3 of 23
HotelARoomList
create
Client
create
HotelBRoomList
uses
create
uses
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
HotelCRoomList
Module 3, slide 4 of 23
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 5 of 23
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 6 of 23
uses
Client
<<interface>>
Factory
requests
+createProduct() : Product
ConcreteProduct1
create
ConcreteFactory1
return new ConcreteProduct1();
+createProduct() : Product
ConcreteProduct2
create
ConcreteFactory2
return new ConcreteProduct2();
+createProduct() : Product
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 7 of 23
-rooms
Client
moreRooms()
nextRoom()
HotelARoomList
<<interface>>
RoomFinder
-finder
+createList() : RoomList
create
HotelARoomFinder
return new HotelARoomList();
+createList() : RoomList
HotelBRoomList
create
HotelBRoomFinder
return new HotelBRoomList();
+createList() : RoomList
HotelCRoomList
create
HotelCRoomFinder
return new HotelCRoomList();
+createList() : RoomList
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 8 of 23
<<interface>>
Statement
+createStatement() : Statement
+executeQuery() : ResultSet
...
...
OracleConnection
<<interface>>
ResultSet
OracleStatement
create
+createStatement() : Statement
create
+executeQuery() : ResultSet
...
...
SybaseConnection
SybaseStatement
create
+createStatement() : Statement
...
OracleResultSet
SybaseResultSet
create
+executeQuery() : ResultSet
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 9 of 23
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 10 of 23
ReservationA
CustomerA
RoomA
+calculateBill()
+confirm()
+getPreferences()
+getDescription()
+getRate()
create
create
create
create
Client
create
create
HotelChainB
create
create
ReservationB
CustomerB
RoomB
+calculateBill()
+confirm()
+getPreferences()
+getDescription()
+getRate()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 11 of 23
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 12 of 23
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 13 of 23
uses
<<interface>>
ProductA
uses
requests
<<interface>>
Factory
+createProductA()
+createProductB()
ProductA1
ProductA2
create
create
ConcreteFactory1
ConcreteFactory2
+createProductA()
+createProductB()
+createProductA()
+createProductB()
create
<<interface>>
ProductB
ProductB1
ProductB2
create
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 14 of 23
Client
<<interface>>
Room
uses
+getDescription()
+getRate()
<<interface>>
HotelChain
+createCustomer() : Customer
+createReservation() : Reservation
+createRoom() : Room
RoomA
RoomB
+getDescription()
+getRate()
+getDescription()
+getRate()
create
<<interface>>
Reservation
HotelChainA
create
+createCustomer() : Customer
+createReservation() : Reservation
+createRoom() : Room
+calculateBill()
+confirm()
HotelChainB
+createCustomer() : Customer
+createReservation() : Reservation
+createRoom() : Room
ReservationA
ReservationB
+calculateBill()
+confirm()
+calculateBill()
+confirm()
create
create
create
create
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<interface>>
Customer
+getPreferences()
CustomerA
CustomerB
+getPreferences()
+getPreferences()
Module 3, slide 15 of 23
Disadvantages:
Developing new families correctly can be time consuming
Adding family members to an existing scheme
can be difficult
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 16 of 23
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 17 of 23
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 18 of 23
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
if (uniqueInstance == null) {
uniqueInstance = new Singleton();
}
return uniqueInstance;
Module 3, slide 19 of 23
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 20 of 23
ClientA
ThreadPool
uses
-singleInstance : ThreadPool
ClientB
uses
+getInstance() : ThreadPool
+getThread() : Thread
+returnThread( : Thread )
-ThreadPool()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 21 of 23
Disadvantages:
Singleton can replace global variables, but this hint is
often misapplied
Singleton must make on-demand instances thread-safe
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 3, slide 22 of 23
Summary
Gang of Four creational patterns hide the
details of object creation:
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Behavioral
Creational
Structural
Architectural Patterns
Anti-Patterns
Module 3, slide 23 of 23
Module 4
Module 4
Using Gang
Module
4 of Four Structural Patterns
Using Gang of Four
Using Gang
Of Four
Structural
Patterns
Structural Patterns
Java EE Patterns
Objectives
Describe the basic characteristics of the
Structural patterns
Apply the Faade pattern
Apply the Proxy pattern
Apply the Adapter pattern
Apply the Composite pattern
Apply the Decorator pattern
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 2 of 46
Primary Function
Provides a simplified interface to a
subsystem.
Provides an intermediate object which
controls access to another object.
Enables a caller to use an object that has an
incompatible interface.
Composes objects into part-whole tree
structures.
Attaches new functionality to an object
dynamically.
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 3 of 46
Guest
+updateProfile()
0..*
Room
+issueWakeUpCall()
+updateStatus()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Reservation
+cancel()
+create()
+update()
0..*
Module 4, slide 4 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 5 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 6 of 46
Class1
Client
Facade
Class2
+request()
Class3
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 7 of 46
HotelSearchService
+findRooms()
Guest
ReservationServiceFacade
+updateProfile()
0..*
Client
+cancelReservation()
+confirmReservation()
+findRoom()
+makeReservation()
+modifyReservation()
Room
+issueWakeUpCall()
+updateStatus()
Reservation
+cancel()
+create()
+update()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
0..*
Module 4, slide 8 of 46
: ReservationServiceFacade : HotelSearchService
: Room
: Guest
: Reservation
1: makeReservation
1.1: findRooms
1.2: updateStatus
1.3: updateProfile
1.4: create
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 9 of 46
Disadvantage:
Introduces an extra level of indirection, which might
impact performance.
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 10 of 46
-imageData : byte[][]
0..*
+getImage() : byte[][]
+getSize() : Dimension
+RoomTypeImage()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 11 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 12 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 13 of 46
<<interface>>
Subject
Client
+request()
Proxy
+request()
-impl
RealSubject
actual implementation
+request()
impl.request()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 14 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 15 of 46
Client
0..*
<<interface>>
RoomTypeImage
+getImage() : byte[][]
+getSize() : Dimension
ProxyRoomTypeImage
ActualRoomTypeImage
-realImage
+getImage() : byte[][]
+getSize() : Dimension
if (realImage == null)
realImage = new ActualRoomTypeImage();
return realImage.getImage();
-imageData : byte[][]
+ActualRoomTypeImage()
+getImage() : byte[][]
+getSize() : Dimension
if (realImage == null)
realImage = new ActualRoomTypeImage();
return realImage.getSize();
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 16 of 46
<<interface>>
RemoteBusiness
+doTask()
Client
Stub
+doTask()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
RemoteBusinessImpl
+doTask()
Actual Implementation
Module 4, slide 17 of 46
Disadvantages:
An extra level of indirection is introduced that might
impact performance
Interaction with the proxy is not always transparent
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 18 of 46
<<interface>>
Searchable
+searchByAuthor( author : String ) : ArrayList
+searchByCallNumber( callNum : String ) : ArrayList
+searchByTitle( title : String ) : ArrayList
Library1SearchEngine
+searchByAuthor( author : String ) : ArrayList
+searchByCallNumber( callNum : String ) : ArrayList
+searchByTitle( title : String ) : ArrayList
Library3SearchEngine
+recall()
+searchByCallNumber( callNum : String ) : ArrayList
+titleSearch( title : char[] ) : ArrayList
Library2SearchEngine
+searchByAuthor( author : String ) : ArrayList
+searchByCallNumber( callNum : String ) : ArrayList
+searchByTitle( title : String ) : ArrayList
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Incompatible Interface
Module 4, slide 19 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 20 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 21 of 46
<<interface>>
DesiredInterface
+doTask1()
+doTask2()
+doTask3()
Adaptee
+doTask2()
+firstTask()
-adaptee
return adaptee.firstTask()
Adapter
+doTask1()
+doTask2()
+doTask3()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
return adaptee.doTask2()
full implementation
Module 4, slide 22 of 46
<<interface>>
DesiredInterface
+doTask1()
+doTask2()
+doTask3()
Adaptee
+doTask2()
+firstTask()
return firstTask()
Adapter
+doTask1()
+doTask3()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
full implementation
Module 4, slide 23 of 46
Library3SearchEngine
+recall()
+searchByCallNumber( callNum : String ) : ArrayList
+titleSearch( title : char[] ) : ArrayList
-adaptee
Library1SearchEngine
+searchByAuthor( author : String ) : ArrayList
+searchByCallNumber( callNum : String ) : ArrayList
+searchByTitle( title : String ) : ArrayList
Library2SearchEngine
+searchByAuthor( author : String ) : ArrayList
+searchByCallNumber( callNum : String ) : ArrayList
+searchByTitle( title : String ) : ArrayList
Library3SearchEngineAdapter
+searchByAuthor( author : String ) : ArrayList
+searchByCallNumber( callNum : String ) : ArrayList
+searchByTitle( title : String ) : ArrayList
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
full implementation
return
adaptee.searchByCallNumber(callNum);
Module 4, slide 24 of 46
import java.util.ArrayList;
public class Library3SearchEngineAdapter
implements Searchable {
private Library3SearchEngine adaptee =
new Library3SearchEngine();
public ArrayList searchByAuthor(String author) {
//... full implementation of search by author
return results;
}
public ArrayList searchByCallNumber(String callNum) {
return adaptee.searchByCallNumber(callNum);
}
public ArrayList searchByTitle(String title) {
char t[] = title.toCharArray();
return adaptee.titleSearch(t);
}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 25 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 26 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 27 of 46
VPSales : Manager
: SalesPerson
: SalesPerson
: SalesPerson
CanadianOperations: Manager
VPOperations : Manager
FrenchOperations: Manager
GermanOperations: Manager
: SalesPerson
OttawaHotel : Manager
: Clerk
MarkhamHotel : Manager
: Concierge
: Clerk
: Clerk
: Clerk
: Concierge
ParisHotel : Manager
: Clerk
: Concierge
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
: Clerk
: Clerk
: Concierge
: Concierge
: SalesPerson
BerlinHotel : Manager
Module 4, slide 28 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 29 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 30 of 46
-children
+operation()
0..*
Part
Composite
+operation()
full implementation
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 31 of 46
-subordinates
0..*
+calculateDeptPay() : double
+calculatePay() : double
Clerk
Concierge
-basePayRate : double
-individualBonus : double
-overtimeHours : int
-basePayRate : double
-individualBonus : double
-tips : double
+calculateDeptPay() : double
+calculatePay() : double
+calculateDeptPay() : double
+calculatePay() : double
SalesPerson
-basePayRate : double
-comissionRate : double
-totalSales : double
return calculatePay();
Manager
-individualBonus : double
+addSubordinate( e : Employee )
+calculateDeptPay() : double
+calculatePay() : double
+getSubordinate( i : int ) : Employee
+removeSubordinate( e : Employee )
+calculateDeptPay() : double
+calculatePay() : double
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 32 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 33 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 34 of 46
Button
List
Container
+paint( g : Graphics )
+paint( g : Graphics )
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 35 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 36 of 46
FrenchPayWithTaxCalculator
CanadianPayWthTaxCalculator
+calculatePayWithoutRetirementFund()
+calculatePayWithRetirementFund()
+calculatePayWithoutRetirementFund()
+calculatePayWithRetirementFund()
GermanPayWithTaxCalculator
+calculatePayWithoutRetirementFund()
+calculatePayWithRetirementFund()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
double pay =
calculateBasePay();
pay -= calculateRetirement(pay);
pay -= calculateTax(pay);
Module 4, slide 37 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 38 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 39 of 46
1
-decoratee
+operation()
ConcreteComponent
+operation()
Decorator
+Decorator( d : Component )
+operation()
decoratee = d;
decoratee.operation();
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
//implentation of
decorator functionality
super.operation();
Module 4, slide 40 of 46
BasePayCalculator
+calculatePay()
-decoratee
PayCalculatorDecorator
+calculatePay()
+PayCalculatorDecorator(
: PayCalculator )
decoratee.calculatePay();
FrenchTaxCalculator
+calculatePay()
+FrenchTaxCalculator(
: PayCalculator )
GermanTaxCalculator
+calculatePay()
+GermanTaxCalculator(
: PayCalculator )
CanadianTaxCalculator
+calculatePay()
+CanadianTaxCalculator(
: PayCalculator )
RetirementFundCalculator
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
+calculatePay()
+RetirementFundCalculator(
: PayCalculator )
Module 4, slide 41 of 46
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 42 of 46
1: create()
calc1: BasePayCalculator
2: create( calc1 )
calc2: CanadianTaxCalculator
3: create( calc2 )
calc3: RetirementFundCalculator
4: calculatePay
4.1: calculatePay
4.2: calculatePay
return
return
return
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 43 of 46
FileInputStream
+close()
+FileInputStream( filename : String )
+read()
...
ByteArrayInputStream
FilterInputStream
+close()
+FilterInputStream( is : InputStream )
+read()
...
BufferedInputStream
DataInputStream
+BufferedInputStream( is : InputStream )
+close()
+read( byte[] )
...
+close()
+DataInputStream( is : InputStream )
+read()
+readChar() : char
+readDouble() : double
+readInt() : int
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 44 of 46
Disadvantages:
Decorator and decorated object are not the same, so object
identity becomes an issue
Many little objects get created, which can slightly decrease
performance
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 45 of 46
Summary
The GoF structural patterns:
Object-Oriented Design Principles
Structural
Architectural Patterns
Anti-Patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 4, slide 46 of 46
Module 5
Module
5
Module
Using5Architectural Building Blocks
Using
Architectural
Using Architectural
Building
Blocks
Building Blocks
Java EE Patterns
Objectives
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 2 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 3 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 4 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 5 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 6 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 7 of 25
Notify of Changes
Model
Get Data
Set Data Changes and
Request Processing
View
Controller
Select View
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 8 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 9 of 25
View
ReservationObservable
RoomObservable
notify
ReservationObserver
notify
ReservationList
get data
RoomObserver
ReservationListScreen
get data
RoomList
RoomAvailabilityListScreen
get data
GuestList
set data
set data
CheckInAndOutScreen
get data
set data
ReservationService
invoke
invoke
displays
Controller
CheckInEventHandler
CheckOutEventHandler
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 10 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 11 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 12 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 13 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 14 of 25
LayerN-1
Layer2
Layer1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 15 of 25
HTTP
TCP
IP
Ethernet
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 16 of 25
Disadvantages:
Adding a new functionality might affect every layer
Separating layers can increase communication overhead
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 17 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 18 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 19 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 20 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 21 of 25
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 22 of 25
Presentation Tier
BusinessTier
Integration Tier
Resource Tier
JDBC
Web Browser
Web Container
EJB Container
Java EE Connector
<%
Database
%>
JSP
Servlet
EJB
JavaMail
JAX-RPC
Java Beans/
Plain Old Java
Objects (POJO)
Non-Java Client
JavaIDL
Directory Service
Legacy Systems
ERP Systems
JTA/JTS
JMS
Java SEClient
Dependency
There are no patterns for the client and resources tiers since
those tiers are implemented outside the Java EE platform.
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 23 of 25
rc
tio
es
ou
gr
at
te
EJB
JMS
APPO
Upper
Any
Browser
iES
iAS
MQ
Series
CICS
Lower
Any
OS
Solaris
Solaris
Solaris
MVS
Hardware
Any
HW
E450
E5500
E250
ES9000
ta
g
JSP
in
or
izo
nt
al
Sc
al
ou
nd
ob
in
lu
st
er
in
HTML
Virtual
ue
ui
ng
Pr
es
en
In
Pr
Bu
es
si
en
ne
io
ss
tio
ta
nt
lie
C
es
Order
service
Legacy
order
system
Form
handler
Order
form
Order
system
interface
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Scaling
Strategy
Module 5, slide 24 of 25
Summary
Architectural patterns focus on the
strategic, high-level composite
structure of a solution
The MVC pattern separates
presentation management from
business logic
Layers are the hardware and
software stack within a given tier
Tiers are the logical or physical
organization of components into
an ordered chain of providers and consumers
Architectural Patterns
Anti-Patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 5, slide 25 of 25
Module 6
Module
6
Introducing Java EE Patterns
Module 6
Introducing
Java EE Patterns
Introducing
Java EE Patterns
Java EE Patterns
Objectives
Describe the Java EE pattern philosophy
Describe the Java EE patterns and tiers in the Java EE
pattern catalog
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 2 of 14
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 3 of 14
Benefits
The key benefits of the Java EE patterns include:
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 4 of 14
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 5 of 14
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 6 of 14
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 7 of 14
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 8 of 14
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 9 of 14
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 10 of 14
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 11 of 14
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 12 of 14
Forward To
Decorator
Integration Tier
Java EE Patterns
GoF
Behavioral Gang
of Four Patterns
GoF
Creational Gang
of Four Patterns
GoF
Structural Gang
of Four Patterns
Front Controller
Composite View
Presentation Tier
Java EE Patterns
Might Create
Strategy
Uses
Based On
Application
Controller
Might Use
Might invoke
Uses
Composite
Creates
Creates
Might Include
Dispatcher View
Uses
Uses
View Helper
Command
Service To Worker
Controller Invokes
Web Service Broker
Might Invoke
Business Delegate
Service Locator
Invokes
Might Execute
Observer
Context Object
Might Create
Might
Invoke
Might
Invoke
Uses
Delegates To
Session Facade
Might Invoke
Application Service
Might Invoke
Might Invoke
Might Be A
Proxy
Service Activator
Might Be A
Might
Create
Might Invoke
Might Invoke
Adapter
Based On
Might Be A
Singleton
Facade
Uses
Abstract Factory
Contains
Factory Method
Transfer Object
Assembler
Creates
Uses Functionality Of
Might Be A
Creates
Transfer Object
Might Be Created By
Composite Entity
Iterator
Might Get Data From
Might Be Created By
Transparently
Persists
Might Be Created By
Data Access Object
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Uses
Domain Store
Module 6, slide 13 of 14
Summary
Java EE patterns help to improve the
internal structure of applications by:
Creational
Structural
Architectural Patterns
Anti-Patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 6, slide 14 of 14
Module 7
Module 7
Using
Integration
Tier
Patterns
Module 7
Using Integration
Tier
Patterns
Using Integration
Tier Patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 1 of 51
Objectives
List the features and purpose of the Integration
Tier patterns
Apply the Service Activator pattern
Apply the Data Access Object (DAO) pattern
Apply the Domain Store pattern
Apply the Web Service Broker pattern
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 2 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 3 of 51
Primary Function
Service Activator
Domain Store
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 4 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 5 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 6 of 51
receives
creates/sends
<<MessageListener>>
ServiceActivator
activates
0..*
Client
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
BusinessComponent
Module 7, slide 7 of 51
Message Server
<<MessageListener>>
<<SessionEJB>>
<<POJO>>
: ServiceActivator : BusinessComponent : BusinessComponent2
<<Message>>
: Request
2. send( : Request )
3: send( :Request )
3.1. parseMessage
3.2 process
3.3 process
3.4 create()
: Acknowledgement
3.5: sendAcknowledgement
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 8 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 9 of 51
<<JMS Message>>
ObjectMessage
recieves
+close()
+onMessage( msg )
+ReservationConfirmationServiceActivator( connFactoryName, queueName )
+getObject()
-startListener()
+setObject( )
creates/sends
<<JMS Sender>>
ReservationConfirmationClient
+sendReservationConfirmation( reservationID )
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
activates
<<session bean>>
ReservationConfirmerBean
+confirmReservation( reservationID )
Module 7, slide 10 of 51
import javax.jms.*;
public class ResConfirmServiceActivator
implements MessageListener{
private QueueSession qSession;
private QueueReceiver qReceiver;
private String connFactoryName;
private String queueName;
private JMSServiceLocator serviceLocator;
public ResConfirmServiceActivator
(String cfn, String qn) {
connFactoryName = cfn;
this.queueName = qn;
startListener();
}
private void startListener() {
try {
serviceLocator =
new JMSServiceLocator(connFactoryName);
QueueConnectionFactory qConnFactory =
serviceLocator.getQueueConnectionFactory();
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 11 of 51
QueueConnection qConn =
qConnFactory.createQueueConnection();
qSession = qConn.createQueueSession
(true,Session.AUTO_ACKNOWLEDGE);
Queue shipBookQueue =
serviceLocator.getQueue(queueName);
qReceiver =
qSession.createReceiver(shipBookQueue);
qReceiver.setMessageListener(this);}
catch (JMSException e) {
e.printStackTrace();
}
}
public void onMessage(Message msg) {
try {
ObjectMessage objMsg = (ObjectMessage) msg;
String reservationID =
(String) objMsg.getObject();
//. . .Lookup and create bean
ReservationConfirmerLocal resConfirmer =...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 12 of 51
resConfirmer.confirmReservation
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(reservationID);
57
}
catch (JMSException e) {
e.printStackTrace();
}
}
public void close() {
try {
qReceiver.setMessageListener(null);
qSession.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 13 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 14 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 15 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 16 of 51
obtains, modifies
DataAccessObject
uses
encapsulates
DataSource
+DataAcessObject()
+delete( : TransferObject )
+find( . . . ) : TransferObject[]
+insert( : TransferObject )
+update( : TransferObject )
creates, uses
TransferObject
-propertyA
-propertyB
+getPropertyA()
+getPropertyB()
+setPropertyA()
+setPropertyB()
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 17 of 51
: DataSource
1. Create()
: DataAccessObject
2. find( . . . )
2.1 SELECT
2.2 Create()
return
: TransferObject
TransferObject
3. Set Property
4. update
4.1 GetProperty
4.2 UPDATE
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 18 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 19 of 51
RdbDAOFactory
XmlDAOFactory
+createDAO1()
+createDAO2()
+createDAO1()
+createDAO2()
creates
RdbDAO1
RdbDAO2
creates
XmlDAO1
<<interface>>
DAO1
+update(
: TransferObject )
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
XmlDAO2
<<interface>>
DAO2
+update(
: TransferObject )
...
Module 7, slide 20 of 51
BusinessObject
obtains/provides
ReservationTO
-endDate
-startDate
...
+getCustomer()
+getEndDate()
+getRoom()
+getStartDate()
+ReservationTO( . . . )
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 21 of 51
import
import
import
import
java.sql.*;
java.util.*;
javax.sql.*;
javax.naming.*;
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 22 of 51
(java.util.Date theDate)
throws DAOException {
ArrayList data = new ArrayList();
Connection conn=null;
PreparedStatement stmt = null;
ResultSet results = null;
try {
conn = ds.getConnection();
String query = "SELECT * FROM RESERVATION +
WHERE DATE = ?";
stmt = conn.prepareStatement(query);
stmt.setDate(1,
new java.sql.Date(theDate.getTime()));
results = stmt.executeQuery();
java.util.Date startDate, endDate;
while (results.next()) {
startDate = results.getDate("startDate");
endDate = results.getDate("endDate");
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 23 of 51
data.add(
new ReservationTO(startDate, endDate));
}
}
catch (SQLException e) {
throw new DAOException
("Error finding reservation", e);
}
finally {
try {
if (results != null)
results.close();
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
} catch (SQLException e) {
throw new DAOException
("Error closing connection", e);
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 24 of 51
}
}
return data;
}
public int deleteReservation
(String reservationID) throws DAOException{
Connection conn=null;
PreparedStatement stmt = null;
int count=0;
try {
conn=ds.getConnection();
String query= "DELETE FROM Reservation
+ WHERE ReservationID = ?";
stmt=conn.prepareStatement(query);
stmt.setString(1, reservationID);
count = stmt.executeUpdate();
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 25 of 51
}
//. . .implement exception handling
}
//. . .implement other access methods
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 26 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 27 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 28 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 29 of 51
+getPersistenceManager() : PersistenceManager
1
get/set data
<<interface>>
PeristenceCapable
1
consults
<<creates>>
ApplicationService
0..* BusinessObject
CRUD
PersistenceManager
+close()
+currentTransaction() : Transaction
+deletePersistent( : PersistenceCapable )
+makePersistent( : PersistenceCapable )
+newQuery( Class, String ) : Query
0..*
updates
Transaction
1
+begin()
+commit()
+rollback()
<<XML file>>
PersistMap
consults
<<DAO>>
executes
<<creates>>
1..* StoreManager
1..*
DataSource
CRUD
1..*
0..*
Query
+declareOperations( )
+execute( ) : Collection
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 30 of 51
: PersistenceManagerFactory
: PersistenceManager
<<DAO>>
: StoreManager
: DataSource
: BusinessObject
2: setData
3: getPersistenceManager
4: currentTransaction
4.1: create()
: Transaction
5: begin
6: makePersistent( busObj )
6.1: create()
: StateManager
6.1.1: setStateManager
7: commit
7.1: flushData
7.1.1: flushData
7.1.1.1: getData
7.1.1.1.1: insert( data )
7.1.1.1.1.1: INSERT
7.2: commit
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 31 of 51
: PersistenceManager
<<DAO>>
: StoreManager
1: newQuery
( class, queryString )
1.1: create()
: BusinessObject
: DataSource
: Query
2: execute
( queryParameters )
2.1: getData
2.1.1: SELECT
2.2: returnRows
2.2.1: repeat for
each row
2.2.1.1: create()
: StateManager
2.2.1.2: create
2.2.1.3: setData
3: getData
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 32 of 51
package sl500;
import java.util.Date;
public class Payment {
private double amount;
private Date datePaid;
private PaymentMethod payMethod;
private Payment() {}
public Payment(double a, Date d, PaymentMethod p) {
amount = a;
datePaid = d;
payMethod = p;
}
//. . .standard plain get/set methods
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 33 of 51
package sl500;
import java.util.Date;
public class PaymentMethod {
private String type;
private String number;
private Date expiration;
private PaymentMethod() {}
public PaymentMethod(String t, String n, Date e) {
type = t;
number = n;
expiration = e;
}
//. . .standard plain get/set methods
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 34 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 35 of 51
package sl500;
import javax.jdo.*;
import java.io.*;
import java.util.*;
public class PaymentService {
private PersistenceManager pm;
public PaymentService() throws IOException {
InputStream propertyStream =
new FileInputStream("jdo.properties");
Properties jdoProps = new Properties();
jdoProps.load(propertyStream);
PersistenceManagerFactory pmf =
JDOHelper.getPersistenceManagerFactory(jdoProps);
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 36 of 51
pm = pmf.getPersistenceManager();
}
public void makePayment(double amount,
String type, String number, Date expiration){
Transaction tx = pm.currentTransaction();
tx.begin();
PaymentMethod method = new PaymentMethod
(type, number, expiration);
Payment thePayment = new Payment(amount, new Date(), method);
pm.makePersistent(thePayment);
tx.commit();
}
public void queryPayments() {
Extent e = pm.getExtent(Payment.class, true);
Iterator i = e.iterator();
while (i.hasNext())
{
Payment p = (Payment) i.next();
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 37 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 38 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 39 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 40 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 41 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 42 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 43 of 51
Client
send request
<<servlet>>
EndpointProcessor invoke
1..*
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
WebServiceBroker
BusinessService
accesses
1..*
Module 7, slide 44 of 51
<<servlet>>
: EndpointProcessor
: WebServiceBroker
: BusinessService
1: send request
1.1: extract Request
1.1.1: invoke
1.1.1.1: invoke
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 45 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 46 of 51
<<session bean>>
ReservationWebServiceBean
<<session bean>>
CustomerReservationSessionFacade
accesses
send request
+cancelReservation( ... )
+findReservation( ... )
+makeReservation( ... )
1..*
invokes
<<servlet>>
<<JAX-RPC>>
EndpointProcessor
<<session bean>>
CustomerMgmtApplicationService
+addCustomer( ... )
+deleteCustomer( ... )
+editCustomer( ... )
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
+addCustomer( ... )
+cancelReservation( ... )
+deleteCustomer( ... )
+editCustomer( ... )
+findReservation( ... )
+getReservationData()
+makeReservation( ... )
+sendReservationConfirmation( ... )
...
<<session bean>>
ReservationMgmtApplicationService
+cancelReservation( ... )
+findReservation( ... )
+getReservationData()
+makeReservation( ... )
+sendReservationConfirmation( ... )
Module 7, slide 47 of 51
package sl500;
import java.rmi.*;
public interface ReservationWebService extends Remote {
public boolean makeReservation(. . .) throws RemoteException;
public boolean cancelReservation(. . .) throws RemoteException;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 48 of 51
package sl500;
import javax.ejb.*;
public class ReservationWebServiceBean implements SessionBean {
public void ejbCreate() {
//. . . Obtain session facade bean
}
public boolean makeReservation(. . .) {
//. . .Call makeReservation on session facade bean
}
public boolean cancelReservation(. . .) {
//. . .Call cancelReservation on session facade bean
}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 49 of 51
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 50 of 51
Summary
Service Activator pattern
Provides asynchronous messaging
for business components,
including EJB components
Data Access Object pattern
Encapsulates data store details
Domain Store pattern Creates a
robust persistence mechanism that
is transparent to the business
objects without using entity beans
Web Service Broker pattern Provides a flexible way
to make business services available as web services
Object-Oriented Design Principles
Architectural Patterns
Presentation Tier
Anti-Patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 7, slide 51 of 51
Module 8
Module 8
Using 8
Presentation-to-Business Tier
Module
Presentation-toPatterns
Business Tier
Presentation-To
Patterns
Business Tier
Patterns
Java EE Patterns
Objectives
Describe basic characteristics of the business tier Java
EE patterns that facilitate communication with the
presentation tier
Apply the Service Locator pattern
Apply the Session Faade pattern
Apply the Business Delegate pattern
Apply the Transfer Object pattern
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 2 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 3 of 44
Primary Function
Provides one interface for service
lookups.
Hides business component detail with a
simpler interface.
Decouples presentation clients and
business services.
Reduces remote calls by encapsulating
return value data into one object.
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 4 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 5 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 6 of 44
<<Singleton>>
ServiceLocator
uses
1..* 1
1..*
uses
Component
uses
1..*
creates
ComponentFactory
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
creates
Context
Module 8, slide 7 of 44
<<Singleton>>
: ServiceLocator
: Component
1: Get Instance
1.1: Create()
: Context
2: Get Component
2.1: Lookup
2.1.1: Create()
return
: ComponentFactory
ComponentFactory
return
Component
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 8 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 9 of 44
<<Servlet>>
Client
CustomerReservationSFHome
create
<<session bean>>
CustomerReservationSessionFacadeBean
+cancelReservation( ... ) : boolean
+findReservation( ... )
+getReservationData()
+makeReservation( ... ) : boolean
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 10 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 11 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 12 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 13 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 14 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 15 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 16 of 44
Client
<<session bean>>
SessionFacade
+doService1( ... )
+doService2( ... )
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
BusinessComponent
1..*
accesses
+doService3( ... )
+getData( ... )
+setData( ... )
...
Module 8, slide 17 of 44
<<session bean>>
: SessionFacade
appService1 : BusinessComponent
appService2 : BusinessComponent
1: doService1( ... )
1.1: doPart1( ... )
2: doService2( ... )
2.1: doSomething( ... )
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 18 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 19 of 44
<<session bean>>
CustomerMgmtApplicationService
<<session bean>>
CustomerReservationSessionFacade
+addCustomer( ... )
+cancelReservation( ... )
+deleteCustomer( ... )
+editCustomer( ... )
+findReservation( ... )
+getReservationData()
+makeReservation( ... )
+sendReservationConfirmation( ... )
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
+addCustomer( ... )
+deleteCustomer( ... )
+editCustomer( ... )
<<session bean>>
ReservationMgmtApplicationService
+cancelReservation( ... )
+findReservation( ... )
+getReservationData()
+makeReservation( ... )
+sendReservationConfirmation( ... )
Module 8, slide 20 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 21 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 22 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 23 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 24 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 25 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 26 of 44
uses
uses
BusinessService
EJB component or
JMS API component
ServiceLocator
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 27 of 44
1: Create()
: ServiceLocator
: BusinessService
: BusinessDelegate
1.1: Get Service
1.1.1: Lookup
return
Service
2: invoke
2.1: Invoke
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 28 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 29 of 44
<<Servlet>>
Client
<<Singleton>>
ServiceLocator
+getHomeObject( jndiName, homeClass ) : EJBHome
+getInstance() : ServiceLocator
-ServiceLocator()
ReservationBusinessDelegate
+cancelReservation( ... )
+findReservation( ... )
+makeReservation( ... )
...
invokes
<<session bean>>
CustomerReservationSessionFacade
+addCustomer( ... )
+cancelReservation( ... )
+deleteCustomer( ... )
+editCustomer( ... )
+findReservation( ... )
+getReservationData()
+makeReservation( ... )
+sendReservationConfirmation( ... )
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 30 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 31 of 44
catch (RemoteException e) {
throw new ReservationException();
}
}
public boolean makeReservation(String resData)
throws ReservationException {
try {
return resSF.makeReservation(resData);
}
catch (Exception e) {
throw new ReservationException();
}
}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 32 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 33 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 34 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 35 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 36 of 44
<<Serializable>>
TransferObject
-attribute1
-attribute2
-attribute3
Client
+getAttribute1()
+getAttribute2()
+getAttribute3()
creates
Component
+getTransferObject() : TransferObject
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 37 of 44
: Component
1: getTransferObject
1.1: Create()
<<Serializable>>
ServerCopy : TransferObject
return TransferObject
<<Serializable>>
ClientCopy : TransferObject
2: getAttribute1
3: getAttribute2
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 38 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 39 of 44
: BusinessObject
1: getTransferObject
1.1: Create()
<<Serializable>>
ServerCopy : TransferObject
return TransferObject
<<Serializable>>
ClientCopy : TransferObject
2: getAttribute1
3: getAttribute2
4. setAttribute1
5. setAttribute2
6. setTransferObject
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 40 of 44
<<entity bean>>
CustomerBean
<<Singleton>>
ServiceLocator
<<entity bean>>
ReservationBean
...
...
ReservationBusinessDelegate
...
<<session bean>>
ReservationMgmtApplicationService
<<session bean>>
CustomerReservationSessionFacade
...
create
+cancelReservation( ... )
+findReservation( ... ) : ReservationTO
+getReservationData()
+makeReservation( ... )
+sendReservationConfirmation( ... )
ReservationDAO
<<session bean>>
PaymentService
+findReservationByCustomer():ReservationTO
+findAvailableReservations()
+findReservationByDate()
...
...
create
ReservationTO
-endDate : Date
-startDate : Date
...
+getCustomer()
+getEndDate() : Date
+getRoom()
+getStartDate() : Date
+ReservationTO( . . ., start : Date, end : Dtae )
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 41 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 42 of 44
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 43 of 44
Summary
Presentation to business tier patterns:
Object-Oriented Design Principles
Architectural Patterns
Presentation Tier
Anti-Patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 8, slide 44 of 44
Module 9
Module 9
Using Intra-Business Tier Patterns
Module 9
Using Intra-Business
Using
Intra-Business
Tier Patterns
Tier Patterns
Java EE Patterns
Objectives
Describe the basic characteristics of the Intra-Business
Tier patterns
Apply the Application Service pattern
Apply the Business Object pattern
Apply the Transfer Object Assembler pattern
Apply the Composite Entity pattern
Apply the Value List Handler pattern
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 2 of 61
Primary Function
Application Service
Business Object
Transfer Object
Assembler
Composite Entity
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 3 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 4 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 5 of 61
ServiceFacade
ApplicationService
uses
DataAccessObject
uses
Service
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 6 of 61
: FirstAppService
: SecondAppService
first : BusinessObject
second : BusinessObject
: DataAccessObject
1: invoke
1.1: process
1.2: invoke
2: invoke
2.1: invoke
2.2: process
3: invoke
3.1: invoke
3.2: invoke
3.3: process
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 7 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 8 of 61
...
<<JMS Sender>>
ReservationConfirmationClient
...
<<session bean>>
ReservationMgmtApplicationService
<<session bean>>
CustomerReservationSessionFacadeBean
+addCustomer( ... )
+cancelReservation( ... )
+deleteCustomer( ... )
+editCustomer( ... )
+findReservation( ... )
+getReservationData()
+makeReservation( ... )
+sendReservationConfirmation( ... )
...
+cancelReservation( ... )
+findReservation( ... )
+getReservationData()
+makeReservation( ... )
+sendReservationConfirmation( ... )
<<entity bean>>
RoomBean
+getRoomTO() : RoomTO
...
<<entity bean>>
ReservationBean
...
<<session bean>>
CustomerMgmtApplicationService
+addCustomer( ... )
+deleteCustomer( ... )
+editCustomer( ... )
<<entity bean>>
CustomerBean
...
ReservationDAO
...
CustomerDAO
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 9 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 10 of 61
}
}
public boolean makeReservation(. . .)
throws Exception {
Reservation res = resHome.create(. . .);
double cost = res.getCost();
return payService.verifyPayment(cost);
}
. . .
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 11 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 12 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 13 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 14 of 61
accesses
ParentBO
contains
0..*
persisted in
persisted in
DependantBO
0..*
contains
DataStore
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 15 of 61
: ParentBO
: DependantBO
: DataStore
1: invoke
1.1: persist
2: invoke
2.1: invoke
2.1.1: persist
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 16 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 17 of 61
<<session bean>>
ReservationMgmtApplicationService
<<entity bean>>
RoomBean
+cancelReservation( ... )
+findReservation( ... )
+getReservationData()
+makeReservation( ... )
+sendReservationConfirmation( ... )
+getRoomTO() : RoomTO
...
<<entity bean>>
ReservationBean
...
<<session bean>>
CustomerMgmtApplicationService
+addCustomer( ... )
+deleteCustomer( ... )
+editCustomer( ... )
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<entity bean>>
CustomerBean
...
Module 9, slide 18 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 19 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 20 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 21 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 22 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 23 of 61
Client
<<session bean>>
TransferObjectAssembler
+getCompositeTransferObject()
BusinessObject
DataAccessObject
builds
0..*
TransferObject
ServiceFacade
Service
contains
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 24 of 61
<<session bean>>
: TransferObjectAssembler
<<entity bean>>
: BusinessEntity
<<session bean>>
: BusinessSession
: DataAccessObject
1: GetComposoteTransferObject
1.1: Create()
: TransferObject
return
CompositeTransferObject
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 25 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 26 of 61
<<entity bean>>
CustomerBean
uses1
+create( ... )
+getReservationTO()
+remove()
+getCustomerTO() : CustomerTO
...
...
<<entity bean>>
RoomBean
+getRoomTO() : RoomTO
<<session bean>>
ReservationReportTOAssemblerBean
...
HotelDAO
+getHotelData( . . . ) : HotelTO
...
+findReservation( ... )
+getReservationAndHotelData( reservationID )
+getReservationData()
+junk()
+makeReservation( ... )
creates
creates
creates
creates
HotelTO
creates
-amenities
-location
...
ReservationHotelTO
-hotel
+getHotel() : HotelTO
+getReservation()
+ReservationHotelTO( : HotelTO,
+getAmenities()
+getLocation()
CustomerTO
RoomTO
...
-customer
-room
-reservation
ReservationTO
-endDate : Date
-startDate : Date
...
+getCustomer()
+getEndDate() : Date
+getRoom()
+getStartDate() : Date
+ReservationTO( , , start : Date, end : Date )
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 27 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 28 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 29 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 30 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 31 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 32 of 61
Container
Data Access Object
JDBC
Data
TM
CMP
Container
Deployment
Descriptor
EJB QL
Data
TM
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 33 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 34 of 61
Client
contains
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 35 of 61
: DataStore
1: busMethod
1.1: loadData
1.2: processRequest
2: busMethod
2.1: getData
2.2: getData
2.2.1: processRequest
3: storeData
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 36 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 37 of 61
...
Address
...
uses
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 38 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 39 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 40 of 61
}
public void ejbPostCreate(String resID,
Date start, Date end, CustomerLocal cust,
RoomLocal room) throws CreateException {
setCustomer(cust);
setRoom(room);
}
public void setEntityContext
(EntityContext ctx){
context = ctx;
}
public void unsetEntityContext() {
context = null;
}
public void ejbRemove() { }
public void ejbActivate() { }
public void ejbPassivate() { }
public void ejbStore() { }
public void ejbLoad() { }
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 41 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 42 of 61
. . .
<ejb-relation>
<ejb-relationship-role>
<ejb-relationship-role-name>
ReservationBean
</ejb-relationshiprole-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>ReservationBean</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>customer</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>
CustomerBean
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 43 of 61
</ejb-relationship-rolename>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>CustomerBean</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
. . .
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 44 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 45 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 46 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 47 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 48 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 49 of 61
Client
ValueListHandler
<<interface>>
List
iterates
+executeSearch( . . . )
accesses
provides data
DataAccessObject
+executeSearch( . . . )
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 50 of 61
: ValueListHandler
: DataAccessObject
1: executeSearch( . . . )
1.1: executeSearch( . . . )
1.1.1: create()
: ValueList
1.1.2: create()
: TransferObject
return
valueList
2: getNextElements( 10 )
2.1: Create Sub-List from ValueList
return
subList
3: getPreviousElemenets( 10 )
3.1: Create Sub-List from ValueList
return
sublist
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 51 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 52 of 61
ReservationTO
-endIndex : int
-startIndex : int
iterates
0..*
-endDate : Date
-startDate : Date
...
+getEndDate() : Date
+getStartDate() : Date
...
create
ReservationDAO
+findAvailableReservations()
+findReservationsByCustomer()
+findReservationsByDate()
+ReservationDAO()
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 53 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 54 of 61
int index;
for (index=0; index<howMany; index++) {
subset[index] = (ReservationTO)
allResults.get(startIndex+index);
}
startIndex = endIndex;
endIndex = startIndex+index;
return subset;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 55 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 56 of 61
startIndex = endIndex = 0;
}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 57 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 58 of 61
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 59 of 61
Summary
Intra-Business Tier patterns help expedite
client access to business objects. In
summary, these patterns contribute as
follows:
Presentation Tier
Anti-Patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 60 of 61
Summary
Composite Entity Organizes related persistence
objects into a composite structure.
Value List Handler Manages large result sets on
behalf of a client.
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 9, slide 61 of 61
Module 10
Module 10
Using
Module
10Presentation Tier Patterns
Using Presentation
Presentation
Using
Tier Patterns
Patterns
Tier
Java EE Patterns
Objectives
Describe basic characteristics of the Presentation Tier
Java EE Patterns
Describe the Model 2 Architecture and the Apache
Struts Framework
Apply the Intercepting Filter pattern
Apply the Front Controller pattern
Apply the Application Controller pattern
Apply the Context Object pattern
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Primary Function
Intercepting
Filter
Provides a simple mechanism for pre-processing and postprocessing of HTTP requests and responses.
Front Controller
Application
Controller
Context Object
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Model
Get Data
Set Data Changes
Request Processing
View
Select View
Controller
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Model 2 Architecture
Model 2 architecture describes how to apply the MVC
architecture to a Java technology web application
The Presentation Tier patterns fit into this architecture
- Encapsulates application state
- Responds to state queries
- Exposes application functionality
Get Data
Model
Set Data Changes
Request Processing
View
Controller
<<JSP page>>
ViewComponent
<<servlet>>
FrontController
Select View
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Post-Processing Tasks
User authentication
Session validate
Response encryption
Response compression
Request decryption
Language translation
Request decompression
Debugging
Request auditing
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
FilterManager
<<interface>>
FilterChain
+doFilter(
: ServletRequest,
: ServletResponse )
FilterChainImpl
+doFilter( . . . )
-servlet
<<Servlet>>
Target
0..* -filters
<<interface>>
Filter
+destroy()
+doFilter( request : ServletRequest, response : ServletResponse, chain : FilterChain )
+init( : FilterConfig )
FilterA
FilterB
+destroy()
+doFilter( . . . )
+init( . . . )
+destroy()
+doFilter( . . . )
+init( . . . )
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
//pre-processing
chain.doFilter(request, response);
//post-processing
: FilterManager
: FilterChainImpl
: FilterA
: FilterB
<<Servlet>>
: Target
1: Request
1.1: doFilter
1.1.1: doFilter
1.1.1.1: doFilter
1.1.1.1.1: doFilter
1.1.1.1.1.1 doFilter
1.1.1.1.1.1.1 service
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package sl500;
import java.io.*;
import javax.servlet.*;
public class TimerFilter implements Filter {
private FilterConfig filterConfig = null;
public void init(FilterConfig filterConfig)
throws ServletException {
this.filterConfig = filterConfig;
}
public void destroy() { }
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<filter>
<filter-name>TimerFilter</filter-name>
<filter-class>sl500.TimerFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>TimerFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Client
<<Servlet>>
ApplicationController
FrontController delegates
invokes
Action
forwards
<<JSP Page>>
View
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<Servlet>>
: FrontController
: ApplicationController
<<JSP Page>>
: View
: Action
1: Send Request
1.1: Delegate
2: Send Request
2.1: Delegate
2.1.1: Forward Request
3: Send Request
3.2: Delegate
3.2.1: Process Request
3.2.2: Forward Request
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
request
<<Filter>>
DebuggingFilter
+doFilter()
RequestContextObjectFactory
forward
<<Filter>>
TimingFilter
<<interface>>
Command
AuthenticationBean
+execute()
+doFilter()
forward
<<Servlet>>
FrontController
+doPost()
forward
<<JSP Page>>
ErrorPage
MakeReservation
SearchReservations
CancelReservation
+execute()
+execute()
+execute()
ApplicationController
forward
<<JSP Page>>
ReservationConfirmation
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
forward
<<JSP Page>>
ReservationSearchResults
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
delegates
ApplicationController
invokes
Action
uses
invokes
creates
Mapper
creates
<<JSP Page>>
View
searches
Map
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
: ApplicationController
: Mapper
: Map
<<JSP Page>>
: View
1: delegate
1.1: getAction
1.1.1: resolve
1.1.2:create()
: Action
1.2: invoke
1.3: getView
1.4: forward
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<Servlet>>
FrontController
ApplicationController
MakeReservation
SearchReservations
CancelReservation
+execute()
+execute()
+execute()
+doPost()
uses
Mapper
ReservationBusinessDelegate
forward
forward
forward
...
searches
Map
<<JSP Page>>
ErrorPage
<<JSP Page>>
ReservationConfirmation
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<JSP Page>>
ReservationSearchResults
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Client
uses
ContextFactory
creates
ContextObject
uses
ProtocolSpecificObject
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
: Client
: ContextFactory
1: create()
: ProtocolSpecificObject
2: getContextObject( :ProtocolSpecificObject )
2.1: create( :ProtocolSpecificObject )
: ContextObject
2.2: getData
2.3: setData
3: getData1
4: getData2
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<interface>>
Command
+execute()
<<Servlet>>
FrontController
ApplicationController
MakeReservation
SearchReservations
CancelReservation
+execute()
+execute()
+execute()
+doPost()
uses
ReservationBusinessDelegate
...
ContextFactory
uses
HttpServletRequest
creates
MakeReservationRequestData
creates
SearchReservationRequestData
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
import javax.servlet.*;
public class MakeReservationRequestData extends Request{
private String roomType;
private int numNights;
//...other fields
public void initialize(ServletRequest request) {
setRoomType(request.getParameter("roomType"));
int numNights = Integer.parseInt
(request.getParameter("numNights"));
setNumNights(numNights);
}
public boolean validate() {
//...Validation rules checked here
return true;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Summary
Intercepting Filter Provides a
simple mechanism for preprocessing and post-processing
HTTP requests and responses
Front Controller Provides a
single entry point to the
presentation tier; may handle
security and validation
Application Controller
Separates the action invocation
and view dispatching from the front controller
Context Object Passes data from context-specific
objects to other scopes
Object-Oriented Design Principles
Architectural Patterns
Presentation Tier
Anti-Patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 11
Module 11
More11
Presentation Tier Patterns
Module
More Presentation
Presentation
More
Tier Patterns
Patterns
Tier
Java EE Patterns
Objectives
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Primary Function
View Helper
Composite
View
Dispatcher
View
Service To
Worker
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Client
requests
ViewHelper
0..*
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<JSP Page>>
: View
: ViewHelper
: BusinessService
1: Send Request
: TransferObjectBean
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<JSP Page>>
ReservationSearchResults
uses
uses
uses
ReservationTO
...
...
LoopTag
CustomerTO
-customer
...
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
1
2
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<JSP Page>>
View
includes
0..*
<<JSP Page>>
ViewFragment
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<JSP Page>>
CompositeView
: ViewManager
<<JSP Page>>
header : ViewFragment
<<JSP Page>>
footer : ViewFragment
1: include
2: include
3: include
4: include
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<JSP Page>>
Header
<<JSP Page>>
ReservationSearchResults
<<JSP Page>>
NavigationBar
<<JSP Page>>
Advertisement1
<<JSP Page>>
ReservationData
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<JSP Page>>
Advertisement2
<<JSP Page>>
ReservationListHeader
<TABLE BORDER='0'>
<TR>
<TD>
<%@ include file="../incl/Header.jsp" %>
</TD>
</TR>
<TR>
<TD>
<jsp:include page="../incl/NavigationBar.jsp"/>
</TD>
<TD>
<jsp:include page="../incl/ReservationData.jsp"/>
</TD>
</TR>
</TABLE>
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Service
Client
<<servlet>>
FrontController
<<transfer object>>
PresentationModel
adapts
1..*
View Helper
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<servlet>>
: FrontController
:TransferObject
1: Request
1.1: Authenticate
1.2: Dispatch
1.2.1: Forward
1.2.1.1: Request Business Process
return transferObject
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<servlet>>
FrontController
request
AuthenticationBean
<<interface>>
Command
+doPost()
Map
MakeReservation
forward
recieves/
stores
forward
View
<<JSP page>>
ErrorPage
SearchReservations
searches
recieves/
stores
Model
forward
<<JSP page>>
ReservationConfirmation
<<JSP page>>
ReservationSearchResults
queries
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
ReservationTO
queries
-endDate
-startDate
...
ReservationBusinessDelegate
+findReservation( ... )
+makeReservation( ... )
...
+getEndDate()
+getStartDate()
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<myTag:executeLogic>
<jsp:useBean id='result' scope='request' class='java.lang.String'/>
<%if (result.equals("failure") {%>
<jsp:forward page="errorPage.jsp">
<%}%>
<jsp:useBean id='resData'
scope='request' class='ReservationTO'/>
Your reservation for
<jsp:getProperty name='resData' property='startDate'/>,
has been confirmed.
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Service
Client
<<servlet>>
FrontController
creates
<<transfer object>>
PresentationModel
adapts
1..*
View Helper
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<servlet>>
: FrontController
security : Service
: ApplicationController
:TransferObject
1: Request
1.1: Authenticate
1.2: Dispatch
1.2.1: Request Business Process
1.2.2: Forward
1.2.1.2: Select View Content
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
request
<<servlet>>
FrontController
AuthenticationBean
+doPost()
<<interface>>
Command
+execute( : HttpServletRequest, : HttpServletResponse ) : String
ApplicationController
Mapper
MakeReservation
Map
searches
forward
forward
receives/
stores
forward
View
<<JSP page>>
ErrorPage
SearchReservations
receives/
stores
Model
<<JSP page>>
ReservationConfirmation
<<JSP page>>
ReservationSearchResults
queries
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
ReservationTO
queries1
-endDate
-startDate
...
ReservationBusinessDelegate
+findReservation( ... )
+makeReservation( ... )
...
+getEndDate()
+getStartDate()
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<jsp:useBean id='resData'
scope='request' class='ReservationTO'/>
Your reservation for
<jsp:getProperty name='resData' property='startDate'/>,
has been confirmed.
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<servlet>>
ActionServlet
{org.apache.struts.action}
creates
forward
forward
+execute( . . . )
forward
SearchReservations
+execute( . . . )
+execute( . . . )
recieves
View
<<JSP page>>
ErrorPage
MakeReservation
recieves
Model
<<JSP page>>
ReservationConfirmation
<<JSP page>>
ReservationSearchResults
ReservationTO
queries
-endDate
-startDate
...
ReservationBusinessDelegate
+findReservation( ... )
+makeReservation( ... )
...
+getEndDate()
+getStartDate()
queries
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
...
Summary
View Helper Provides an object to carry out
presentation tier logic to remove it from view
components, like JSP pages.
Composite View Provides a simple way to create
views from smaller view components.
Dispatcher View Pattern Combines the Front
Controller and View Helper patterns. The view
components request business processes and thus might
have to assume some controller responsibility.
Service to Worker Pattern Combines the Front
Controller and View Helper patterns. The controller
requests business processes.
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Module 11
Module 12
Exploring AntiPatterns
Module 12
Exploring
Exploring
AntiPatterns
AntiPatterns
Java EE Patterns
Objectives
Define AntiPatterns
Describe Integration Tier AntiPatterns
Describe Business Tier AntiPatterns
Describe Presentation Tier AntiPatterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Introducing AntiPatterns
AntiPatterns identify and document well-known code
development practices that have a negative impact on
a software system
Studying AntiPatterns helps you avoid them and learn
refactored solutions
In this module, AntiPatterns are grouped into three sets
of patterns:
Integration Tier AntiPatterns
Business Tier AntiPatterns
Presentation Tier AntiPatterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Mirage AntiPattern
AntiPattern problem:
Many developers use BMP due to servers based on EJB
1.x architecture (EJB servers) CMP limitations
CMP offers many benefits over BMP:
CMP can provide data caching, lazy loading, and
other server optimizations
CMP code does not contain vendor specific SQL
CMP is easier to develop and maintain
CMP 2.0 provides container managed
relationships (CMR)
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Mirage AntiPattern
Symptoms and consequences:
Using BMP unnecessarily might lead to:
Needlessly high development and
maintenance effort
Less efficient entity bean performance
Refactored solution:
Consider using CMP instead of BMP
There are times when BMP is the only option
Check into the reputation of your servers CMP
implementation, or do your own performance tests
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Summary
AntiPatterns help us focus on the
common mistakes made in
development and provide
refactored solutions to avoid or
remedy these problems
Studying patterns and
AntiPatterns provide a natural
benefit of seeing development
issues from both a positive and a
negative perspective
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Architectural Patterns
Anti-Patterns
Module 13
Module
13
Applying
Module 13 Java EE BluePrints Design
Guidelines
Applying Java EE
Applying
Java
EE
BluePrints Design
BluePrints
Design
Guidelines
Guidelines
Java EE Patterns
Objectives
Describe the Java EE BluePrints design guidelines
Describe the Java Pet Store demo software
Describe the Java EE patterns used in the Java Pet Store
demo software
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Object-Oriented Guidelines
Many of the Java EE BluePrints design guidelines are
specializations of general object-oriented guidelines.
Modules should:
Be separately compilable so they can be developed
independently
Have few interfaces to communicate with as few other
modules as possible
Use loose coupling to other modules
Have explicit interfaces so that whenever two modules
communicate, it is obvious from public declarations
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Browser client
Java technology-based Application client
Java technology-based MIDlet client
Non-Java technology-based client
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<Filter>>
EncodingFilter
invoke
<<Filter>>
SignOnFilter
+doFilter( ... )
+doFilter( ... )
...
...
forward
<<JSP page>>
SignOnPage
<<Servlet>>
MainServlet
invoke
+doGet( ... )
+doPost( ... )
+doProcess( ... )
...
RequestProcessor
+processRequest( : HttpServletRequest )
ScreenFlowManager
...
+forwardToNextScreen( . . . )
+init()
WebController
create
invoke
forward
<<Servlet>>
TemplateServlet
<<interface>>
HTMLAction
<<session bean>>
EJBControllerLocalEJB
+processEvent( : Event )
...
+doGet( ... )
+doPost( ... )
+process( ... )
forward
create
Event
<<interface>>
StateMachine
+processEvent( : Event )
...
create
invoke
+getEJBActionClassName() : String
+getEventName()
+setEJBActionClassName( : String )
<<interface>>
EJBAction
+perform( : Event ) : EventResponse
<<JSP page>>
TemplatePage
uses
InsertTag
include
<<JSP page>>
FragmentPages
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<filter>
<filter-name>SignOnFilter</filter-name>
...
<filter-class>
com.sun.j2ee.blueprints.signon.web.SignOnFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>SignOnFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package com.sun.j2ee.blueprints.signon.web;
import javax.servlet.*;
...
public class SignOnFilter implements Filter {
private HashMap protectedResources;
private FilterConfig config = null;
...
public void init(FilterConfig config)
throws ServletException {
this.config = config;
URL protectedResourcesURL=
config.getServletContext().getResource
("/WEB-INF/signon-config.xml");
SignOnDAO dao =
new SignOnDAO(protectedResourcesURL);
...
protectedResources =
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
dao.getProtectedResources();
}
public void doFilter( ServletRequest request,
ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest hreq =
(HttpServletRequest) request;
String targetURL = hreq.getRequestURI();
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
...
// check if the user is signed on
boolean signedOn = false;
if (hreq.getSession().getAttribute
(SIGNED_ON_USER)!= null {
signedOn = ((Boolean) hreq.getSession().
getAttribute(SIGNED_ON_USER)).booleanValue();
} else {
hreq.getSession().setAttribute
(SIGNED_ON_USER, new Boolean(false));
}
// jump to the resource if signed on
if (signedOn) {
chain.doFilter(request, response);
return;
}
// find out if the patterns match the target URL
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Iterator it =
protectedResources.keySet().iterator();
while (it.hasNext()) {
String protectedName = (String) it.next();
ProtectedResource resource =
(ProtectedResource)
protectedResources.get(protectedName);
String urlPattern = resource.getURLPattern();
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<servlet>
<servlet-name>MainServlet</servlet-name>
<description>The Front Controller for the Pet Store
</description>
<servlet-class>
com.sun.j2ee.blueprints.waf.controller.web.MainServlet
</servlet-class>
...
</servlet>
...
<servlet-mapping>
<servlet-name>MainServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package com.sun.j2ee.blueprints.waf.controller.web;
...
public class MainServlet extends HttpServlet {
...
private HashMap urlMappings;
private HashMap eventMappings;
public void init(ServletConfig config)
throws ServletException {
...
urlMappings =
URLMappingsXmlDAO.loadRequestMappings
(requestMappingsURL);
context.setAttribute
(WebKeys.URL_MAPPINGS, urlMappings);
eventMappings = URLMappingsXmlDAO.
loadEventMappings(requestMappingsURL);
context.setAttribute
(WebKeys.EVENT_MAPPINGS, eventMappings);
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
...
}
public void doGet(...) ... {
doProcess(request, response);
}
public void doPost(...) ... {
doProcess(request, response);
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
request.getSession().
getAttribute(WebKeys.COMPONENT_MANAGER);
WebController wcc = sl.getWebController
(request.getSession());
eventResponse =
wcc.handleEvent(ev, request.getSession());
}
action.doEnd(request, eventResponse);
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package com.sun.j2ee.blueprints.waf.controller.web;
...
public class DefaultWebController implements WebController {
...
public synchronized EventResponse handleEvent
(Event ev, HttpSession session)
throws EventException {
DefaultComponentManager cm = (DefaultComponentManager)
session.getAttribute(WebKeys.COMPONENT_MANAGER);
EJBControllerLocal controllerEJB
=cm.getEJBController(session);
return controllerEJB.processEvent(ev);
}
...
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package com.sun.j2ee.blueprints.waf.controller.ejb;
...
public class EJBControllerLocalEJB
implements SessionBean {
protected StateMachine sm;
protected SessionContext sc;
public void ejbCreate() {
sm = new StateMachine(this, sc);
}
public EventResponse processEvent(Event ev)
throws EventException {
return (sm.processEvent(ev));
}
public void setSessionContext
(SessionContext sc) {
this.sc = sc;
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
}
public
sm =
}
public
public
void ejbRemove() {
null;
void ejbActivate() {}
void ejbPassivate() {}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package com.sun.j2ee.blueprints.waf.controller.ejb;
...
public class StateMachine
implements java.io.Serializable {
...
public EventResponse processEvent(Event ev)
throws EventException {
String actionName =
ev.getEJBActionClassName();
EventResponse response = null;
...
action = (EJBAction)
Class.forName(actionName).newInstance();
...
action.init(this);
action.doStart();
response = action.perform(ev);
action.doEnd();
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
return response;
}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package com.sun.j2ee.blueprints.waf.controller.web.flow;
...
public class ScreenFlowManager
implements java.io.Serializable {
...
public void forwardToNextScreen
(HttpServletRequest request,
HttpServletResponse response)
throws java.io.IOException,
FlowHandlerException,
javax.servlet.ServletException {
String selectedURL = request.getRequestURI();
...
URLMapping urlMapping =
getURLMapping(selectedURL);
if (!urlMapping.useFlowHandler()) {
currentScreen = urlMapping.getScreen();
} else {
FlowHandler handler = null;
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
The screendefinitions_
en_US.xml File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<screen-definitions>
<default-template>/template.jsp
</default-template>
<screen name="main">
<parameter key="title"
value="Welcome to the BluePrints Petstore"
direct="true"/>
<parameter key="banner" value="/banner.jsp" />
<parameter key="sidebar"
value="/sidebar.jsp" />
<parameter key="body" value="/main.jsp" />
<parameter key="mylist" value="/mylist.jsp" />
<parameter key="advicebanner"
value="/advice_banner.jsp" />
<parameter key="footer" value="/footer.jsp" />
</screen>
<screen name="cart">
<parameter key="title" value="Cart" direct="true"/>
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
The screendefinitions_
en_US.xml File
19
20
21
22
23
24
25
26
27
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package com.sun.j2ee.blueprints.waf.view.template;
...
public class TemplateServlet extends HttpServlet {
...
public void process (HttpServletRequest request,
HttpServletResponse response)
throws IOException,ServletException {
String screenName = null;
String selectedUrl = request.getRequestURI();
int lastPathSeparator =
selectedUrl.lastIndexOf("/") + 1;
int lastDot = selectedUrl.lastIndexOf(".");
if (lastPathSeparator != -1 && lastDot != -1
&& lastDot > lastPathSeparator) {
screenName = selectedUrl.substring
(lastPathSeparator, lastDot);
}
//code omitted to cache request parameters
//and request attributes
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
...
String templateName = localeScreens.
getTemplate(screenName);
if (templateName != null) {
...
context.getRequestDispatcher(templateName).
forward(request, response);
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
AdminRequestBD
AdminRequestDB() throws AdminDBException
getChartInfo(:String, Date, Date, String) throws AdminDBException
getOrdersByStatus( : String ) : OrdersTO throws AdminDBException
updateOrders( OrderApproval ) throws AdminDBException
<<singleton>>
ServiceLocator
<<session bean>>
AsynchSenderEJB
+getInstance() : ServiceLocator
+getLocalHome( : String ) : EJBLocalHome
+sendAMessage( : String )
...
...
<<session bean>>
OPCAdminFacadeEJB
getChartInfo(:String, Date, Date, String) throws OPCAdminFacadeException
getOrdersByStatus( : String ) : OrdersTO throws OPCAdminFacadeException
...
<<session bean>>
ProcessManagerEJB
<<entity bean>>
ManagerEJB
...
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
<<entity bean>>
PurchaseOrderEJB
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package com.sun.j2ee.blueprints.admin.web;
...
public class AdminRequestBD {
private String OPC_ADMIN_NAME =
"java:comp/env/ejb/remote/OPCAdminFacade";
private OPCAdminFacade opcAdminEJB = null;
public AdminRequestBD()
throws AdminBDException{
try {
OPCAdminFacadeHome home =
(OPCAdminFacadeHome)
ServiceLocator.getInstance().
getRemoteHome(OPC_ADMIN_NAME,
OPCAdminFacadeHome.class);
opcAdminEJB = home.create();
} catch (CreateException ce) {
ce.printStackTrace();
throw new AdminBDException(ce.getMessage());
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
...
}
public OrdersTO getOrdersByStatus(String status)
throws AdminBDException {
try {
return
opcAdminEJB.getOrdersByStatus(status);
} catch (RemoteException re) {
re.printStackTrace();
throw new AdminBDException(re.getMessage());}}}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package
com.sun.j2ee.blueprints.servicelocator.web;
...
public class ServiceLocator {
private InitialContext ic;
private Map cache; //holds references to EJBHomes
private static ServiceLocator me;
static {
me = new ServiceLocator();
...
}
private ServiceLocator()
throws ServiceLocatorException {
try {
ic = new InitialContext();
cache = Collections.synchronizedMap
(new HashMap());
} catch (NamingException ne) {
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
getQueueConnectionFactory(...) ...{...}
public Queue getQueue(...) ... {...}
public TopicConnectionFactory
getTopicConnectionFactory(...) ...{...}
public Topic getTopic(...) ... {...}
public DataSource getDataSource(...) ... {...}
public URL getUrl(...) ... {...}
public boolean getBoolean(...) ... {...}
public String getString(...) ... {...}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package com.sun.j2ee.blueprints.opc.admin.ejb;
...
public interface OrdersTO extends Serializable {
public Iterator iterator();
public int size();
public boolean contains(Object o);
public boolean containsAll(Collection c);
public boolean equals(Object o);
public int hashCode();
public boolean isEmpty();
public Object[] toArray();
public Object[] toArray(Object[] a);
static class MutableOrdersTO
extends ArrayList implements OrdersTO {
}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
package com.sun.j2ee.blueprints.opc.admin.ejb;
...
public class OPCAdminFacadeEJB
implements SessionBean {
private String PURCHASE_ORDER_EJB =
"java:comp/env/ejb/local/PurchaseOrder";
private String PROCMGR_ORDER_EJB =
"java:comp/env/ejb/local/ProcessManager";
private SessionContext sc;
private PurchaseOrderLocalHome poLocalHome;
private ProcessManagerLocal processManagerLocal;
public void ejbCreate() throws CreateException {
try {
ServiceLocator serviceLocator =
new ServiceLocator();
poLocalHome = (PurchaseOrderLocalHome)
serviceLocator.getLocalHome
(PURCHASE_ORDER_EJB);
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
ProcessManagerLocalHome
processManagerLocalHome =
(ProcessManagerLocalHome)
serviceLocator.getLocalHome
(PROCMGR_ORDER_EJB);
processManagerLocal =
processManagerLocalHome.create();
} catch(ServiceLocatorException se) {
throw new EJBException(se);
} catch (CreateException ce) {
throw new EJBException(ce);
}
}
public OrdersTO getOrdersByStatus(String status)
throws OPCAdminFacadeException {
OrdersTO.MutableOrdersTO retVal =
new OrdersTO.MutableOrdersTO();
PurchaseOrderLocal po;
ProcessManagerLocal mgr = processManagerLocal;
try {
PurchaseOrderLocalHome pohome = poLocalHome;
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Collection orders =
mgr.getOrdersByStatus(status);
Iterator it = orders.iterator();
while((it!= null) && (it.hasNext())) {
ManagerLocal mgrEjb =
(ManagerLocal) it.next();
po = pohome.
findByPrimaryKey(mgrEjb.getOrderId());
Date gotDate = new Date(po.getPoDate());
String podate = (gotDate.getMonth()+1) +
"/" + gotDate.getDate() + "/" +
(gotDate.getYear()+1900);
retVal.add(new OrderDetails(po.getPoId(),
po.getPoUserId(), podate,
po.getPoValue(), status));
}
} catch(FinderException fe) {
System.err.println
("finder Ex while getOrdByStat :"
+ fe.getMessage());
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Summary
The Java EE BluePrints design
guidelines provide best practices
for designing enterprise systems
using Java EE platform technology
The Java Pet Store demo software
is a sample Web application that
illustrates these best practices
By studying the Java Pet Store
demo software , you can see an
example of how the Java EE
patterns can be applied to create a large enterprise
application
Object-Oriented Design Principles
Architectural Patterns
Presentation Tier
Anti-Patterns
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix A
Appendix A
Quick
Appendix
A Reference for UML
Quick
Reference
There are no
overheads associated with this appendix.
For
UML
for UML
There are no overheads
associated with this appendix
associated with this appendix
Java EE Patterns
Appendix B
Appendix
Appendix B
B
J2EE
Appendix
B Technology Review
J2EE
J2EE Technology
Technology
Review
Review
Java EE Patterns
Objectives
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 2 of 91
Specification
The reference implementation server
J2EE BluePrints design guidelines
The Java Pet Store Demo application
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 3 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 4 of 91
JDBC API
Java Message Service API (JMS)
JavaMail API
Java Transaction API (JTA)
Java Authentication and Authorization Service (JAAS)
J2EE connector architecture
J2EE management model
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 5 of 91
HTTP
SSL
Web Container
EJB Container
<%
%>
J2SE
SAAJ
Application
Client Container
J2SE
Java
Mail
JAF
JAXRPC
SAAJ
Java
Mail
JAF
JDBC
JAXRPC
EJB
JAXR
JACC
JMX
JNDI
JMS
JTA
HTTP
SSL
Servlet
JDBC
Applet
JAXR
JACC
JMX
JNDI
JMS
JTA
JSP
J2SE
JAXRPC
SAAJ
JAXR
JMS
JNDI
JDBC
Application
Client
JMX
J2SE
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Database
Appendix B, slide 6 of 91
Caller Java VM
Server
Caller
bind
lookup
java.rmi.
Naming
RemoteObject
java.rmi.
Naming
RMI Registry
Stub
Skeleton
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 7 of 91
import java.rmi.*;
public interface Borrowable extends java.rmi.Remote {
public boolean checkOut(String patron) throws RemoteException,
PatronException;
public boolean checkIn() throws RemoteException;
public boolean catalog() throws RemoteException;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 8 of 91
import java.rmi.*;
import java.rmi.server.*;
public class Book extends UnicastRemoteObject
implements Borrowable {
String title;
String author;
String publisher;
String callNo;
public Book(String t, String a, String p,
String c) throws RemoteException {
title = t;
author = a;
publisher = p;
callNo = c;
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 9 of 91
}
public boolean checkOut(String patron) throws PatronException {
boolean result = false;
if (checkOut == true)
result = true;
return result;
}
public boolean checkIn() {
boolean result = false;
if (checkIn == true)
result = true;
return result;
}
public boolean catalog() {
boolean result = false;
if (catalogued == true)
result = true;
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 10 of 91
return result;
}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 11 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 12 of 91
import java.rmi.*;
import library.*;
public class BookUser {
Borrowable b;
public boolean createBook(String t, String a, String p, String c){
b = (Borrowable) Naming.lookup(//libServer/Book);
// Need to know the name of the server
// Need to know the logical name of the remote object
}
public boolean checkOut(String patron) {
b.checkOut(patron);
}
// Other methods as necessary
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 13 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 14 of 91
Java RMI
Complexity
Quite complex
Required
software
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 15 of 91
Java RMI
Additional
services
Network
protocol
Interface
definition
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 16 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 17 of 91
Application
Server
Web Service
Infrastructure
Application
Functions
Swing
Client
Other Client
Types
Heterogeneous
Client Base
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 18 of 91
SOAP
Message
Internet
SOAP
Message
Marshall/
Unmarshall
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Transmit
Appendix B, slide 19 of 91
Service
Endpoint
Web Container
EJB Container
JAX-RPC runtime
SOAP
RPCRouter
Servlet Binding
Classes
To Service
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Stateless To Service
Session
EJB
Binding
Classes
Appendix B, slide 20 of 91
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface InterfaceName extends Remote {
// business method
public ReturnType methodName(paramList)
throws RemoteException;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 21 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 22 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 23 of 91
JNDI API
Naming Manager
JNDI SPI
LDAP
DNS
NIS
NDS
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
RMI
CORBA
JNDI
Implementation
Possibilities
Appendix B, slide 24 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 25 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 26 of 91
Understanding Servlets
Web Tier
HTTP(s)
Query
HTML
Result
Client Browser
Servlet
Data
Source
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 27 of 91
Servlet Class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import
import
import
import
import
java.io.*;
java.util.*;
javax.servlet.*;
javax.servlet.http.*;
libraryApp.*;
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 28 of 91
Servlet Class
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 29 of 91
Servlet Class
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
response.setContentType("text/html");
response.setBufferSize(8192);
PrintWriter out = response.getWriter();
// then write the data of the response
out.println
("<html><head><title>Catalog Query Results</title></head>");
out.println("<body>");
Iterator iter = titles.getItems();
while (iter.hasNext()) {
String title = (Book)iter.next();
out.println(title);
}
out.println("</body>");
out.println("</html>");
out.close();
}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 30 of 91
Understanding Servlets
Subclass of HttpServlet
doGet Called when a client sends a GET request:
HttpServletRequest object; use the
getParameter method to get parameters for the
Web page
HttpServletResponse object:
Use the setContentType method to set mime
type
Use a PrintWriter object to send HTML back to
the client
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 31 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 32 of 91
Init event
jspInit()
Request
Response
jspService
Destroy event
jspDestroy
JSP Servlet
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 33 of 91
<HTML>
<HEAD>
<TITLE>KDL University Library System</TITLE>
</HEAD>
<BODY>
<FORM action="/Catalog.jsp" method="get">
Search Type:
<INPUT type=text name=type><BR>
Search Text:
<INPUT type=text name=value><BR>
<INPUT type="submit" value="Submit">
</FORM>
</BODY>
</HTML>
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 34 of 91
JSP Page
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 35 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 36 of 91
JavaBeans components
<jsp:useBean id="name" />
Custom tags
<%@ taglib uri="/tlds/library.tld" prefix="library" %>
<P>New books in our collection</P>
<library:showNewBooks month="January" >
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 37 of 91
JMS
Queue
JMS Listener
JMS Subscriber
JMS Publisher
JMS
Topic
JMS Subscriber
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 38 of 91
import javax.jms.*;
import javax.naming.*;
public class PurchaseRequestSender {
public static void main(String[] args) {
Context context = null;
QueueConnectionFactory qcFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueSender queueSender = null;
TextMessage message = null;
try {
context = new InitialContext();
} catch (NamingException ne) {
System.out.println("Could not create +
JNDI context: " + ne.toString());
System.exit(1);
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 39 of 91
try {
qcFactory = (QueueConnectionFactory)
context.lookup("java:comp/env/jms/
PurchasingQueueConnectionFactory");
queue = (queue) context.lookup
("java:comp/env/jms/PurchaseQueue");
} catch (NamingException e) {
System.out.println
("JNDI lookup failed: " +e.toString());
System.exit(1);
}
try {
queueConnection =
qcFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
message = queueSession.createTextMessage();
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 40 of 91
message.setText
("// Purchase request data goes here");
queueSender.send(message);
} catch (JMSException jmse) {
System.out.println("Exception occurred: " +
jmse.toString());
} finally {
if (queueConnection != null) {
try {
queueConnection.close();
} catch (JMSException e) {
System.out.println
("JMS error: " +e.getMessage());
e.printStackTrace();
}
}
}
}
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 41 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 42 of 91
import javax.jms.*;
import javax.naming.*;
public class PurchaseOrderReceiver {
public static void main(String[] args) {
Context context = null;
QueueConnectionFactory qcFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueReceiver queueReceiver = null;
TextMessage message = null;
try {
context = new InitialContext();
} catch (NamingException e) {
System.out.println("Could not create
InitiialContext: " + e.toString());
System.exit(1);
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 43 of 91
}
try {
qcFactory = (QueueConnectionFactory)
context.lookup("java:comp/env/jms
PurchasingQueueConnectionFactory");
queue = (Queue)context.lookup
("java:comp/env/jms/PurchaseQueue");
} catch (NamingException e) {
System.out.println
("JNDI lookup failed: " + e.toString());
System.exit(1);
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 44 of 91
}
try {
queueConnection =
qcFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(
false,Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession
.createReceiver(queue);
queueConnection.start();
while (true) {
Message m = queueReceiver.receive(1);
if (m != null) {
if (m instanceof TextMessage) {
message = (TextMessage) m;
System.out.println("Reading +
message: " + message.getText());
} else {
break;
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 45 of 91
}
}
}
} catch (JMSException e) {
System.out.println("Exception occurred: "
+ e.toString());
} finally {
queueConnection.close();
...
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 46 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 47 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 48 of 91
Client
4
6
Home
Interface Home
Object
Remote
Interface
Container
5
create
find
remove
9
Bean
EJB
Object
8
10
JNDI
JNDI
Environmental Properties
Services
Server B
Naming
Transaction
Persistence
Security
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 49 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 50 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 51 of 91
Is an XML document
Contains structural information about the
EJB component
Is used for deployment by the container
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 52 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 53 of 91
Session Bean
Entity Bean
Primary
Purpose
Modeling
synchronous
business logic
Modeling
Modeling entities,
asynchronous
especially tables in
an RDBMS or objects business logic
in an ODBMS
Interface
SessionBean
EntityBean
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
MessageDrivenBean
Stateless. Not
accessible by the
client except through
the JMS API
Appendix B, slide 54 of 91
Session Beans
Stateful Session Bean
Conversational State
Stateful
Stateless
Instance owned by
client?
Generally yes
Generally no
create method
parameters
Use
Modeling conversational
Modeling one-shot
business logic, such as
business logic, such as
needed for a shopping cart querying a catalog or
validating a credit card
number. Sometimes more
efficient than a stateful
session bean
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 55 of 91
import javax.ebj.*;
import java.rmi.*;
public interface ShoppingCartHome extends javax.ejb.EJBHome {
public ShoppingCart create() throws
CreateException, RemoteException;
public ShoppingCart create(String custID) throws
CreateException, RemoteException;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 56 of 91
import java.rmi.*;
import javax.ejb.*;
public interface ShoppingCart extends javax.ejb.EJBObject {
public Collection getItemsInCart() throws RemoteException;
public boolean addToCart(String itemID, int qty)
throws RemoteException;
public boolean removeFromCart(String itemID, int qty)
throws RemoteException;
public checkOut(String custID)
throws RemoteException, CustomerException;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 57 of 91
import javax.ejb.*;
import java.util.*;
public class ShoppingCartBean implements javax.ejb.SessionBean {
private SessionContext context;
private String customerID;
private LinkedList items;
// Initialize the bean instance with no parameters
public void ejbCreate() {}
// Initialize the bean instance with one parameter
public void ejbCreate(String custID) {
customerID = custID;
}
// Save object which provides environmental access
public void setSessionContext(SessionContext sc) {
context = sc;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 58 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 59 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 60 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 61 of 91
Entity Beans
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 62 of 91
import javax.ejb.*;
import java.rmi.*;
import java.util.*;
public interface BookHome extends javax.ejb.EJBHome {
public Book create(String anAuthor, String aTitle,
String aCallNo, String aSubject)
throws CreateException, RemoteException;
public String findByPrimaryKey(String theCallNo)
throws FinderException, RemoteException;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 63 of 91
import javax.ejb.*;
import java.rmi.*;
import java.util.*;
public interface Book extends EJBObject {
public boolean checkOut(String cardID) throws RemoteException;
public String getAuthor() throws RemoteException;
public String getTitle() throws RemoteException;
public String getStatus() throws RemoteException;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 64 of 91
import javax.ejb.*;
import java.util.*;
public class BookBean
implements javax.ejb.EntityBean {
private String author;
private String title;
private String callNo;
private String subject;
private String status;
private EntityContext context;
public String ejbCreate(String anAuthor,
String aTitle, String aCallNo,
String aSubject) {
author = anAuthor;
title = aTitle;
callNo = aCallNo;
subject = aSubject;
// Do an insert into the database
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 65 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 66 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 67 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 68 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 69 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 70 of 91
Entity Beans
A BMP bean must contain:
A codeless no argument constructor.
The persistent fields.
Home related methods ejbCreate and
ejbPostCreate method for every create method in
the Home interface. ejbFindXXX for every findXXX in
the Home interface.
Business methods Every business method in the
component interface must be in the bean class.
One or more javax.ejb.EntityBean
interface methods.
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 71 of 91
Entity Beans
Entity Bean Methods:
ejbCreate Inserts a row
ejbRemove Deletes a row
ejbPassivate Clean up code before container
writes a stateful session bean to secondary storage
ejbActivate Regain resources after container
rebuilds a stateful session bean from secondary storage
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 72 of 91
Entity Beans
Entity Bean Methods:
setEntityContext Constructor code
unsetEntityContext Cleanup code before container
destroys instance
ejbLoad Puts data from database into bean
ejbStore Puts data from bean into database
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 73 of 91
import javax.ejb.*;
import java.rmi.*;
public interface PatronHome extends EJBHome {
public Patron create(String name, String addr, String cardID)
throws RemoteException, CreateException;
public String findByPrimaryKey(String cardID)
throws RemoteException, FinderException;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 74 of 91
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
public interface Patron extends EJBObject {
public String getName() throws RemoteException;
public Collection getHoldings() throws RemoteException;
public float getFines() throws RemoteException;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 75 of 91
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
public abstract class PatronBean implements EntityBean {
private EntityContext context;
public String ejbCreate(String name,
String addr, String cardID) {
setName(name);
setAddress(addr);
setLibCardNo(cardID);
return getLibCardNo();
}
public void ejbPostCreate(String name,
String addr, String cardID) {
}
public void setEntityContext(EntityContext ctx) {
context = ctx;
}
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 76 of 91
public
public
public
public
public
public
public
public
public
public
public
public
void unsetEntityContext() { }
void ejbRemove() { }
void ejbActivate() {}
void ejbPassivate() {}
void ejbLoad() {}
void ejbStore() {}
abstract String getName();
abstract void setName(String name);
abstract String getLibCardNo();
abstract void setLibCardNo(String lcn);
abstract String getAddress();
abstract void setAddress(String addr);
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 77 of 91
Entity Beans
A CMP bean must contain:
A codeless no argument constructor
Abstract getters and setters in place of persistent fields
Home related methods ejbCreate and
ejbPostCreate method for every create method in
the Home interface.
Business methods Every business method in the
component interface must be in the bean class
javax.ejb.EntityBean interface methods
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 78 of 91
Message-Driven Beans
Are asynchronously invoked through the JMS API
Have no home or component interface
Are similar to stateless session beans:
Hold no conversational state
Pooled
Handle requests from multiple clients
MDB
JMS Client
JMS
Message
Topic
MDB
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 79 of 91
import java.io.Serializable;
import java.rmi.*;
import javax.ejb.*;
import javax.naming.*;
import javax.jms.*;
public class PurchaseOrderMakerBean
implements MessageDrivenBean, MessageListener {
private MessageDrivenContext mdContext;
public void setMessageDrivenContext(
MessageDrivenContext mdc) {
mdContext = mdc;
}
public void ejbCreate() { }
public void onMessage(Message inMessage) {
try {
if (inMessage instanceof TextMessage) {
TextMessage msg =(TextMessage) inMessage;
// Extract data from msg and create order
} else {
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 80 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 81 of 91
Message-Driven Beans
Must contain:
A codeless no argument constructor
javax.ejb.MessageDrivenBean interface methods:
ejbCreate Initialization code
setMessageDrivenContext Optionally save a
reference to the context
A javax.jms.MessageListener interface method:
onMessage Code for how to process a message
There are no interfaces, and the client is a standard JMS client
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 82 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 83 of 91
lookup("java:/j2ee/jcbs/ds1")
DataSource
DataSource
Connection
Connection
Statement
Statement
Statement
Statement
ResultSet
ResultSet
ResultSet
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Connection
Appendix B, slide 84 of 91
import
import
import
import
java.sql.*;
javax.sql.*;
java.util.*;
javax.naming.*;
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 85 of 91
ds = (DataSource)context.lookup
("java:comp/env/jdbc/catalog");
} catch(NamingException ne) {
System.out.println
("JNDI failure: " + ne.getMessage());
System.exit(1);
}
}
public Collection search(String authorName) {
ArrayList al = new ArrayList();
try {
conn = ds.getConnection();
stmt = conn.prepareStatement(
"select * from Catalog where author = ?");
stmt.setString(1, authorName);
ResultSet rs = stmt.executeQuery();
int x = 0;
while(rs.next() == true) {
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 86 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 87 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 88 of 91
Enterprise
Bean
System Contract
Web
Component
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Application
Contract
Resource
Adapter
EIS
Application
Contract
Appendix B, slide 89 of 91
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 90 of 91
Summary
J2EE platform is a framework for building enterprise
applications using Java technology
The major technologies supported by J2EE include:
Java RMI
Java IDL
JNDI API
Java Servlet API
JavaServer Pages
JMS API
EJB technology
JDBC technology
Java EE Patterns
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision C.1
Appendix B, slide 91 of 91