blob: ec4f8ca7e66934c457d92543033bf281a2e7cc6b [file] [log] [blame]
modeltype UML uses 'http://www.eclipse.org/uml2/2.0.0/UML';
modeltype XHTML uses 'http://www.w3.org/1999/xhtml';
transformation Uml2Xhtml(in Uml : UML, out Xhtml : XHTML);
configuration property DEBUG : Boolean;
main() {
var model := Uml.rootObjects()![Model];
object DocumentRoot {
html := object xhtml::HtmlType {
head := object xhtml::HeadType {
title := object xhtml::TitleType {
text := guardText(model.name);
};
};
_body := object xhtml::BodyType {
h1 := object xhtml::H1Type {
text := guardText('Model ' + model.name)
};
div += object xhtml::DivType {
h2 := object xhtml::H2Type {
text := guardText('Classes in ' + model.name)
};
table := object xhtml::TableType {
model.map allClasses()->forEach(p) {
tr += p.map class2row()
}
};
};
div += model.map allClasses()->map class2div();
}
}
}
}
mapping uml::Class::class2row() : xhtml::TrType {
td := object xhtml::TdType {
a := new xhtml::AType (self.fullName(), self.name)
}
}
mapping uml::Class::class2div() : xhtml::DivType {
debugLog("Processing class: " + self.fullName() + "..");
id := self.fullName();
hr := new xhtml::HrType();
h3 := object xhtml::H3Type {
text := guardText('Class '.concat(self.name));
};
div := object xhtml::DivType {
div += map classGeneralizations(self);
div += map classOwnedAttributes(self);
}
}
mapping classGeneralizations(in cls: uml::Class) : xhtml::DivType
when { not cls.generalization->isEmpty() }
{
h3 += object xhtml::H3Type {
text := 'Generalizations'
};
ul := object xhtml::UlType {
li := cls.generalization->map gen2listitem()
}
}
mapping uml::Generalization::gen2listitem() : xhtml::LiType {
assert fatal (self.general <> null and self.specific <> null) with log ("Malformed generalization link", self);
a := new xhtml::AType (self.general.fullName(), self.general.name)
}
mapping classOwnedAttributes(in cls: uml::Class) : xhtml::DivType
when { not cls.ownedAttribute->isEmpty() }
{
h3 += object xhtml::H3Type {
text := 'Attributes'
};
ul := object xhtml::UlType {
li := cls.ownedAttribute->map attr2listitem()
}
}
mapping uml::Property::attr2listitem() : xhtml::LiType {
text := guardText(self.name)
}
query uml::PackageableElement::fullName() : String {
return if self.owner.oclIsUndefined() then
self.name
else
self.owner.oclAsType(uml::Package).fullName().concat('.').concat(self.name)
endif
}
mapping uml::Package::allClasses() : OrderedSet(uml::Class) {
init {
result := self.ownedMember[uml::Class]->sortedBy(name)
}
}
query guardText(in text: String) : String {
return if text.oclIsUndefined() then '' else text endif
}
constructor xhtml::TdType::TdType(value : String) {
text := guardText(value)
}
constructor xhtml::AType::AType(id : String, text : String) {
href := '#'.concat(id);
result.text := guardText(text);
}
query debugLog(text : String) {
log (text) when DEBUG;
}