Using Aspec -o ien a ion Techniques o
Imp o e Reuse o Me amodels
A. M. Reina Quin e o J. To es Valde ama
Depa men o Languages and Compu e Sys ems
Uni e si y o Se ille
Se ille, Spain
Abs ac
Me amodelling is an ac i i y ha a ac s a en ion o he esea ch communi y dealing wi h he Model-
D i en De elopmen (MDD). To be eusable in diffe en MDD app oaches a me amodel should be unawa e
o being ex ended by ano he me amodel. This p ope y o me amodel is called obli iousness. This pape
shows ha cu en echniques implemen ing me amodels do no main ain obli iousness when some elemen s
o he ex ended me amodel and he elemen s o he o iginal model ha e associa ion ela ions. Th ee diffe en
app oaches o euse o me amodels a e analyzed. One o he app oaches uses adi ional objec -o ien ed
echniques. Two o he app oaches use aspec -o ien ed echniques. The pape shows ha he hi d app oach,
which conside s ela ionships as fi s -class ci izens a he implemen a ion le el by using ela ionship aspec s,
gua an ees obli iousness o me amodels.
Keywo ds: Me amodelling, Aspec -O ien ed P og amming, Model-D i en A chi ec u e.
1 In oduc ion
Model D i en De elopmen (MDD) is suppo ed by wo main app oaches: So -
wa e Fac o ies (SF) [11] p omo ed by Mic oso and Model D i en A chi ec u e
(MDA) [19] p omo ed by he Objec Managemen G oup (OMG) [16,5].
The So wa e Fac o ies app oach p oposes he use o ex ensible and configu able
ools o au oma e he de elopmen and main enance o diffe en so wa e p oduc
amilies. The au oma ion is ob ained by means o he composi ion and configu a ion
o diffe en componen s. Thus, he So wa e Fac o ies app oach in eg a es mul iple
ac i i ies and echniques. One o hese ac i i ies is he de elopmen o a ious
modelling languages and domain specific ools.
This wo k has been pa ially suppo ed by he Spanish Minis e y o Science and Technology and FEDER
unds: TIC-2003-369.
The Model D i en A chi ec u e app oach is based on he modelling s anda ds
p oposed by he OMG: he Unified Modelling Language (UML) [22]and heMe a
Objec Facili y (MOF) [20]. MDA p oposes a amewo k composed o diffe en
le els o modelling: Compu a ion Independen Model (CIM), Pla o m Indepen-
den Model (PIM), and Pla o m Specific Model (PSM) and model ans o ma ions.
Thus, he models and ans o ma ions ha e become he fi s -class ci izens. Figu e 1
shows a MOF diag am o he main elemen s o he MDA app oach.
Model
T ans o ma ion CIM PIM PSM Code Me amodel
1..*
1
con o msTo
sou ce
a ge
1..*
1..*
Fig. 1. Me amodel o he MDA app oach
In addi ion o he CIM, PIM, PSM and ans o ma ion, Figu e 1shows ano he
impo an elemen o MDA: a me amodel. A me amodel is a special kind o model
which desc ibes an abs ac syn ax o ano he model.
So, he me amodel ha e become he key elemen s o bo h MDD app oaches. In
his con ex i is e y p omising o define and implemen me amodels ha can be
eused [2].
Ca alysis me hod [7] in oduces wo mechanisms o me amodel euse: he package
ex ension and he package empla e mechanism [4]. In his pape we ocus on he
package ex ension mechanism. Me amodel MMA ex ends me amodel MMB i MMA spe-
cializes MMB. Thus, any o he elemen s o he MMA me amodel has a ela ionship
wi h any o he elemen s o he MMB me amodel. This mechanism allows defining
he MMA and MMB me amodels sepa a ely, and me ging hem oge he . In o de o
imp o e euse o me amodels i is impo an o main ain he obli iousness, i.e. he
unawa eness o MMB abou MMA.
We ha e analyzed h ee diffe en app oaches o implemen a ion o me amodels
in o de o unde s and i hey main ain he obli iousness o me amodels. The
fi s app oach uses inhe i ance o make he o iginal me amodel obli ious so ha
he p oblem is sol ed wi h adi ional objec -o ien ed echniques. The second and
hi d app oaches a e based on aspec -o ien ed echniques [9,10]. The second ap-
p oach in oduces in e - ype decla a ions, while he hi d one ea s he ela ion-
ships in me amodels as aspec s [23]. In his pape we show ha he hi d app oach
gua an ees obli iousness o me amodels which acili a es me amodel euse.
This pape is s uc u ed as ollows: sec ion 2in oduces he main me amodelling
concep s. In sec ion 3 he Eclipse Modelling F amewo k o implemen ing models
and me amodels is p esen ed. Sec ion 4p esen s he p oblems ha a ise when
me amodels a e ex ended. Sec ion 5analyses h ee diffe en app oaches o ex ension
o me amodels. Sec ion 6 d aws conclusions om he analysis.
2 Me amodelling
Acco ding o[15] a me amodel is a p ecise defini ion o he cons uc s and ules
needed o c ea ing seman ic models. Me amodelling is a way o o ganize ela ed
models. The OMG defines ou diffe en le els o modelling [14]. Figu e 2shows a
scheme o he ela ionships among he le els M0, M1, M2 and M3 defined by he
OMG. The MOF is placed on he op o he hie a chy, and i is used o define i sel ;
he e o e, he le el abo e MOF (M3) can be seen as he MOF i sel . The UML is
a le el M2. The abs ac syn ax o he UML has been desc ibed using he MOF.
An ins ance o he UML me amodel can be seen as a class diag am (le el M1). An
ins an ia ion o a class diag am is an objec diag am (Le el M0).
M1: Sys em Model
M2:(Me a-model)
M0: Sys em
M3: (Me a-me a-model)
+name
MOF Class
-name
UML Class
-name
UML A ibu e
- i le
-name
Cus ome
-name
-numbe
O de
i le = "D "
name = "John Doe"
Obje o1 : Cus ome
i le = "D "
name = "F ank Else"
: Cus ome
name = "Some hing"
numbe = "12345678"
: O de
<<ins ance o >>
<<ins ance o >> <<ins ance o >>
<<ins ance o >>
<<ins ance o >>
<<ins ance o >> <<ins ance o >>
<<ins ance o >> <<ins ance o >>
Fig. 2. The ou laye me amodel a chi ec u e p oposed by he OMG
The me amodel eposi o ies can be classified in wo main g oups:
•The MOF-based ones.TheMOF[20] is he me amodelling amewo k p oposed
by he Objec Managemen G oup (OMG) o define o he modelling amewo ks.
The MOF specifica ion is endo and language independen . Wi h he MOF
specifica ion, he OMG has s anda dized a se o mappings ha speci y how a
specific echnology ep esen s and manages me a-da a. Fo ins ance, XMI [21]is
a XML ep esen a ion o model in e change be ween ools, while JMI [25]isan
abs ac syn ax defini ion o me a-da a in Ja a applica ions. Some eposi o ies
ha implemen he JMI in e ace a e: MDR om Ne Beans [17]o NSMDF[18]
om No oSo . The Co al Me amodelling F amewo k [24] has he ha d coded
MOF, al hough o he diffe en me amodels can be ins alled. Co al is no based
on Ja a, bu on Py hon.
•The Eco e-based ones. Eco e is he me amodel included in he Eclipse Mode-
lling F amewo k (EMF) [3]. I is diffe en om MOF. EMF is a low-cos ool
o ob ain he benefi s o o mal modelling and Ja a code gene a ion and i is
language-dependen . The unc ionali y o EMF is simila o MDR.
3 Eclipse Modelling F amewo k (EMF)
The Eclipse Modelling F amewo k (EMF) [3] is a modelling amewo k o Eclipse.
EMF is, on he one hand, a amewo k, and, on he o he hand, a acili y o
defining a model in one o he ollowing o ms: Ja a in e aces, UML diag ams
o XML Schemas. Eco e is he me amodel ha uses EMF o ep esen models.
Eco e is i sel an Eco e model, and i is o he same OMG le el (Figu e 2)asMOF.
Figu e 3depic s diffe en sou ces o a co e model.
Co e Model
Co e Model
UML Model
XML Schema
O he
Ja a Code
+
Anno a ions
Ja a Code
+
Anno a ions
Fig. 3. Sou ces o a Co e Model
The e a e ou basic me aclasses o ep esen an Eco e model: EClass,EA -
ibu e,ERe e ence and EDa aType.
•EClass models a class. I has an a ibu e called name o s o e he name o he
modelled class. I has composi ion ela ionships wi h EA ibu e and ERe e -
ence. The ca dinali y o he composi ion means ha an EClass can ha e ze o o
mo e a ibu es and ze o o mo e e e ences.
•EA ibu e models an a ibu e. I has an a ibu e (name) and an associa ion
wi h EDa aType. The associa ion ep esen s ha an a ibu e mus ha e a ype.
•ERe e ence models one o he wo ends o an associa ion be ween classes. I has
wo a ibu es: name and con ainmen . The a ibu e con ainmen is ue i he
associa ion end ep esen s a composi ion ela ion. Finally, ERe e ence has an
associa ion wi h EClass. This ela ion models he a ge ype, ha is, he class
which is a ano he end o he associa ion.
•EDa aType models he ype o an a ibu e. I can be a p imi i e ype (in ,
loa , ...) o an objec ype.
We use Ja a in e aces o define he co e model. Fo each class o he model an
in e ace is defined. Fo each a ibu e and o each e e ence con ained in he class,
a s anda d ge () me hod is decla ed in he in e ace. Wi h his in o ma ion he
EMF gene a o will deduce he model a ibu es and e e ences. The Ja a in e aces
and he ge () me hods a e anno a ed in o de o help he EMF gene a o o deduce
he model p ope ies.
Wi h he in e aces and he anno a ions, EMF p oduces wo files: a .eco e file
and a .genmodel.The.eco e is an XML file ha con ains he co e model. The
.genmodel is a kind o w appe o he co e model wi h ex a in o ma ion. This
in o ma ion is needed o gene a ing he implemen a ion o he model.
Once he implemen a ion is gene a ed, each Eco e class ( ha is, each EClass)
co esponds o wo hings in Ja a: an in e ace and i s co esponding implemen-
a ion class. Fo example, class Book in ou Eco e model will be modelled as an
EClass in EMF, and i will be mapped on o a Ja a in e ace (public in e ace
Book) and an implemen a ion class (public class BookImpl ... implemen s
Book). Figu e 4depic s hese ela ions.
Book : EClass
Book
BookImpl
lib a y lib a y.impl
Fig. 4. Rela ionship be ween an Eco e class and he gene a ed s uff
I we define he Eco e model using anno a ed Ja a, we will jus be in cha ge o
w i ing he in e aces and he ge () me hods (i needed). A e wa ds, he EMF
gene a o will comple e hese in e aces wi h mo e anno a ions and se () me hods.
Fu he mo e, i will gene a e he implemen a ion classes and all he ex a code
needed.
4 P oblem S a emen : Me amodel Ex ension
I a me amodel is eused, i should be defined in such a way ha i is comple ely
unawa e o being ex ended by ano he me amodel.
To in oduce he p oblem, we ha e classified he possible ela ions be ween he
elemen s o wo models ( he o iginal and he ex ended one) in o wo main g oups:
inhe i ance ela ionships and he es o ela ionships. The ollowing subsec ions
in oduce wo diffe en examples o illus a e he impac o hese wo kinds o ela-
ions on he defini ion and implemen a ion o me amodels.
4.1 Example 1: Ex ensions by means o inhe i ance ela ionships
This example has been ob ained om [8]. I has been chosen because i is a e y
simple, in oduc o y example. Figu e 5shows a package named Lib a y which
holds a MOF me amodel o a lib a y. This package con ains h ee me aclasses
(Lib a y,Book and W i e ) and one enume a ion (BookCa ego y). Fo w i ing
his me amodel wi h EMF, h ee in e aces (one o each me aclass) ha e o be
defined. In each in e ace a numbe o ge () me hods should be w i en (one ge ¬
() me hod o each a ibu e and ano he one o each e e ence). Fu he mo e, a
new class should be defined o he enume a ion.
+Mis e y = 0
+Science-Fic ion = 1
+Biog aphy = 2
«enume a ion»
BookCa ego y -name : S ing
Lib a y
-name : S ing
W i e
-ca ego y : BookCa ego y
-name : S ing
-pages : in = 100
Book
+lib a y1
+w i e s*
+lib a y
1
+books
*
+au ho
1
+books *
+Mis e y = 0
+Science-Fic ion = 1
+Biog aphy = 2
«enume a ion»
BookCa ego y -name : S ing
Lib a y
-name : S ing
W i e
-ca ego y : BookCa ego y
-name : S ing
-pages : in = 100
Book
+lib a y1
+w i e s*
+lib a y
1
+books
*
+au ho
1
+books *
Lib a y
-name : S ing
Lib a y::Lib a y -ca ego y : BookCa ego y
-name : S ing
-pages : in = 100
Lib a y::Book
-loca ion : S ing
SchoolLib a y SchoolBook
- alue : loa
Asse
SchoolLib a y
Fig. 5. Ex eding a me amodel by means o inhe i ance ela ionship
Figu e 6shows a pa o he implemen a ion o he Lib a y me amodel wi h
EMF: he Lib a y me aclass and he BookCa ego y enume a ion.
package lib a y;
impo ja a.u il.Lis ;
/**
*@model
*/
public in e ace Lib a y
{
/**
* @model
*/
S ing ge Name();
/**
* @model ype="W i e " con ainmen =" ue"
*/
Lis ge W i e s();
/**
* @model ype="Book" con ainmen =" ue"
*/
Lis ge Books();
}
package lib a y;
/**
* @model
*/
public class BookCa ego y
{
/**
* @model name="Mys e y"
*/
public s a ic inal in MYSTERY = 0;
/**
* @model name="ScienceFic ion"
*/
public s a ic inal in SCIENCE_FICTION = 1;
/**
* @model name="Biog aphy"
*/
public s a ic inal in BIOGRAPHY = 2;
}
Fig. 6. Pa o he Lib a y EMF me amodel wi h Ja a no a ion
Figu e 5shows he SchoolLib a y package which ex ends he Lib a y package.
F om he MOF model poin o iew his ex ension implies ha he SchoolLib a y
package includes wo classes (Book and Lib a y) wi h he s e eo ype << om Li-
b a y>>. This s e eo ype means ha hose me aclasses belong o he Lib a y
package. In Figu e 6, his is depic ed wi h he name o he package placed jus
be o e henameo heclass(Lib a y::Book). Figu e 7shows he ex ends clause
in he SchoolLib a y and SchoolBook in e aces. These sen ences exp ess he
inhe i ance ela ionship be ween he pai o classes SchoolLib a y-Lib a y and
SchoolBook-Book. The classes Book and Lib a y should no be modified. Thus, as
a conclusion, i we ex end a me amodel by means o inhe i ance he obli iousness
o he o iginal me amodel is main ained.
package schoollib a y;
impo lib a y.Lib a y;
/**
* @model
*/
public in e ace SchoolLib a y ex ends Lib a y
{
/**
* @model
*/
S ing ge Loca ion();
}
package schoollib a y;
impo lib a y.Book;
/**
* @model
*/
public in e ace SchoolBook ex ends Book, Asse
{
}
Fig. 7. Pa o he ex ended SchoolLib a y package
4.2 Example 2: Ex ensions by means o associa ions
Figu e 8shows a ela ion be ween he wo packages. The o iginal package is called
com.me amodels.ja a2, i has been ob ained om [6], and i is a e sion o he
UML me amodel which ailo s he UML me aclasses o he Ja a2 Specifica ion.
The com.me amodels.aspec j package con ains an Aspec J me amodel which ex-
ends he Ja a me amodel acco ding o he Aspec J specifica ion [1]. Aspec J is an
ex ension o Ja a o de elop aspec -o ien ed applica ions. The Aspec J me amodel
has been ob ained om [12].
Aspec J Ja a2
<<ex ends>>
Fig. 8. Package ela ionship
Figu e 9shows he MOF Ja a 2 me amodel. Mos o he me aclasses use he
same name as he co esponding UML me aclasses. We ocus on he me aclasses
ha a e ele an o ou example: Elemen ,Gene aliza ion,Fea u e and Pa am-
e e .
The Gene aliza ion class models he ex end and implemen s ela ionships
be ween classifie s (classes and/o in e aces). An ins ance o his class ep esen s
an inhe i ance ela ionship be ween a sub ype and a supe ype. I can also ep esen
he ela ionship be ween a class and an in e ace.
AFea u e ep esen s some hing ha can be decla ed in a class o an in e ace
(a field, a cons uc o o an o dina y me hod).
The Pa ame e class abs ac s he pa ame e s in a me hod o cons uc o . This
ela ionship is ep esen ed by a composi ion ela ion be ween Pa ame e and Be-
ha io alFea u e. A pa ame e is also ela ed o a Type.
Tha specifica ion o his me amodel in anno a ed Ja a con ains one in e ace
o each me aclass and one final s a ic class o each enume a ion. Figu e 10 shows
-name[1] : S ing
-modi ie s[*] : Fea u eModi ie
Fea u e
+p i a e
+p o ec ed
+public
+s a ic
+abs ac
+ inal
+na i e
+synch onized
+ ansien
+ ola ile
+s ic p
«enume ación»
Fea u eModi ie
-ini Val : S ing
Field
-name : S ing
-modi ie s : ClassModi ie
Classi ie
+public
+p o ec ed
+p i a e
+abs ac
+s a ic
+s ic p
«enume ación»
ClassModi ie
-owne 1
-membe
*
-s a icIni [0..1] : Block
-ins anceIni [*] : Block
Class
« ipo de da os»
Block
Type - ype
0..1
- ea u e
*
-kind : P imi i eTag
P imi i eType
+boolean
+by e
+sho
+in
+long
+ loa
+double
+cha
«enume ación»
P imi i eTag
-body : Block
Beha io alFea u e
Cons uc o Me hod
Gene aliza ion
Elemen
-sub ype
1
-supe ipo
*
-supe ype
*
-sub ipo *
In e ace
Fig. 9. Aspec J Me amodel
he code needed o gene a ing he me aclasses Fea u e and Class.Fea u e has
wo a ibu es name and modi ie s which a e ans o med in he implemen a ion
in o wo ge () me hods, ge Name and ge Modi ie s.
Fea u e is also ela ed o Type and Classi ie . The fi s ela ion is an as-
socia ion while he second one is a composi ion ela ionship. F om he poin o
iew o Fea u e he e is no diffe ence be ween hese wo ela ionships: he e a e
wo ge () me hods (ge Owne and ge Type ea u e) wi h an opposi e anno a ion.
This anno a ion e e o he name a he o he end o he associa ion. The diffe -
ence be ween hese wo kinds o ela ionships is specified in he classes Type and
Classi ie , espec i ely. The Type in e ace will ha e a ge () me hod named
ge Fea u es while he Classi ie in e ace will ha e a ge () me hod (ge Mem-
be ) wi h an ex a anno a ion (con ainmen = ue). This con ainmen anno a ion
has he composi ion seman ics.
The Ja a2 me amodel is ex ended by he me amodel depic ed in Figu e 11.As
well as in he example in oduced in he p e ious sec ion, a he modelling le el,
he e is no p oblem o euse some me aclasses o he com.me amodel.ja a2 package.
We only need o label he classes wi h he s e eo ype <<Ja a2>>.Figu e11 shows
he s e eo yped classes Class,Gene aliza ion,Fea u e,Elemen and Pa ame e .
The Elemen and com.me amodel.aspec j package ha e inhe i ance ela ion-
ship. The e a e composi ion ela ionship be ween Class and Poin cu ; be ween
Pa ame e and Poin cu ; and be ween Pa ame e and Ad ice.Gene aliza ion
has associa ion ela ionship wi h Aspec and Fea u e has an associa ion wi h As-
pec .
I we wan o implemen hese ela ionships we need o decla e ge () me hods
package com.me amodel.ja a2;
impo o g.eclipse.em .common.u il.ELis ;
/**
* @model
*/
public in e ace Class ex ends Classi ie {
/**
* @model
* da aType="com.me amodel.ja a2.Block"
*/
Block ge S a icIni ();
/**
* @model
* da aType="com.me amodel.ja a2.Block"
*/
Block ge Ins anceIni ();
/**
* @model
* ype="com.me amodel.ja a2.Beha io alFea u e"
* opposi e=" h ownExcep ions"
*/
ELis ge Beha io alFea u es();
}
package com.me amodel.ja a2;
impo o g.eclipse.em .common.u il.ELis ;
/**
* @model
*/
public in e ace Fea u e ex ends Elemen {
/**
* @model
*/
S ing ge Name();
/**
* @model
* ype="com.me amodel.ja a2.Fea u eModi ie "
*/
ELis ge Modi ie s();
/**
* @model opposi e="membe "
*/
Classi ie ge Owne ();
/**
* @model opposi e=" ea u es"
*/
Type ge Type ea u e();
}
Fig. 10. Ja a 2 Implemen a ion
in he in e aces. Figu e 12 shows wo o hese in e aces, Poin cu and Aspec .
The Poin cu in e ace con ains an anno a ed me hod called ge Decla e ha
models one edge o he ela ionship be ween Poin cu and Class. Bu in o de
o model he o he end o he associa ion, a new anno a ed ge () me hod wi h an
anno a ion con ainmen = ue should be included in he Class in e ace. The e-
o e, a his poin we need o modi y he Class in e ace and, as a consequence, he
com.me amodel.ja a2 package becomes awa e o being ex ended wi h he com.¬
me amodel.aspec j package.
The same p oblem a ises when we y o implemen he associa ion be ween
Aspec and Fea u e.Thege In oducedFea u es me hod implemen s one o he
ends o he ela ionship, bu in o de o implemen he o he end we ha e o decla e
a new ge me hod in he Fea u e in e ace.
So, i we ex end a me amodel using ela ionships diffe en om inhe i ance, he
obli iousness o he o iginal me amodel is los .
5 Using aspec echnology o imp o e euse o me a-
models
This sec ion desc ibes h ee diffe en app oaches o making he com.me amodel¬
.ja a2 unawa e o being ex ended by ano he me amodel. The fi s one is based
on he adi ional objec -o ien ed inhe i ance mechanism, while he second and he
hi d ones a e based on aspec -o ien ed solu ions [13].