A%%lication State
A%%lication 4ules
Persistent data
A%%lication State
(!e data &odel re%resents t!e 7noun7 o'6ects needed '" t!e a%%lication and<or its
users, suc! as:
%eo%le 0facult", staff, students, custo&ers, +isitors, a%%lication ad&inistrators1
widgets needed '" a%%lication users 0s!o%%ing carts, transcri%ts, contact infor&ation,
&erc!andise1
(!e data &odel defines t!ese o'6ects a'stractl")
(!e instances of t!e data o'6ects currentl" in-%la", and t!e +alue of t!ose o'6ects,
constitutes t!e 7a%%lication state)7
A%%lication 4ules
A%%lication rules are t!e 'usiness logic of t!e a%%lication)
-3a&%les of 'usiness logic are:
View (ec!ologies
(e&%lating
St"ling
Controller (ec!nologies
4es%onsi'ilities of t!e Controller
(!e Controller will do t!e following:
Parse a user re?uest 0i)e), 7read7 it1
Validate t!e user re?uest 0i)e), assure it
confor&s to a%%lication$s re?uire&ents1
Deter&ine w!at t!e user is tr"ing to do
0'ased on .4>, re?uest %ara&eters,
and<or for& ele&ents1
5'tain data fro& t!e Model 0if
necessar"1 to include in res%onse to user
Select t!e ne3t View t!e client s!ould
see
(!e se?uencing of calls to t!e Model
0'usiness-logic la"er1, and<or t!e se?uencing
of +iews and re?uired in%ut fro& t!e user
defines t!e a%%lication$s wor*flow) or*flow
is t!us defined in t!e Controller la"er of t!e
a%%lication)
(!e Controller la"er is, essentiall", a traffic co%)))
Controller (ec!nologies
(!ere are nu&erous a%%lication fra&ewor*s t!at can 'e used to
%ro+ied t!e control la"er in an MVC-arc!itected a%%lication)
(!ese include:
Struts
e'or*
S%ring
!ic! of t!ese 0or ot!ers1 is &ost a%%ro%riate to an a%%lication is
a ?uestion to discuss wit! an e3%erienced a%%lication arc!itect)
De%lo"&ent Descri%tors:
9unction
Additional -3ternali:ation
!at De%lo"&ent Descri%tors Do
A 7De%lo"&ent Descri%tor7 is a configuration file) It is not code, and it is ne+er
co&%iled)
De%lo"&ent Descri%tors are used to configure an a%%lication as it starts u% in its
container 0i)e), in its a%%lication ser+er1) Configuring an a%%lication includes wiring
its co&%onents toget!er: declaring w!at res%onses corres%ond to w!ic! re?uests)
In t!e J2-- en+iron&ent, t!e &ot!er of all de%lo"&ent descri%tors is t!e file
we')3&l) (!e contents of t!is file are s%ecified in t!e Ja+a Ser+let s%ecificationA
de%ending on t!e +ersion of t!e s%ecification t!e file &ust confor& to a %articular
D(D or ESD:
D(D for Ser+let S%ec 2)H we')3&l
ESD for Ser+let S%ec 2)4 we')3&l
De%lo"&ent Descri%tors are
Declarati+e
De%lo"&ent Descri%tors are 7declarati+e7 and are utili:ed in t!e conte3t of J2--$s
declarati+e %rogra&&ing &odel) !at t!at 'oils down to is t!at:
Man" of t!e i&%ortant attri'utes of J2-- classes are not !ard-coded
De%lo"&ent Descri%tors are read w!en t!e co&%onents are started 0de%lo"ed1, and
used to configure de%lo"ed &odules and classes
(!is &eans one can declare 0+ia t!e De%lo"&ent Descri%tor1 w!at suc! attri'utes
oug!t to 'e wit!out c!anging or reco&%iling an" code)
(!e attri'utes in ?uestion are ones t!at s%ecif" a%%lication co&%onents, wor*flow,
securit", etc)
(!ere$s not!ing &agical a'out t!is in t!e J2-- fra&ewor*) !at$s i&%ortant is t!at &an"
of t!e attri'utes t!at &ig!t !a+e 'een !ard-coded in older fra&ewor*s are, in J2--,
7e3ternali:ed)7 -3ternali:ation allows a%%lications to 'e &ore &odular)
Additional -3ternali:ation
Additional e3ternali:ation is 'uilt on t!e %attern esta'lis!ed
wit! we')3&l) Additional functionalit" declared outside outside
t!e a%%lication code'ase &ig!t include:
I %age flow - defined '" we' a%%lication fra&ewor*s suc! as
Struts
I %age decoration 0s*ins1 - are defined '" we' %age la"out
and decoration fra&ewor*s suc! as SiteMes!
/enefits of De%lo"&ent
Descri%tors 021
(!e c!ief ad+antage of e3ternali:ing configuration +ia De%lo"&ent Descri%tors is t!at t!e
'inding 'etween different &odules or la"ers is 7looser7A t!at is, c!anges can 'e
i&%le&ented wit!out rewriting or reco&%iling code)
De%lo"&ent Descri%tors can 'e used in J2-- a%%lications to s%ecif":
!ic! %ersistent data stores are to 'e used 0e)g), w!ic! data'ase on w!ic! !ost1
!ic! securit" fra&ewor* s!ould 'e used
!at securit" s!ould a%%l" to eac! %art of t!e a%%lication 0i)e), w!ic! user-roles
are aut!ori:ed to do w!at actions or see w!at %ages1
!ic! class s!ould !andle eac! user-re?uested .4>
!at t!e a%%lication wor*flow s!ould 'e
!ic! View %age s!ould 'e used to res%ond to eac! user re?uest, and !ow
a%%lication state 0+alues of data in t!e Model1 s!ould 'e ta*en into account in t!is
deter&ination
!ic! 7s*in7 s!ould 'e used to decorate eac! View %age %resented to t!e user
/enefits of De%lo"&ent
Descri%tors 021
9or e3a&%le, de%lo"&ent descri%tor ele&ents defining t!e Controller la"er of an
a%%lication &a% user-re?uested .4>s to t!e classes t!at will fulfill t!e re?uests) (!e
&a%%ing defines t!e a%%lication$s wor*flow) /ecause t!e &a%%ing is declared in a
De%lo"&ent Descri%tor, t!e wor*flow can 'e c!anged wit!out altering code, as in t!is
e3a&%le:
Workflow Changes for Secure Encryption Software On-line Purchase: t!e order in
w!ic! a user is %resented %ages can 'e e3ternali:ed in t!e De%lo"&ent Descri%tor
-3a&%le De%lo"&ent Descri%tor:
(!e ne3t slides s!ow an e3a&%le of a struts-config)3&l file, fro& t!e Stree* client
a%%lication /ear9acts) it!out getting into too &an" details, t!ese are t!e ste%s t!at
connect a user$s re?uest wit! t!e se?uence of actions descri'ed '" t!is de%lo"&ent
descri%tor:
At a%%lication startu%, Struts ActionSer+let is initiali:ed wit! data in struts-config)3&l
we')3&l de%lo"&ent descri%tor &a%s all .4> re?uests of t!is for& to a Struts
ActionSer+let 0w!ose class is also s%ecified in we')3&l1
.ser re?uests .4>, of t!e for& !tt%:<<Jconte3t-rootK<student<do<I
(!e action %at! is t!e %art of t!e .4> t!at follows 7student<do7
De%ending on t!e action-%at! %art of t!e re?uested .4>:
An 7Action Class7 s%ecific to t!e t"%e of o%eration re?uested is identified 0t!e
7t"%e7 attri'ute of BactionC1
(!e s%ecified 7Action Class7 calls a%%ro%riate Model classes to %erfor&s 'usiness
logic, %rocessing data 0e)g), for& data1 in t!e user$s re?uest
(!e View t!at t!e user will see ne3t is selected 'ased on w!ic! forward na&e
07na&e7 attri'ute of t!e BforwardC ele&ent1 is set as a result of %rocessing %erfor&ed
'" t!e Model class0es1
struts-config)3&l 02 of 21
B#3&l +ersionL72)07 encodingL7IS5-MMNO-27#C
BPD5C(QP- struts-config P./>IC 7-<<A%ac!e Software 9oundation<<D(D Struts Configuration 2)2<<-D7
7!tt%:<<6a*arta)a%ac!e)org<struts<dtds<struts-configR2R2)dtd7C
Bstruts-configC
Bglo'al-forwardsC
Bforward na&eL7s"ste&Message7 %at!L7<s"ste&Message)6s%7<C
B<glo'al-forwardsC
Baction-&a%%ingsC
Baction %at!L7<studentMain7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)StudentMainAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7welco&e7 %at!L7<student<welco&e)6s%7<C
Bforward na&eL7logout7 %at!L7<login<logout)6s%7 redirectL7true7<C
B<actionC
Baction %at!L7<studentContact7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)StudentContactAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7dis%la"Profile7 %at!L7<student<%ersonal<dis%la"Profile)6s%7<C
Bforward na&eL7dis%la"Contacts7 %at!L7<student<%ersonal<dis%la"Contact)6s%7<C
Bforward na&eL7u%dateContact7 %at!L7<student<%ersonal<u%dateContact)6s%7<C
Bforward na&eL7confir&Contact.%date7 %at!L7<student<%ersonal<confir&Contact.%date)6s%7<C
B<actionC
Baction %at!L7<registration7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)Student4egistrationAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7classSc!edules7 %at!L7<student<registration<classSc!edules)6s%7<C
Bforward na&eL7reg9eeSu&&ar"7 %at!L7<student<registration<reg9eeSu&&ar")6s%7<C
Bforward na&eL7su&&er4eg9ee7 %at!L7<student<registration<su&4eg9ee)6s%7<C
Bforward na&eL7registration/loc*s7 %at!L7<student<registration<registration/loc*s)6s%7<C
Bforward na&eL7final-3a&Sc!edule7 %at!L7<student<registration<final-3a&Sc!edule)6s%7<C
Bforward na&eL7tele'earsA%%oint&ent7 %at!L7<student<registration<tele'earsA%%oint&ent)6s%7<C
B<actionC
S)))T
struts-config)3&l 02 of 21
S)))T
Baction %at!L7<acade&ic4ecord7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)StudentAcade&ic4ecordAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7current(er&8rades7 %at!L7<student<acade&ic<studentCurrent8rades)6s%7<C
Bforward na&eL7%rior(er&8rades7 %at!L7<student<acade&ic<studentPrior8rades)6s%7<C
B<actionC
Baction %at!L7<financialAid7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)Student9inancialAidAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7offer>etter7 %at!L7<student<fin-aid<fin-aid-offer)!t&l7<C
Bforward na&eL7financialAidStatus7 %at!L7<student<fin-aid<finaidStatus)6s%7<C
Bforward na&eL7financialAidAwardSu&&ar"7 %at!L7<student<fin-aid<finaidAwardSu&&ar")6s%7<C
Bforward na&eL7&issingDocu&ents7 %at!L7<student<fin-aid<finaidMissingDocs)6s%7<C
B<actionC
Baction %at!L7<CA4S7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)StudentCA4SAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7classSc!edules7 %at!L7<student<%ersonal<classSc!edules)6s%7<C
Bforward na&eL7refundSu&&ar"7 %at!L7<student<cars<refundSu&&ar")6s%7<C
Bforward na&eL7awardsSu&&ar"7 %at!L7<student<cars<awardsSu&&ar")6s%7<C
Bforward na&eL7%a"&entSu&&ar"7 %at!L7<student<cars<%a"&entSu&&ar")6s%7<C
Bforward na&eL7?uic*State&ent7 %at!L7<student<cars<?uic*State&ent)6s%7<C
B<actionC
Baction %at!L7<loans7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)Student>oansAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7direct>oan7 %at!L7<student<loans<direct>oan)6s%7<C
B<actionC
B<action-&a%%ingsC
B<struts-configC
Sa&%le A%%lication
4e?uire&ents