A Reusable Asset - phillyjug.files.wordpress.com · Books (GoF Design Patterns, Java Cookbook, Core...
Transcript of A Reusable Asset - phillyjug.files.wordpress.com · Books (GoF Design Patterns, Java Cookbook, Core...
Coor
dina
ted
Web
Con
trolle
rs:
Coor
dina
ted
Web
Con
trolle
rs:
A Re
usab
le As
set
A Re
usab
le As
set
Agen
daAg
enda
!Th
e Pro
blem
"Do
main
�wha
t pro
blem
does
the C
oord
inated
Web
Con
trolle
r as
set s
olve?
"Pr
agma
tics �
how
do yo
u pac
kage
and d
elive
r an a
sset
so
that it
is co
st eff
ectiv
e?!
The S
olutio
n: Co
ordin
ated W
eb C
ontro
ller A
sset
"Ma
king s
ure t
his is
the r
ight s
olutio
n (fit
analy
sis)
"Ap
plying
the a
sset
in yo
ur en
viron
ment
!Co
ordin
ated W
eb C
ontro
llers
in Ac
tion
"A
demo
nstra
tion u
sing t
he as
set�s
unit t
ests
!Th
e Pro
blem
"Do
main
�wha
t pro
blem
does
the C
oord
inated
Web
Con
trolle
r as
set s
olve?
"Pr
agma
tics �
how
do yo
u pac
kage
and d
elive
r an a
sset
so
that it
is co
st eff
ectiv
e?!
The S
olutio
n: Co
ordin
ated W
eb C
ontro
ller A
sset
"Ma
king s
ure t
his is
the r
ight s
olutio
n (fit
analy
sis)
"Ap
plying
the a
sset
in yo
ur en
viron
ment
!Co
ordin
ated W
eb C
ontro
llers
in Ac
tion
"A
demo
nstra
tion u
sing t
he as
set�s
unit t
ests
Audi
ence
Audi
ence
!Th
is pr
esen
tation
assu
mes t
hat y
ou ar
e fam
iliar w
ith th
e fol
lowing
tech
nolog
ies"
Web
appli
catio
ns"
Java
, J2E
E 1.2
, JSP
1.1
"Un
ified M
odeli
ng La
ngua
ge (U
ML)
!Th
is pr
esen
tation
assu
mes t
hat y
ou ar
e fam
iliar w
ith th
e fol
lowing
tech
nolog
ies"
Web
appli
catio
ns"
Java
, J2E
E 1.2
, JSP
1.1
"Un
ified M
odeli
ng La
ngua
ge (U
ML)
The P
robl
em: D
omain
The P
robl
em: D
omain
!Ma
ny w
eb ap
plica
tions
are d
riven
by co
ntroll
ers (
MVC,
Fr
ont C
ontro
ller J
2EE
Desig
n Patt
ern)
."
Contr
oller
s man
age t
he di
alog b
etwee
n the
user
and t
he
syste
m, ov
errid
ing pa
ge re
ques
ts if a
ppro
priat
e.!
Many
web
appli
catio
n are
a co
mpos
ition o
f disc
rete
sub
syste
ms or
sepa
rate
web a
pplic
ation
s.!
Contr
oller
s are
often
deve
loped
inde
pend
ently
from
ea
ch ot
her.
!Cl
ashe
s and
confu
sion c
an ha
ppen
whe
n con
trolle
rs ar
e int
egra
ted in
the s
ame
"W
hich c
ontro
ller h
as pr
eced
ence
?"
Can m
ultipl
e con
trolle
rs be
activ
e at th
e sam
e tim
e?"
Wha
t are
the r
ules f
or m
anag
ing in
dividu
al co
ntroll
ers?
!Ma
ny w
eb ap
plica
tions
are d
riven
by co
ntroll
ers (
MVC,
Fr
ont C
ontro
ller J
2EE
Desig
n Patt
ern)
."
Contr
oller
s man
age t
he di
alog b
etwee
n the
user
and t
he
syste
m, ov
errid
ing pa
ge re
ques
ts if a
ppro
priat
e.!
Many
web
appli
catio
n are
a co
mpos
ition o
f disc
rete
sub
syste
ms or
sepa
rate
web a
pplic
ation
s.!
Contr
oller
s are
often
deve
loped
inde
pend
ently
from
ea
ch ot
her.
!Cl
ashe
s and
confu
sion c
an ha
ppen
whe
n con
trolle
rs ar
e int
egra
ted in
the s
ame
"W
hich c
ontro
ller h
as pr
eced
ence
?"
Can m
ultipl
e con
trolle
rs be
activ
e at th
e sam
e tim
e?"
Wha
t are
the r
ules f
or m
anag
ing in
dividu
al co
ntroll
ers?
The P
robl
em: P
ragm
atics
The P
robl
em: P
ragm
atics
!Ho
w do
I find
solut
ions t
o my p
roble
ms in
gene
ral?
"Bo
oks (
GoF
Desig
n Patt
erns
, Jav
a Coo
kboo
k, Co
re J2
EE
Patte
rns,
etc.)
"W
eb S
ites (
jGur
u, Th
eSer
verS
ide.co
m, et
c.)"
Comp
onen
ts!
How
do I d
eterm
ine if
this i
s the
right
solut
ion fo
r my
prob
lem?
"Tr
y/Eva
luate
it"
Ask a
frien
d.!
Wha
t do I
have
to do
to ge
t this
solut
ion w
orkin
g in m
y de
velop
ment
envir
onme
nt?
!Ho
w do
I find
solut
ions t
o my p
roble
ms in
gene
ral?
"Bo
oks (
GoF
Desig
n Patt
erns
, Jav
a Coo
kboo
k, Co
re J2
EE
Patte
rns,
etc.)
"W
eb S
ites (
jGur
u, Th
eSer
verS
ide.co
m, et
c.)"
Comp
onen
ts!
How
do I d
eterm
ine if
this i
s the
right
solut
ion fo
r my
prob
lem?
"Tr
y/Eva
luate
it"
Ask a
frien
d.!
Wha
t do I
have
to do
to ge
t this
solut
ion w
orkin
g in m
y de
velop
ment
envir
onme
nt?
RAS:
A S
tand
ard
for A
sset
sRA
S: A
Sta
ndar
d fo
r Ass
ets
!Th
e Reu
sable
Ass
et Sp
ecific
ation
is a
stand
ard f
or
pack
aging
asse
ts. It
prov
ides m
echa
nisms
and
guida
nce f
or:
"Ho
w to
mana
ge di
scre
te ar
tifacts
"W
hat d
ocum
entat
ion is
requ
ired
"Cu
stom
autom
ation
via s
cripti
ng
!Th
e Reu
sable
Ass
et Sp
ecific
ation
is a
stand
ard f
or
pack
aging
asse
ts. It
prov
ides m
echa
nisms
and
guida
nce f
or:
"Ho
w to
mana
ge di
scre
te ar
tifacts
"W
hat d
ocum
entat
ion is
requ
ired
"Cu
stom
autom
ation
via s
cripti
ng
The S
olut
ion:
Coo
rdin
ated
Web
Con
trolle
rsTh
e Sol
utio
n: C
oord
inat
ed W
eb C
ontro
llers
!Th
e Coo
rdina
ted W
eb C
ontro
ller (
CWC)
asse
t is a
MVC
base
d des
ign pa
ttern
/mec
hanis
m tha
t allo
ws m
ultipl
e co
ntroll
ers t
o be i
ntegr
ated i
n the
same
web
appli
catio
n.!
It exte
nds t
he F
ront
Contr
oller
desig
n patt
ern b
y pr
ovidi
ng a
mech
anism
to co
ordin
ate th
e acti
vities
of
multip
le ac
tive F
ront
Contr
oller
s.!
This
asse
t is a
comb
inatio
n of:
"Do
cume
ntatio
n"
Java
sour
ce an
d con
figur
ation
files
"UM
L mod
els"
Exec
utable
patte
rns (
XDE)
"Pr
oces
s and
usag
e guid
ance
"
Unit t
est in
frastr
uctur
e
!Th
e Coo
rdina
ted W
eb C
ontro
ller (
CWC)
asse
t is a
MVC
base
d des
ign pa
ttern
/mec
hanis
m tha
t allo
ws m
ultipl
e co
ntroll
ers t
o be i
ntegr
ated i
n the
same
web
appli
catio
n.!
It exte
nds t
he F
ront
Contr
oller
desig
n patt
ern b
y pr
ovidi
ng a
mech
anism
to co
ordin
ate th
e acti
vities
of
multip
le ac
tive F
ront
Contr
oller
s.!
This
asse
t is a
comb
inatio
n of:
"Do
cume
ntatio
n"
Java
sour
ce an
d con
figur
ation
files
"UM
L mod
els"
Exec
utable
patte
rns (
XDE)
"Pr
oces
s and
usag
e guid
ance
"
Unit t
est in
frastr
uctur
e
The C
WC.
ras f
ileTh
e CW
C.ra
s file
!Th
e Coo
rdina
ted W
eb C
ontro
ller a
sset
is pa
ckag
ed as
a RA
S file
.!
The a
sset
has a
sing
le de
scrip
tor fil
e, for
matte
d as a
n XM
L doc
umen
t. "
Clas
sifica
tion �
spec
ifies e
lemen
ts tha
t help
clas
sify t
he
asse
t�s ap
plica
tion a
nd de
velop
ment
envir
onme
nts.
"So
lution
�sp
ecifie
s the
artifa
cts an
d typ
es th
at ma
ke up
the
asse
t."
Usag
e �lis
t�s ac
tivitie
s for
the u
se of
this
asse
t. Ca
n be
autom
ated s
cripts
or si
mply
point
ers t
o inc
luded
do
cume
ntatio
n."
Relat
ed A
ssets
�re
feren
ces t
o othe
r dep
ende
nt as
sets.
!Th
e Coo
rdina
ted W
eb C
ontro
ller a
sset
is pa
ckag
ed as
a RA
S file
.!
The a
sset
has a
sing
le de
scrip
tor fil
e, for
matte
d as a
n XM
L doc
umen
t. "
Clas
sifica
tion �
spec
ifies e
lemen
ts tha
t help
clas
sify t
he
asse
t�s ap
plica
tion a
nd de
velop
ment
envir
onme
nts.
"So
lution
�sp
ecifie
s the
artifa
cts an
d typ
es th
at ma
ke up
the
asse
t."
Usag
e �lis
t�s ac
tivitie
s for
the u
se of
this
asse
t. Ca
n be
autom
ated s
cripts
or si
mply
point
ers t
o inc
luded
do
cume
ntatio
n."
Relat
ed A
ssets
�re
feren
ces t
o othe
r dep
ende
nt as
sets.
The r
asse
t.xm
l Ass
et D
escr
ipto
r File
The r
asse
t.xm
l Ass
et D
escr
ipto
r File
<?xmlversion="1.0" encoding="UTF-8"?>
<asset asset-guid="" date="" name="RAS File" ... >
<classification>
<descriptor-group name="Reference Application Classification">
<context id="Application_Environment" name="Application Environment" value="Websphere4.2"/>
<context id="Development_Environment" name="Development Environment" value="WSSAD 4.0.3, Rational XDE"/>
<descriptor name="Artifact Author" value="jim conallen"/>
<descriptor name="Packager" value="jim conallen"/>
<descriptor name="Keyword" value="web application"/>
<descriptor name="Keyword" value="web development"/>
<descriptor name="Keyword" value="J2EE"/>
<descriptor name="Keyword" value="JSP"/>
<descriptor name="Keyword" value="controller"/>
<descriptor name="Keyword" value="coordinator"/>
<descriptor name="Keyword" value="MVC"/>
<descriptor name="Keyword" value="request processing"/>
<descriptor name="Keyword" value="XDE"/>
<descriptor name="Keyword" value="Websphere"/>
<descriptor name="Keyword" value="Java"/>
<descriptor name="Problem Solved" value="Coordination of discrete web controllers."/>
</descriptor-group>
</classification>
<solution>
<artifact reference="CWC Code.mdx" type="XDE Model"/>
<artifact reference="Unit Test Design.mdx" type="artifact"/>
<artifact reference="Unit Test User-Experience.mdx" type="artifact"/>
<artifact reference="documentation/Web Controller/cwc.html" type="artifact"/>
<artifact reference="documentation/Web Controller/install.html" type="artifact"/>
<artifact reference="source/com/rational/cwc/Coordinator.java" type="artifact"/>
<artifact reference="source/com/rational/cwc/IPageDispatcher.java" type="artifact"/>
<artifact reference="source/com/rational/cwc/IWebController.java" type="artifact"/>
<artifact reference="source/com/rational/cwc/PageDispatcher.java" type="artifact"/>
<artifact reference="source/com/rational/cwc/RequestProcessor.java" type="artifact"/>
<artifact reference="webApplication/WEB-INF/web.xml" type="artifact"/>
<artifact reference="webApplication/WEB-INF/WebControllerConfig.xml" type="artifact"/>
<artifact reference="webApplication/WEB-INF/WebControllerConfig.xsd" type="artifact"/>
<artifact reference="webApplication/WEB-INF/lib/xercesImpl.jar" type="artifact"/>
<artifact reference="webApplication/WEB-INF/lib/xmlParserAPIs.jar" type="artifact"/>
...
</solution>
Ther
asse
t.xm
lAss
et D
escr
ipto
r File
Ther
asse
t.xm
lAss
et D
escr
ipto
r File
<descriptor name="Keyword" value="coordinator"/>
<descriptor name="Keyword" value="MVC"/>
<descriptor name="Keyword" value="request processing"/>
<descriptor name="Keyword" value="XDE"/>
<descriptor name="Keyword" value="Websphere"/>
<descriptor name="Keyword" value="Java"/>
<descriptor name="Problem Solved" value="Coordination of discrete web controllers."/>
</descriptor-group>
</classification>
<solution>
<artifact reference="CWC Code.mdx" type="XDE Model"/>
<artifact reference="Unit Test Design.mdx" type="artifact"/>
<artifact reference="Unit Test User-Experience.mdx" type="artifact"/>
<artifact reference="documentation/Web Controller/cwc.html" type="artifact"/>
<artifact reference="documentation/Web Controller/install.html" type="artifact"/>
<artifact reference="source/com/rational/cwc/Coordinator.java" type="artifact"/>
<artifact reference="source/com/rational/cwc/IPageDispatcher.java" type="artifact"/>
<artifact reference="source/com/rational/cwc/IWebController.java" type="artifact"/>
<artifact reference="source/com/rational/cwc/PageDispatcher.java" type="artifact"/>
<artifact reference="source/com/rational/cwc/RequestProcessor.java" type="artifact"/>
<artifact reference="webApplication/WEB-INF/web.xml" type="artifact"/>
<artifact reference="webApplication/WEB-INF/WebControllerConfig.xml" type="artifact"/>
<artifact reference="webApplication/WEB-INF/WebControllerConfig.xsd" type="artifact"/>
<artifact reference="webApplication/WEB-INF/lib/xercesImpl.jar" type="artifact"/>
<artifact reference="webApplication/WEB-INF/lib/xmlParserAPIs.jar" type="artifact"/>
...
</solution>
<usage>
<asset-activity>
<activity id="Install" task="Install this asset" reference="documentation/Web Controller/cwc.html"/>
<activity id="Factory configfile default" reference="source/com/rational/cwc/WebControllerFactory.java"/>
<activity id="Update web.xmlconfiguration file" reference="webApplication/WEB-INF/web.xml"/>
</asset-activity>
</usage>
</asset>
Fit A
nalys
isFi
t Ana
lysis
!W
hat e
nviro
nmen
ts ha
s this
asse
t bee
n des
igned
for?
Te
sted a
gains
t ?!
Who
crea
ted th
is as
set?
Is th
is a r
eliab
le so
urce
?!
How
much
of th
e ass
et is
open
? How
muc
h is b
inary
and h
ow m
uch i
s sou
rce?
!Ho
w mu
ch w
ill I h
ave t
o cha
nge m
y cur
rent
desig
n to
acco
mmod
ate th
is pa
ttern
?!
Wha
t othe
r ass
ets/pa
ttern
s am
I usin
g? A
re th
ere a
ny
confl
icts?
"Is
this a
sset
comp
atible
with
the �
Patte
rn T
empla
te� J2
EE
patte
rn?
"W
hat im
pact
will t
his ha
ve on
my H
TML d
evelo
pmen
t (UX
) tea
m?
!W
hat e
nviro
nmen
ts ha
s this
asse
t bee
n des
igned
for?
Te
sted a
gains
t ?!
Who
crea
ted th
is as
set?
Is th
is a r
eliab
le so
urce
?!
How
much
of th
e ass
et is
open
? How
muc
h is b
inary
and h
ow m
uch i
s sou
rce?
!Ho
w mu
ch w
ill I h
ave t
o cha
nge m
y cur
rent
desig
n to
acco
mmod
ate th
is pa
ttern
?!
Wha
t othe
r ass
ets/pa
ttern
s am
I usin
g? A
re th
ere a
ny
confl
icts?
"Is
this a
sset
comp
atible
with
the �
Patte
rn T
empla
te� J2
EE
patte
rn?
"W
hat im
pact
will t
his ha
ve on
my H
TML d
evelo
pmen
t (UX
) tea
m?
CWC
Docu
men
tatio
nCW
C Do
cum
enta
tion
!As
sets
prov
ide th
eir
own d
ocum
entat
ion
which
inclu
des:
"Au
thor/p
acka
ger
"Cl
assif
icatio
n key
word
s"
Prob
lem su
mmar
y"
Bene
fits"
Liabil
ities
"Kn
own u
ses
"Us
age i
nstru
ction
s"
Relat
ed A
ssets
"Re
sour
ce S
umma
ry
!As
sets
prov
ide th
eir
own d
ocum
entat
ion
which
inclu
des:
"Au
thor/p
acka
ger
"Cl
assif
icatio
n key
word
s"
Prob
lem su
mmar
y"
Bene
fits"
Liabil
ities
"Kn
own u
ses
"Us
age i
nstru
ction
s"
Relat
ed A
ssets
"Re
sour
ce S
umma
ry
Asse
t Usa
geAs
set U
sage
!Th
e usa
ge se
ction
gu
ides t
he
deve
loper
on ho
w to
�use
� the
asse
t inc
luding
:"
Instal
lation
"Co
nfigu
ratio
n"
Testi
ng"
Modif
ying
!Th
e usa
ge se
ction
gu
ides t
he
deve
loper
on ho
w to
�use
� the
asse
t inc
luding
:"
Instal
lation
"Co
nfigu
ratio
n"
Testi
ng"
Modif
ying
CWC
Stru
ctur
al Ov
ervie
wCW
C St
ruct
ural
Over
view
!Cl
ass D
iagra
m !
Clas
s Diag
ram
Co
ord
inat
or
«Jav
aInt
erfa
ce»
IPag
eDis
pat
cher
«Jav
aInt
erfa
ce»
IWeb
Co
ntr
olle
r
Pa
geD
isp
atch
er
Req
ues
tPro
cess
or
Web
Co
ntr
olle
rFac
tory
Web
Co
ntr
olle
rMet
a
- ac
tiveC
ontr
olle
r
- ac
tiveC
ontr
olle
rs*
- de
faul
tCon
trol
ler
- av
aila
bleC
ontr
olle
rs*
Parti
cipan
ts -
1Pa
rticip
ants
-1
!Re
ques
tPro
cess
or"
The r
eque
st pr
oces
sor is
a se
rvlet
that in
terce
pts al
l inco
ming
HTT
P re
ques
ts an
d dele
gates
its pr
oces
sing t
o the
coor
dinato
r. A
sepa
rate
coor
dinato
r insta
nce i
s cac
hed i
n eac
h use
r's se
ssion
(i.e.
use b
ean t
ag
with
sess
ion sc
ope)
. Afte
r pro
cess
ing an
IPag
eDisp
atche
robje
ct is
retur
ned t
hat is
used
to in
itiate
the di
spatc
hing o
f the r
espo
nse p
age.
!Co
ordin
ator
"Th
e Coo
rdina
tor is
resp
onsib
le for
man
aging
a qu
eue o
f Web
co
ntroll
ers.
The c
oord
inator
is ca
lled u
pon b
y the
Requ
estP
roce
ssor
to pr
oces
s an i
ncom
ingHt
tpReq
uest.
The
Http
Requ
estis
proc
esse
d by
the ac
tive c
ontro
ller a
nd th
en th
e coo
rdina
tor qu
eries
the c
ontro
ller f
or
the ne
xt sc
reen
. The
contr
oller
retur
ns an
insta
nce o
f an o
bject
that
imple
ments
theI
Page
Disp
atche
rinter
face,
which
is pa
ssed
back
to th
e Re
ques
tPro
cess
or.
"Th
e coo
rdina
tor ex
amine
s the
URL
to se
e if a
diffe
rent
contr
oller
is
spec
ified.
Only
if the
activ
e con
trolle
r (top
of st
ack)
does
n'tre
quire
ex
clusiv
e acc
ess w
ill the
contr
oller
try t
o find
the s
pecif
ied co
ntroll
er in
ac
tive q
ueue
. If it
isn't
foun
d the
n the
coor
dinato
r will
create
a ne
w on
e fro
m the
Web
Contr
oller
Facto
ry.
!Re
ques
tPro
cess
or"
The r
eque
st pr
oces
sor is
a se
rvlet
that in
terce
pts al
l inco
ming
HTT
P re
ques
ts an
d dele
gates
its pr
oces
sing t
o the
coor
dinato
r. A
sepa
rate
coor
dinato
r insta
nce i
s cac
hed i
n eac
h use
r's se
ssion
(i.e.
use b
ean t
ag
with
sess
ion sc
ope)
. Afte
r pro
cess
ing an
IPag
eDisp
atche
robje
ct is
retur
ned t
hat is
used
to in
itiate
the di
spatc
hing o
f the r
espo
nse p
age.
!Co
ordin
ator
"Th
e Coo
rdina
tor is
resp
onsib
le for
man
aging
a qu
eue o
f Web
co
ntroll
ers.
The c
oord
inator
is ca
lled u
pon b
y the
Requ
estP
roce
ssor
to pr
oces
s an i
ncom
ingHt
tpReq
uest.
The
Http
Requ
estis
proc
esse
d by
the ac
tive c
ontro
ller a
nd th
en th
e coo
rdina
tor qu
eries
the c
ontro
ller f
or
the ne
xt sc
reen
. The
contr
oller
retur
ns an
insta
nce o
f an o
bject
that
imple
ments
theI
Page
Disp
atche
rinter
face,
which
is pa
ssed
back
to th
e Re
ques
tPro
cess
or.
"Th
e coo
rdina
tor ex
amine
s the
URL
to se
e if a
diffe
rent
contr
oller
is
spec
ified.
Only
if the
activ
e con
trolle
r (top
of st
ack)
does
n'tre
quire
ex
clusiv
e acc
ess w
ill the
contr
oller
try t
o find
the s
pecif
ied co
ntroll
er in
ac
tive q
ueue
. If it
isn't
foun
d the
n the
coor
dinato
r will
create
a ne
w on
e fro
m the
Web
Contr
oller
Facto
ry.
Serv
let C
onfig
urat
ion
Serv
let C
onfig
urat
ion
!Th
e mos
t impo
rtant
web.x
ml co
nfigu
ratio
n opti
on di
rects
all
inco
ming
requ
ests
to the
Req
uestP
roce
ssor
servl
et!
The m
ost im
porta
nt we
b.xml
confi
gura
tion o
ption
dire
cts
all in
comi
ng re
ques
ts to
the R
eque
stPro
cess
or se
rvlet
<?xml
version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN“
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app id="WebApp">
<display-name>Cwc</display-name>
<servlet>
<servlet-name>RequestProcessor</servlet-name>
<display-name>RequestProcessor</display-name>
<servlet-class>com.rational.cwc.RequestProcessor</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RequestProcessor</servlet-name>
<url-pattern>*.scr</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<exception-type>com.rational.cwc.UnknownControllerException</exception-type>
<location>/index.jsp</location>
</error-page>
</web-app>
Parti
cipan
ts -
2Pa
rticip
ants
-2
!IW
ebCo
ntroll
er"
An ob
ject th
at im
pleme
nts th
eIW
ebCo
ntroll
erint
erfac
e is
capa
ble of
proc
essin
g anH
ttpRe
ques
t. Th
e con
trolle
r int
erac
ts wi
th mi
ddle
tier c
ompo
nents
to up
date
the st
ate of
the
busin
ess.
A co
ntroll
er m
ust a
lso be
able
to re
turn a
nIP
ageD
ispatc
hero
bject
that c
an be
used
to fo
rwar
d the
re
spon
se pa
ge pr
oces
sing t
o. A
web
contr
oller
mus
t also
be
able
to re
turn k
ey m
eta in
forma
tion (
name
and d
escri
ption
) an
d ind
icate
wheth
er it
is in
an ex
clusiv
e stat
e or n
ot (i.e
. sh
ould
not b
e bum
ped f
rom
the ac
tive c
ontro
ller r
ole).
The
las
t res
pons
ibility
of a
contr
oller
is to
indic
ate w
hen i
t has
co
mplet
ed. W
hen a
contr
oller
indic
ates t
hat it
has c
omple
ted
the co
ordin
ator is
free
to re
move
it fro
m the
activ
e con
trolle
r sta
ck.
!IW
ebCo
ntroll
er"
An ob
ject th
at im
pleme
nts th
eIW
ebCo
ntroll
erint
erfac
e is
capa
ble of
proc
essin
g anH
ttpRe
ques
t. Th
e con
trolle
r int
erac
ts wi
th mi
ddle
tier c
ompo
nents
to up
date
the st
ate of
the
busin
ess.
A co
ntroll
er m
ust a
lso be
able
to re
turn a
nIP
ageD
ispatc
hero
bject
that c
an be
used
to fo
rwar
d the
re
spon
se pa
ge pr
oces
sing t
o. A
web
contr
oller
mus
t also
be
able
to re
turn k
ey m
eta in
forma
tion (
name
and d
escri
ption
) an
d ind
icate
wheth
er it
is in
an ex
clusiv
e stat
e or n
ot (i.e
. sh
ould
not b
e bum
ped f
rom
the ac
tive c
ontro
ller r
ole).
The
las
t res
pons
ibility
of a
contr
oller
is to
indic
ate w
hen i
t has
co
mplet
ed. W
hen a
contr
oller
indic
ates t
hat it
has c
omple
ted
the co
ordin
ator is
free
to re
move
it fro
m the
activ
e con
trolle
r sta
ck.
Parti
cipan
ts -
3Pa
rticip
ants
-3
!W
ebCo
ntroll
erFa
ctory
"Th
eWeb
Contr
oller
Facto
ryis
a sing
leton
facto
ry ob
ject th
at is
resp
onsib
le for
the c
reati
on of
Web
Contr
oller
Meta
instan
ces.
Its m
ain re
spon
sibilit
y is t
o rea
d the
XML
confi
gura
tion f
ile
that li
sts th
e nam
es an
d Jav
a clas
ses o
f all t
he kn
own
contr
oller
clas
ses.
The
file a
lso sp
ecifie
s som
e meta
inf
orma
tion a
bout
the co
ntroll
er. T
he co
nfigu
ratio
n file
can b
e re
loade
d at r
untim
e.
!W
ebCo
ntroll
erMe
ta"
AW
ebCo
ntroll
erMe
tains
tance
repr
esen
ts me
ta inf
orma
tion
abou
t an a
ctual
Web
contr
oller
clas
s. T
he m
eta cl
ass i
s use
d to
create
actua
l insta
nces
of a
contr
oller
via t
he
Clas
s.for
Name
(...)
andc
reate
Instan
ce()
metho
ds.
!W
ebCo
ntroll
erFa
ctory
"Th
eWeb
Contr
oller
Facto
ryis
a sing
leton
facto
ry ob
ject th
at is
resp
onsib
le for
the c
reati
on of
Web
Contr
oller
Meta
instan
ces.
Its m
ain re
spon
sibilit
y is t
o rea
d the
XML
confi
gura
tion f
ile
that li
sts th
e nam
es an
d Jav
a clas
ses o
f all t
he kn
own
contr
oller
clas
ses.
The
file a
lso sp
ecifie
s som
e meta
inf
orma
tion a
bout
the co
ntroll
er. T
he co
nfigu
ratio
n file
can b
e re
loade
d at r
untim
e.
!W
ebCo
ntroll
erMe
ta"
AW
ebCo
ntroll
erMe
tains
tance
repr
esen
ts me
ta inf
orma
tion
abou
t an a
ctual
Web
contr
oller
clas
s. T
he m
eta cl
ass i
s use
d to
create
actua
l insta
nces
of a
contr
oller
via t
he
Clas
s.for
Name
(...)
andc
reate
Instan
ce()
metho
ds.
Sam
ple C
ontro
ller C
onfig
urat
ion
File
Sam
ple C
ontro
ller C
onfig
urat
ion
File
!A
custo
m XM
L sch
ema f
or th
is as
set.
!Re
pres
ents
contr
oller
meta
infor
matio
n.!
Contr
oller
s are
defin
ed w
ith na
mes a
nd im
pleme
nting
cla
sses
. Exc
lusivi
ty is
set in
this
file.
!A
custo
m XM
L sch
ema f
or th
is as
set.
!Re
pres
ents
contr
oller
meta
infor
matio
n.!
Contr
oller
s are
defin
ed w
ith na
mes a
nd im
pleme
nting
cla
sses
. Exc
lusivi
ty is
set in
this
file.
<?xml
version="1.0" encoding="UTF-8"?>
<WebControllerConfig:web-controller-config
xmlns:WebControllerConfig="http://www.rational.com/cwc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.rational.com/cwc/WebControllerConfig.xsd">
<web-controllers>
<web-controller name="UTController1A" class="com.rational.cwc.unittest.Controller1"
description="Sample controller 1A"/>
<web-controller name="UTController2A" class="com.rational.cwc.unittest.Controller2"
description="Sample controller 2A"/>
<web-controller name="UTController1Cx" class="com.rational.cwc.unittest.Controller1"
exclusive="true" description="Sample controller 1C Exclusive control"/>
<web-controller name="UTController2Cx" class="com.rational.cwc.unittest.Controller2"
exclusive="true" description="Sample controller 2C Exclusive control"/>
<web-controller name="Login" class="com.rational.cwc.unittest.LoginWebController"
description="Simple login web-controller that includes a balance check"/>
</web-controllers>
<default-web-controller name="UTController1A"/>
</WebControllerConfig:web-controller-config>
Parti
cipan
ts -
4Pa
rticip
ants
-4
!IP
ageD
ispatc
her
"An
objec
t that
imple
ments
theI
Page
Disp
atche
rinter
face i
s ca
pable
of is
suing
a for
ward
requ
est to
aRe
ques
tDisp
atche
rob
ject.
This
inter
face p
rovid
es an
abstr
actio
n lay
er in
the
HTTP
requ
est p
roce
ssing
cycle
. Imp
lemen
tation
s may
int
erpr
et the
forw
ard r
eque
st ve
ry sim
ply (i.
e. for
ward
dire
ctly
to the
supp
lied U
RL),
or th
ey m
ay pr
ovide
soph
istica
ted
imple
menta
tions
that
involv
e pag
e com
posit
ion (i.
e. Su
n J2E
E Te
mplat
ed P
age p
atter
n).
!Pa
geDi
spatc
her
"A
simple
imple
menta
tion o
f theI
Page
Disp
atche
rinter
face.
W
hen c
reate
d the
Page
Disp
atche
robje
ct ac
cepts
a UR
L.
This
URL i
s use
d dire
ctly (
witho
ut mo
difica
tion)
with
the
Requ
estD
ispatc
herw
hen f
orwa
rding
.
!IP
ageD
ispatc
her
"An
objec
t that
imple
ments
theI
Page
Disp
atche
rinter
face i
s ca
pable
of is
suing
a for
ward
requ
est to
aRe
ques
tDisp
atche
rob
ject.
This
inter
face p
rovid
es an
abstr
actio
n lay
er in
the
HTTP
requ
est p
roce
ssing
cycle
. Imp
lemen
tation
s may
int
erpr
et the
forw
ard r
eque
st ve
ry sim
ply (i.
e. for
ward
dire
ctly
to the
supp
lied U
RL),
or th
ey m
ay pr
ovide
soph
istica
ted
imple
menta
tions
that
involv
e pag
e com
posit
ion (i.
e. Su
n J2E
E Te
mplat
ed P
age p
atter
n).
!Pa
geDi
spatc
her
"A
simple
imple
menta
tion o
f theI
Page
Disp
atche
rinter
face.
W
hen c
reate
d the
Page
Disp
atche
robje
ct ac
cepts
a UR
L.
This
URL i
s use
d dire
ctly (
witho
ut mo
difica
tion)
with
the
Requ
estD
ispatc
herw
hen f
orwa
rding
.
Deta
iled
Stru
ctur
al Vi
ewDe
taile
d St
ruct
ural
View
unitt
estCo
ord
ina
tor
+ g
etA
ctiv
eCon
trol
lers
(
)+
get
Act
iveC
ontr
olle
r (
)+
add
Con
trol
ler
( )
+ r
emov
eCon
trol
ler
( )
+ n
umbe
rAct
iveC
ontr
olle
rs (
)
+ p
roce
ssR
eque
st (
)
Re
qu
est
Pro
cess
or
+ R
eque
stPr
oces
sor
( )
+ d
oGet
(
)+
doP
ost
( )
«Jav
aInt
erfa
ce»
IWeb
Cont
rolle
r
+ n
extS
cree
n (
)+
com
plet
ed (
)+
pro
cess
(
)+
res
et (
)
+ g
etEx
clus
ive
( )
+ s
etEx
clus
ive
( )
+ g
etN
ame
( )
+ g
etD
escr
iptio
n (
)+
set
Nam
e (
)+
set
Des
crip
tion
( )
Log
inW
eb
Co
ntr
olle
r
Pa
ge
Dis
pa
tch
er
- ur
l : S
trin
g
+ f
orw
ard
( )
+ P
ageD
ispa
tche
r (
)
«Jav
aInt
erfa
ce»
IPag
eDis
patc
her
+ fo
rwar
d (
)
We
bC
on
tro
llerF
act
ory
+ G
etD
efau
ltWeb
Con
trol
ler
( )
+ G
etW
ebC
ontr
olle
r (
)+
Get
AllW
ebC
ontr
olle
rMet
a (
)+
Get
Def
aultW
ebC
ontr
olle
rNam
e (
)+
Rel
oadC
ontr
olle
rs (
)
+ R
eloa
dCon
trol
lers
(
)-
Set
Ava
ilabl
eCon
trol
lers
(
)+
Get
Def
aultW
ebC
ontr
olle
rMet
a (
)-
Set
Def
aultC
ontr
olle
r (
)
Cont
rolle
r Co
ntr
olle
r1C
on
tro
ller2
Un
kno
wn
Co
ntr
olle
rExc
ep
tio
n
- ex
pect
edC
ontr
olle
r :
Str
ing
= "
"
+ g
etEx
pect
edC
ontr
olle
r (
)+
set
Expe
cted
Con
trol
ler
( )
+ U
nkno
wnC
ontr
olle
rExc
eptio
n (
)
We
bC
on
tro
llerM
eta
+ n
ame
: S
trin
g+
des
crip
tion
: S
trin
g+
cla
ssN
ame
: S
trin
g+
exc
lusi
ve :
boo
lean
+ v
alid
(
)+
cre
ateI
nsta
nce
( )
+ W
ebC
ontr
olle
rMet
a (
)
- av
aila
bleC
ontr
olle
rs*
- de
faul
tCon
trol
ler
- ac
tiveC
ontr
olle
r
- ac
tiveC
ontr
olle
rs*
Colla
bora
tions
: Coo
rdin
ator
Initi
aliza
tion
Colla
bora
tions
: Coo
rdin
ator
Initi
aliza
tion
/ Br
owse
r :
Req
uest
Proc
esso
r
: C
oord
inat
or
/ re
ques
t/
sess
ion
: IP
ageD
ispa
tche
r
1 :
doPo
st (
req
uest
, r
espo
nse
) 2
: do
Get
( r
eque
st ,
res
pons
e )
5 :
\Cre
ateO
pera
tion\
3 :
\get
Ses
sion
\
4 :
\get
Att
ribu
te\
6 :
\set
Att
ribu
te\
7 :
proc
essR
eque
st (
req
uest
)
8 :
forw
ard
( re
ques
t ,
resp
onse
)
Colla
bora
tions
: Pro
cess
Req
uest
Colla
bora
tions
: Pro
cess
Req
uest
rem
ove
cont
rolle
r
get
activ
e co
ntro
ller
get
spec
ified
con
trol
ler
chec
k co
ntro
ller
com
plet
ion
get
defa
ult
cont
rolle
r
add
cont
rolle
r
rese
t co
ntro
ller
[con
trol
ler
spec
ified
]
[com
plet
ed]
[nul
l]
[not
com
plet
e]
Proc
ess
Req
uest
add
cont
rolle
r
proc
ess
requ
est
[res
et r
eque
sted
]
get
next
scr
een
Colla
bora
tions
: New
Con
trolle
rCo
llabo
ratio
ns: N
ew C
ontro
ller
: R
eque
stPr
oces
sor
: C
oord
inat
or :
Web
Con
trol
lerF
acto
ry/
cont
rolle
r :
IWeb
Con
trol
ler
/ re
ques
t/
new
con
trol
ler
: IW
ebC
ontr
olle
r
1 :
proc
essR
eque
st (
req
uest
)
2 :
getA
ctiv
eCon
trol
ler
( )
3 :
Get
Def
aultW
ebC
ontr
olle
rNam
e (
)
4 :
addC
ontr
olle
r (
cont
rolle
rNam
e )
5 :
com
plet
ed (
)
6 :
rem
oveC
ontr
olle
r (
cont
rolle
r )
7 :
\get
Para
met
er("
cont
rolle
r")\
8 :
getN
ame
( )
9 :
getE
xclu
sive
(
)
10 :
add
Con
trol
ler
( co
ntro
llerN
ame
)
11 :
get
Act
iveC
ontr
olle
r (
)
12 :
\ge
tPar
amet
er("
rese
t")\
13 :
pro
cess
( r
eq )
14 :
nex
tScr
een
( )
IPag
eDis
patc
her
Colla
bora
tions
: Add
Con
trolle
rCo
llabo
ratio
ns: A
dd C
ontro
ller
: C
oord
inat
or:
IWeb
Con
trol
ler
/ ac
tiveC
ontr
olle
rs:
Web
Con
trol
lerF
acto
ry
If n
ot c
urre
ntly
an
activ
e co
ntro
ller
get
a ne
w o
ne f
rom
the
fac
tory
and
m
ake
it th
e cu
rren
tly a
ctiv
e co
ntro
ller.
If t
he c
ontr
olle
r w
as f
ound
in t
he
vect
or o
f ac
tive
cont
rolle
rs,
then
re
mov
e it
and
then
add
it t
o th
e en
d of
the
vec
tor
(and
hen
ce m
akin
g it
top
of t
he v
irtu
al s
tack
).
1 :
addC
ontr
olle
r (
cont
rolle
rNam
e )
2 :
\ite
rate
act
iveC
ontr
olle
rs\
3 :
getN
ame
( )
4 :
\rem
ove(
cont
rolle
r)\
5 :
\add
(con
trol
ler)
\
6 :
Get
Web
Con
trol
ler
( na
me
)
7 :
\add
(con
trol
ler)
\
Colla
bora
tions
: Con
trolle
r Com
plet
eCo
llabo
ratio
ns: C
ontro
ller C
ompl
ete
: R
eque
stPr
oces
sor
: C
oord
inat
or/
cont
rolle
r :
IWeb
Con
trol
ler
/ ac
tiveC
ontr
olle
rs
1 :
proc
essR
eque
st (
req
uest
)
2 :
getA
ctiv
eCon
trol
ler
( )
3 :
com
plet
ed (
)
5 :
\rem
ove(
con
trol
ler
)\
6 :
\las
tEle
men
t()\
7 :
getA
ctiv
eCon
trol
ler
( )
4 :
rem
oveC
ontr
olle
r (
cont
rolle
r )
Requ
estP
roce
ssor
Ser
vlet
Requ
estP
roce
ssor
Ser
vlet
!Al
l requ
ests
are f
unne
led th
roug
h this
servl
et the
refor
e it
must
be ef
ficien
t.!
All re
ques
ts ar
e fun
neled
thro
ugh t
his se
rvlet
there
fore i
t mu
st be
effic
ient.
public void
doGet(HttpServletRequest
request,
HttpServletResponse
response)
throwsIOException, ServletException {
HttpSession session = request.getSession();
Coordinator coordinator = (Coordinator) session.getAttribute("coordinator");
if( coordinator == null ) {
//get fresh list of current controllers from the servlet context (application)
coordinator = new Coordinator();
session.setAttribute("coordinator", coordinator );
} IPageDispatcher nextScreen= coordinator.processRequest(request);
// this is our last chance to change the returned page
nextScreen.forward( request, response );
} public void
doPost(HttpServletRequest
request,
HttpServletResponse
response)
throws
IOException, ServletException {
doGet(request, response);
}public void
doGet(HttpServletRequest
request,
HttpServletResponse
response)
throwsIOException, ServletException {
HttpSession session = request.getSession();
Coordinator coordinator = (Coordinator) session.getAttribute("coordinator");
if( coordinator == null ) {
//get fresh list of current controllers from the servlet context (application)
coordinator = new Coordinator();
session.setAttribute("coordinator", coordinator );
} IPageDispatcher nextScreen= coordinator.processRequest(request);
// this is our last chance to change the returned page
nextScreen.forward( request, response );
} public void
doPost(HttpServletRequest
request,
HttpServletResponse
response)
throws
IOException, ServletException {
doGet(request, response);
}
Coor
dina
tor::
proc
essR
eque
st(..
.)Co
ordi
nato
r::pr
oces
sReq
uest
(...)
public IPageDispatcher processRequest(HttpServletRequest
request) {
IWebController
controller =getActiveController();
if( controller.completed() ) {
removeController( controller );
controller =
getActiveController();
} // check to see if another controller has been requested
String
controllerName= request.getParameter("controller");
if(
controllerName
!= null && !controllerName.equals(controller.getName())
&& !controller.getExclusive() ) {
addController(
controllerName
);
controller =
getActiveController();
} // check to see if we've been asked to reset the controller first
String reset = request.getParameter("reset");
if( reset != null ) controller.reset();
controller.process( request );
IPageDispatcher
next = controller.nextScreen();
return next;
}
Coor
dina
tor:
getA
ctive
Cont
rolle
r(�)
Coor
dina
tor:
getA
ctive
Cont
rolle
r(�)
!La
zy in
stanti
ation
is us
ed w
hen g
etting
the a
ctive
co
ntroll
er.
!Th
e add
Contr
oller
meth
od is
resp
onsib
le to
maint
aining
the
integ
rity of
the c
ontro
ller q
ueue
.
!La
zy in
stanti
ation
is us
ed w
hen g
etting
the a
ctive
co
ntroll
er.
!Th
e add
Contr
oller
meth
od is
resp
onsib
le to
maint
aining
the
integ
rity of
the c
ontro
ller q
ueue
.
public
IWebController getActiveController() {
// there is also where any custom logic in prioritizing
// which active controller should go. In this example
// the priority is what ever is on top of the stack, or
// rather the last controller to be added.
if(
activeController
== null ) {
// default to a known one
String controllerName
= WebControllerFactory.GetDefaultWebControllerName();
addController(
controllerName
);
} return activeController;
}
Coor
dina
tor::
addC
ontro
ller(�
)Co
ordi
nato
r::ad
dCon
trolle
r(�)
private void
addController( String
controllerName
) {
IWebController
controller = null;
int
index = -1;
boolean
found = false;
int
count =activeControllers.size();
for(Enumeration e =
activeControllers.elements(); e.hasMoreElements();) {
IWebControllerctrl = (IWebController) e.nextElement();
index++;
if( ctrl.getName().equals(
controllerName
) ) {
controller = ctrl;
found = true;
break;
}} if( found ) {
if( index < count-1 ) { // put it at the top of the list.
activeControllers.remove(controller);
activeControllers.add(controller);
activeController= controller;
}} else {
controller = (IWebController)
WebControllerFactory.GetWebController(
controllerName
);
if( controller != null ) {
activeControllers.add( controller );
activeController= controller;
}}
}
Coor
dina
tor::
rem
oveC
ontro
ller(�
)Co
ordi
nato
r::re
mov
eCon
trolle
r(�)
!W
hen a
contr
oller
is re
move
the n
ext o
ne in
the q
ueue
mo
ves t
o the
fron
t.!
If the
activ
e con
trolle
r is se
t to nu
ll the
gette
r will
instan
tiate
a new
defau
lt con
trolle
r.
!W
hen a
contr
oller
is re
move
the n
ext o
ne in
the q
ueue
mo
ves t
o the
fron
t.!
If the
activ
e con
trolle
r is se
t to nu
ll the
gette
r will
instan
tiate
a new
defau
lt con
trolle
r.private void
removeController(
IWebController
controller ) {
if( controller != null ) {
activeControllers.remove( controller );
if(
activeController.equals( controller ) ) {
if(
activeControllers.isEmpty() ) {
activeController= null;
} else {
activeController= (IWebController)activeControllers.lastElement();
}}
}}
Wor
king
with
JSPs
Wor
king
with
JSPs
!JS
Ps sh
ould
focus
on bu
ilding
the U
I.!
JSPs
are n
ot re
spon
sible
for pr
oces
sing u
ser in
put.
This
is the
resp
onsib
ility o
f the c
ontro
ller.
!JS
Ps ca
n acc
ess t
he co
ntroll
er an
d coo
rdina
tor th
roug
h the
Http
Servl
etSes
sion o
bject.
!Al
l hyp
erlin
ks in
web
page
s sho
uld be
form
atted
to po
int
to the
Req
uestP
roce
ssor
servl
et (i.e
. hav
e a *.
scr
exten
sion)
.!
Links
can r
eque
st a n
ew co
ntroll
er w
ith th
e �co
ntroll
er�
para
meter
"<a
href=
�pro
file.sc
r?co
ntroll
er=a
ccou
nt�>U
pdate
Pro
file</
a>
!JS
Ps sh
ould
focus
on bu
ilding
the U
I.!
JSPs
are n
ot re
spon
sible
for pr
oces
sing u
ser in
put.
This
is the
resp
onsib
ility o
f the c
ontro
ller.
!JS
Ps ca
n acc
ess t
he co
ntroll
er an
d coo
rdina
tor th
roug
h the
Http
Servl
etSes
sion o
bject.
!Al
l hyp
erlin
ks in
web
page
s sho
uld be
form
atted
to po
int
to the
Req
uestP
roce
ssor
servl
et (i.e
. hav
e a *.
scr
exten
sion)
.!
Links
can r
eque
st a n
ew co
ntroll
er w
ith th
e �co
ntroll
er�
para
meter
"<a
href=
�pro
file.sc
r?co
ntroll
er=a
ccou
nt�>U
pdate
Pro
file</
a>
Sam
ple J
SPSa
mpl
e JSP
<%@page import="com.rational.cwc.*"%>
<%@page import="com.rational.cwc.unittest.*"%>
<jsp:useBean
class="com.rational.cwc.Coordinator" id="coordinator" scope="session"/>
<%
IWebController currentController
= coordinator.getActiveController();
String
ctrlName
=currentController.getName();
if( !ctrlName.equals("Login") ) {
throw new
UnknownControllerException("Unknown controller...", ctrlName);
} LoginWebControllercontroller = (LoginWebController)
currentController;
String message = controller.getMessage();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Login Page</TITLE></HEAD>
<BODY>
<h2>Login Screen</h2>
<p>Message: <em><%=message%></em></p>
<form name="login" action="login.scr" method="post">
<p>Username: <input name="username" type="text" size=20></p>
<p>Password: <input name="password" type="password" size=20></p>
<p><input name="submitLogin" type="submit" value="Login">
</form>
...
</BODY>
</HTML>
The C
ontro
ller
The C
ontro
ller
!Co
ntroll
ers i
n this
mec
hanis
m ar
e all s
tate b
ased
. Eac
h co
ntroll
er is
expe
cted t
o main
tain i
ts ow
n stat
e mac
hine.
!A
contr
oller
mus
t:"
Acce
pt an
HTT
PSer
vletR
eque
st ob
ject to
proc
ess.
"Re
turn a
n IPa
geDi
spatc
her o
bject
that is
used
to tr
igger
the
build
ing of
the o
utput
page
(usu
ally f
orwa
rds t
o a JS
P or
se
rvlet)
.!
Contr
oller
s mus
t gra
ceful
ly ha
ndle
the fo
llowi
ng us
er
even
ts:"
Refre
sh bu
tton
"Ba
ck/F
orwa
rd bu
tton
"Bo
okma
rks"
Conc
urre
nt br
owse
r wind
ows.
!Co
ntroll
ers i
n this
mec
hanis
m ar
e all s
tate b
ased
. Eac
h co
ntroll
er is
expe
cted t
o main
tain i
ts ow
n stat
e mac
hine.
!A
contr
oller
mus
t:"
Acce
pt an
HTT
PSer
vletR
eque
st ob
ject to
proc
ess.
"Re
turn a
n IPa
geDi
spatc
her o
bject
that is
used
to tr
igger
the
build
ing of
the o
utput
page
(usu
ally f
orwa
rds t
o a JS
P or
se
rvlet)
.!
Contr
oller
s mus
t gra
ceful
ly ha
ndle
the fo
llowi
ng us
er
even
ts:"
Refre
sh bu
tton
"Ba
ck/F
orwa
rd bu
tton
"Bo
okma
rks"
Conc
urre
nt br
owse
r wind
ows.
Exam
ple:
Log
in C
ontro
ller
Exam
ple:
Log
in C
ontro
ller
!A
contr
oller
to m
anag
e the
login
of a
web u
ser.
!If t
he us
er ha
s an
outst
andin
g bala
nce
requ
est p
ayme
nt be
fore
allow
ing th
em to
get to
us
er st
atus s
creen
.
!A
contr
oller
to m
anag
e the
login
of a
web u
ser.
!If t
he us
er ha
s an
outst
andin
g bala
nce
requ
est p
ayme
nt be
fore
allow
ing th
em to
get to
us
er st
atus s
creen
.
Log
inW
eb
Co
ntr
olle
r
# c
urre
ntS
tate
: in
t =
ST
_IN
IT#
req
uest
edU
RL
: S
trin
g =
nul
l#
ST
_IN
IT :
int
= 0
# m
essa
ge :
Str
ing
= n
ull
# b
alan
ce :
dou
ble
= 0
.0#
car
dHol
der
: S
trin
g =
nul
l#
car
dTyp
e :
Str
ing
= n
ull
# c
ardN
umbe
r :
Str
ing
= n
ull
# c
ardE
xpir
atio
n :
Str
ing
= n
ull
# u
sern
ame
: S
trin
g =
nul
l#
des
crip
tion
: S
trin
g =
""
# S
T_L
OG
IN :
int
= 1
# S
T_P
AYM
ENT
_REQ
UIR
ED :
int
= 2
# S
T_A
CC
EPT
_PA
YMEN
T :
int
= 3
# S
T_U
SER
_ST
AT
US
: in
t =
4#
ST
_LO
GO
UT
: in
t =
5#
pas
swor
d :
Str
ing
= n
ull
# n
ame
: S
trin
g =
""
+ c
ompl
eted
(
)+
get
Excl
usiv
e (
)+
nex
tScr
een
( )
+ r
eset
(
)+
pro
cess
(
)+
get
Nam
e (
)+
get
Des
crip
tion
( )
+ g
etM
essa
ge (
)
+ g
etBa
lanc
e (
)+
get
Car
dHol
der
( )
+ g
etC
ardT
ype
( )
+ g
etC
ardN
umbe
r (
)+
get
Car
dExp
irat
ion
( )
- ev
entL
ogin
(
)-
even
tPay
(
)-
even
tPay
Now
(
)-
even
tLog
out
( )
+ s
etN
ame
( )
+ s
etD
escr
iptio
n (
)+
set
Excl
usiv
e (
)+
get
Use
rnam
e (
)+
get
Pass
wor
d (
)
«Jav
aInt
erfa
ce»
IWeb
Cont
rolle
r
+ ne
xtSc
reen
(
)+
com
plet
ed (
)
+ pr
oces
s (
)+
rese
t (
)+
getE
xclu
sive
(
)+
setE
xclu
sive
( )
+ ge
tNam
e (
)+
getD
escr
iptio
n (
)+
setN
ame
( )
+ se
tDes
crip
tion
( )
Logi
n Co
ntro
ller:
UX M
odel
Over
view
Logi
n Co
ntro
ller:
UX M
odel
Over
view
Log
in
Ba
lan
ce
Sta
tus
Pa
ym
en
t
Log
ou
t
Log
in F
orm
Pa
ym
en
t Fo
rm
logi
n w
ith o
utst
andi
ng b
alan
ce
logi
n no
bal
ance
pay
paym
ent a
ccep
ted
inva
lid lo
gin
inva
lid in
fo
Logi
n Co
ntro
ller:
UX M
odel
NavM
ap D
etail
sLo
gin
Cont
rolle
r: UX
Mod
el Na
vMap
Det
ails
«scr
een»
Log
in
+ m
essa
ge
«scr
een»
Bala
nce
+ m
essa
ge+
bal
ance
«scr
een»
Sta
tus
+ m
essa
ge
«scr
een»
Pa
ym
en
t
+ m
essa
ge
«scr
een»
Log
ou
t«i
nput
for
m»
Log
in F
orm
+ U
sern
ame
: T
ext
+ P
assw
ord
: Pa
ssw
ord
+ L
ogin
: S
ubm
it
«inp
ut f
orm
»P
ay
me
nt
Form
+ C
ardH
olde
r :
Tex
t+
Car
dNum
ber
: T
ext
+ C
ardT
ype
: S
elec
t+
Car
dExp
irat
ion
: T
ext
+ P
ay :
Sub
mit
pay
logi
n no
bal
ance
inva
lid in
fo
logi
n w
ith o
utst
andi
ng b
alan
ce
paym
ent a
ccep
ted
inva
lid lo
gin
Logi
n Co
ntro
ller:
UX B
asic
Flow
Sto
rybo
ard
Logi
n Co
ntro
ller:
UX B
asic
Flow
Sto
rybo
ard
: L
ogin
user
: S
tatu
s :
Log
out
The
use
r na
viga
tes
to t
he lo
gin
scre
en.
The
use
r su
pplie
s a
user
nam
e an
d pa
ssw
ord.
The
n lo
gins
.
If t
he u
sern
ame/
pass
wor
d is
inva
lid
the
logi
n sc
reen
is r
etur
ned
with
a
notif
icat
ion
mes
sage
. T
he u
ser
can
re-e
nter
a v
alid
com
bina
tion.
With
a v
alid
use
rnam
e/pa
ssw
ord
com
bina
tion
(and
no
outs
tand
ing
bala
nce
for
the
user
's a
ccou
nt,
the
syst
em n
avig
ates
to
the
user
sta
tus
page
.
The
use
r lo
gout
s of
the
sys
tem
. T
he
syst
em r
etur
ns a
fin
al lo
gout
scr
een,
co
nfir
min
g a
suce
ssfu
l log
out.
1 :
\nav
igat
e\
2 :
\ent
er u
ser
info
\
6 :
\nav
igat
e\
5 :
\log
in\
7 :
\log
out\
3 :
\log
in\
4 :
\nav
igat
e\
8 :
\nav
igat
e\
Logi
n Co
ntro
ller:
UX P
aym
ent S
tory
boar
dLo
gin
Cont
rolle
r: UX
Pay
men
t Sto
rybo
ard
The
use
r na
viga
tes
to t
he lo
gin
scre
en.
The
use
r su
pplie
s a
user
nam
e an
d pa
ssw
ord.
The
n lo
gins
.
: L
ogin
user
The
use
r ha
s an
out
stan
ding
bal
ance
. T
he s
yste
m n
otifi
es t
he u
ser
and
offe
rs a
n op
pert
unity
to
mak
e th
e pa
ymen
t no
w,
or t
o lo
gout
.
: B
alan
ce
The
use
r op
ts t
o pa
y no
w.
: P
aym
ent
The
use
r en
ters
new
pay
men
t in
form
atio
n.
If t
he in
form
atio
n is
inva
lid,
the
syst
em r
etur
ns t
he p
aym
ent
scre
en
and
disp
lays
a m
essa
ge in
dica
ting
the
info
rmat
ion
was
not
acc
epte
d.
The
use
r en
ters
new
info
rmat
ion.
The
use
r en
ters
val
id p
aym
ent
info
rmat
ion.
T
he s
yste
m r
etur
ns
with
the
use
r st
atus
scr
een.
: S
tatu
s
1 :
\nav
igat
e\
2 :
\ent
er u
ser
info
\
3 :
\log
in\
4 :
\nav
igat
e\
5 :
\pay
now
\
7 :
\ent
er p
aym
ent
info
\
6 :
\nav
igat
e\
8 :
\nav
igat
e\
9 :
\ent
er v
alid
pay
men
t in
fo\
10 :
\na
viga
te\
Logi
n Co
ntro
ller:
JSPs
Logi
n Co
ntro
ller:
JSPs
«Ser
verP
age»
sta
tus.
jsp
«Clie
ntPa
ge»
sta
tus.
jsp
_C
lien
t1
Co
ord
ina
tor
+ g
etA
ctiv
eCon
trol
lers
(
)+
get
Act
iveC
ontr
olle
r (
)+
add
Con
trol
ler
( )
+ r
emov
eCon
trol
ler
( )
+ n
umbe
rAct
iveC
ontr
olle
rs (
)
+ p
roce
ssR
eque
st (
)
«Ser
verP
age»
ba
lan
ce.j
sp
«Ser
verP
age»
log
in.j
sp
«Clie
ntPa
ge»
log
ou
t.h
tml
«Ser
verP
age»
pa
ym
en
t.js
p
«Clie
ntPa
ge»
log
in.j
sp_
Clie
nt1
«Clie
ntPa
ge»
pa
ym
en
t.js
p_
Clie
nt1
«Clie
ntPa
ge»
ba
lan
ce.j
sp_
Clie
nt1
«Bui
ld»
«JS
PUse
Bean
»
+ c
oord
inat
or
«JS
PUse
Bean
»
+ c
oord
inat
or
«JS
PUse
Bean
»
+ c
oord
inat
or
«JS
PUse
Bean
»
+ c
oord
inat
or
«Bui
ld»
«Bui
ld»
«Bui
ld»
Logi
n Co
ntro
ller:
Stat
emac
hine
Logi
n Co
ntro
ller:
Stat
emac
hine
logi
n
paym
ent
requ
ired
acce
pt p
aym
ent
user
sta
tus
Logo
ut
[bal
ance
<0]
logi
n
payn
ow
[val
id]
pay
logo
ut
[bal
ance
>=
0]
logi
n
logo
ut
[inv
alid
]pa
y
[aut
hent
icat
ion
faile
d]lo
gin
logo
ut
Logi
n Co
ntro
ller:
Stat
emac
hine
/ UX
map
ping
Logi
n Co
ntro
ller:
Stat
emac
hine
/ UX
map
ping
logi
n
paym
ent
requ
ired
acce
pt p
aym
ent
user
sta
tus
Logo
ut
«Ser
verP
age»
log
in.j
sp
«Ser
verP
age»
sta
tus.
jsp
«Clie
ntPa
ge»
log
ou
t.h
tml
«Ser
verP
age»
pa
ym
en
t.js
p
«Ser
verP
age»
ba
lan
ce.j
sp[b
alan
ce<
0]
[val
id]
[bal
ance
>=
0]
[inv
alid
]
[aut
hent
icat
ion
faile
d]
logo
ut
logo
ut
logo
ut
Logi
n Co
ntro
ller:
Impl
emen
tatio
nLo
gin
Cont
rolle
r: Im
plem
enta
tion
!Ea
ch st
ate in
the
statem
achin
e defi
nes a
n int
erna
l enu
mera
tion.
!Ea
ch st
ate in
the
statem
achin
e defi
nes a
n int
erna
l enu
mera
tion.
protected static final
int
ST_INIT = 0;
protected static final
int
ST_LOGIN = 1;
protected static final
int
ST_PAYMENT_REQUIRED = 2;
protected static final
int
ST_ACCEPT_PAYMENT = 3;
protected static final
int
ST_USER_STATUS = 4;
protected static final
int
ST_LOGOUT = 5;
logi
n
paym
ent
requ
ired
acce
pt p
aym
ent
user
sta
tus
Logo
ut
[bal
ance
<0]
logi
n
payn
ow
[val
id]
pay
logo
ut
[bal
ance
>=
0]
logi
n
logo
ut
[inv
alid
]pa
y
[aut
hent
icat
ion
faile
d]lo
gin
logo
ut
Logi
n Co
ntro
ller:
Impl
emen
tatio
nLo
gin
Cont
rolle
r: Im
plem
enta
tion
!Of
cour
se ea
ch co
ntroll
er w
ill de
fine m
embe
r attr
ibutes
ap
prop
riate
for its
uniqu
e role
.!
Of co
urse
each
contr
oller
will
defin
e mem
ber a
ttribu
tes
appr
opria
te for
its un
ique r
ole.
protected
int currentState
= ST_INIT;
protected String
requestedURL= null;
protected String message = null;
protected double balance = 0.0;
protected String
cardHolder
= null;
protected String
cardType
= null;
protected String
cardNumber
= null;
protected String
cardExpiration
= null;
protected String username = null;
protected String password = null;
protected String name = "";
protected String description = "";
Logi
n Co
ntro
ller:
Impl
emen
tatio
nLo
gin
Cont
rolle
r: Im
plem
enta
tion
!Th
e con
trolle
r pro
vides
gette
r, se
tters
and s
imple
im
pleme
ntatio
ns fo
r impo
rtant
oper
ation
s.!
The c
ontro
ller p
rovid
es ge
tter,
sette
rs an
d sim
ple
imple
menta
tions
for im
porta
nt op
erati
ons.
public booleancompleted(){
return (currentState== ST_LOGOUT);
} public boolean getExclusive(){
return false;
} public void
setExclusive(boolean
exclusive){
// ignore this since this will never be exclusive
} public StringgetBalance(){
// return the balance as a locally formatted currency string.
return NumberFormat.getCurrencyInstance().format(balance);
}
Logi
n Co
ntro
ller:
Impl
emen
tatio
nLo
gin
Cont
rolle
r: Im
plem
enta
tion
public void process(HttpServletRequest req){
message = "";
String event = req.getServletPath();
switch(currentState){
case ST_INIT: // no processing required, only possible next state is login
currentState= ST_LOGIN;
break;
case ST_LOGIN: // only accepted event is login
eventLogin(req);
break;
case ST_PAYMENT_REQUIRED: // user can either pay now, or logout
if( event.equals("/paynow.scr") ) {
eventPayNow(req);
} else if( event.equals("/logout.scr") ) {
eventLogout(req);
} break;
case ST_ACCEPT_PAYMENT:
if( event.equals("/logout.scr") ) { // user is aborting
currentState
= ST_LOGOUT;
} if( event.equals("/enterpayment.scr") ) {
eventPay(req);
} break;
case ST_USER_STATUS:
if( event.equals("/logout.scr") ) {
eventLogout(req);
} break;
case ST_LOGOUT: // this is a final state -
nothing to do
break;
}
public void process(HttpServletRequest req){
message = "";
String event = req.getServletPath();
switch(currentState){
case ST_INIT: // no processing required, only possible next state is login
currentState= ST_LOGIN;
break;
case ST_LOGIN: // only accepted event is login
eventLogin(req);
break;
case ST_PAYMENT_REQUIRED: // user can either pay now, or logout
if( event.equals("/paynow.scr") ) {
eventPayNow(req);
} else if( event.equals("/logout.scr") ) {
eventLogout(req);
} break;
case ST_ACCEPT_PAYMENT:
if( event.equals("/logout.scr") ) { // user is aborting
currentState
= ST_LOGOUT;
} if( event.equals("/enterpayment.scr") ) {
eventPay(req);
} break;
case ST_USER_STATUS:
if( event.equals("/logout.scr") ) {
eventLogout(req);
} break;
case ST_LOGOUT: // this is a final state -
nothing to do
break;
}
Logi
n Co
ntro
ller:
Impl
emen
tatio
nLo
gin
Cont
rolle
r: Im
plem
enta
tion
private voideventLogin(HttpServletRequest req){
// For authorization this implementation just checks for non-empty fields
// The user balance is based entered username -
just to keep this unit test
// simple. Normally there would be calls to session beans, etc.
username = req.getParameter("username"); // set controller state
password = req.getParameter("password");
if( username == null || password == null ||
username.equals("") || password.equals("") ) {
message = "Please enter a value for both fields.";
currentState
= ST_LOGIN;
} else {
//if username begins with a capital letter then has balance
char
ch= username.charAt(0);
if(
ch
>= 'a' ) {
balance = 0;
currentState
= ST_USER_STATUS;
} else {
balance = 120.00;
currentState
= ST_PAYMENT_REQUIRED;
}}
}
Logi
n Co
ntro
ller:
Impl
emen
tatio
nLo
gin
Cont
rolle
r: Im
plem
enta
tion
public IPageDispatcher nextScreen(){
IPageDispatcher
screen;
// this is where the mapping between internal states of the controller
// are mapped to screens. In this example the mapping is 1:1 -
very
// simple. So simple in fact that I could have implemented this with
// a
HashMap, however using a switch statement helps to emphasize that 1:1
// mappings are not necessarily the only ones possible.
switch(
currentState){
case ST_LOGIN:
screen = new
PageDispatcher("unit-test/login.jsp");
break;
case ST_PAYMENT_REQUIRED:
screen = new
PageDispatcher("unit-test/balance.jsp");
break;
case ST_ACCEPT_PAYMENT:
screen = new
PageDispatcher("unit-test/payment.jsp");
break;
case ST_USER_STATUS:
screen = new
PageDispatcher("unit-test/status.jsp");
break;
case ST_LOGOUT:
// not all pages need be
jsps
screen = new
PageDispatcher("unit-test/logout.html");
break;
} return screen;
}
The R
ight
Sol
utio
n?Th
e Rig
ht S
olut
ion?
!W
e�ve r
eview
ed th
is as
set�s
"Do
cume
ntatio
n"
Mode
ls (D
esign
, UX)
"Co
de"
Exam
ples/U
nit T
est
!Th
e dec
ision
can b
e mad
e whe
ther o
r not
to us
e this
as
set.
If it c
an w
e nee
d to u
nder
stand
how
it will
be
incor
pora
ted in
to ou
r par
ticula
r pro
ject.
!W
e�ve r
eview
ed th
is as
set�s
"Do
cume
ntatio
n"
Mode
ls (D
esign
, UX)
"Co
de"
Exam
ples/U
nit T
est
!Th
e dec
ision
can b
e mad
e whe
ther o
r not
to us
e this
as
set.
If it c
an w
e nee
d to u
nder
stand
how
it will
be
incor
pora
ted in
to ou
r par
ticula
r pro
ject.
Usin
g th
e Ass
etUs
ing
the A
sset
!Inc
orpo
rate
the as
set�s
core
clas
ses
"Al
l java
code
sans
unit t
est s
pecif
ic cla
sses
.!
Upda
te ou
r cod
e or t
he as
set c
ode t
o use
the s
ame s
uppo
rt co
mpon
ents
for X
ML pa
rsing
(Xer
ces2
.0.2)
.!
Docu
ment
how
to us
e patt
ern a
utoma
tion i
n the
deve
lopme
nt pr
oces
s."
The C
WC
asse
t com
es w
ith an
XDE
patte
rn as
set th
at pr
ovide
s au
tomati
on fo
r the
crea
tion o
f IWeb
Contr
oller
clas
ses.
This
autom
ation
ini
tializ
es th
e con
trolle
r�s in
terfa
ce an
d cre
ates c
ase s
tatem
ents
in ke
y op
erati
ons b
ased
on its
mod
eled s
tatem
achin
e.!
Docu
ment
how
to sp
ecify
and c
ode J
SPs t
o use
contr
oller
s for
all
acce
ss to
midd
le tie
r com
pone
nts.
!En
sure
all H
TML h
yper
links
and f
orm
subm
ission
s are
enco
ded
to go
thro
ugh t
he R
eque
stPro
cess
or se
rvlet.
!Inc
orpo
rate
the as
set�s
core
clas
ses
"Al
l java
code
sans
unit t
est s
pecif
ic cla
sses
.!
Upda
te ou
r cod
e or t
he as
set c
ode t
o use
the s
ame s
uppo
rt co
mpon
ents
for X
ML pa
rsing
(Xer
ces2
.0.2)
.!
Docu
ment
how
to us
e patt
ern a
utoma
tion i
n the
deve
lopme
nt pr
oces
s."
The C
WC
asse
t com
es w
ith an
XDE
patte
rn as
set th
at pr
ovide
s au
tomati
on fo
r the
crea
tion o
f IWeb
Contr
oller
clas
ses.
This
autom
ation
ini
tializ
es th
e con
trolle
r�s in
terfa
ce an
d cre
ates c
ase s
tatem
ents
in ke
y op
erati
ons b
ased
on its
mod
eled s
tatem
achin
e.!
Docu
ment
how
to sp
ecify
and c
ode J
SPs t
o use
contr
oller
s for
all
acce
ss to
midd
le tie
r com
pone
nts.
!En
sure
all H
TML h
yper
links
and f
orm
subm
ission
s are
enco
ded
to go
thro
ugh t
he R
eque
stPro
cess
or se
rvlet.
Dem
onst
ratio
nDe
mon
stra
tion
!Ru
nning
unit t
ests
for"
Login
Con
trolle
r"
Simp
le Co
ntroll
er1 a
nd C
ontro
ller2
�Ex
amine
contr
oller
stac
k beh
avior
�Ex
amine
contr
oller
s with
exclu
sive c
ontro
l
!Us
ing W
eb C
ontro
ller p
atter
n ass
et to
autom
ate th
e cre
ation
of an
IWeb
Contr
oller
clas
s.
!Ru
nning
unit t
ests
for"
Login
Con
trolle
r"
Simp
le Co
ntroll
er1 a
nd C
ontro
ller2
�Ex
amine
contr
oller
stac
k beh
avior
�Ex
amine
contr
oller
s with
exclu
sive c
ontro
l
!Us
ing W
eb C
ontro
ller p
atter
n ass
et to
autom
ate th
e cre
ation
of an
IWeb
Contr
oller
clas
s.
Sum
mar
ySu
mm
ary
!As
sets
can p
rovid
e sop
histic
ated s
olutio
ns to
comm
on
prob
lems.
!St
anda
rdiza
tion o
f ass
et pa
ckag
ing w
ill en
able
grea
ter
use o
f ass
ets.
!Th
e CW
C as
set e
xpan
ds on
the J
2EE
Fron
t Con
trolle
r Pa
ttern
and p
rovid
es a
mech
anism
to cl
eanly
man
age
simult
aneo
us w
eb co
ntroll
ers.
!As
sets
can p
rovid
e sop
histic
ated s
olutio
ns to
comm
on
prob
lems.
!St
anda
rdiza
tion o
f ass
et pa
ckag
ing w
ill en
able
grea
ter
use o
f ass
ets.
!Th
e CW
C as
set e
xpan
ds on
the J
2EE
Fron
t Con
trolle
r Pa
ttern
and p
rovid
es a
mech
anism
to cl
eanly
man
age
simult
aneo
us w
eb co
ntroll
ers.