-- $Id$ module Singleton; create OUT : UML refining IN : UML; uses Java; -- ====================================================================== -- model-specific helpers begin -- ====================================================================== helper context String def : stereotype() : UML!Stereotype = UML!Stereotype.allInstances()->select(s|s.name=self)->first(); helper context UML!GeneralizableElement def : isSingleton() : Boolean = not self.stereotype->select(s|s.name='Singleton')->isEmpty(); -- ====================================================================== -- model-specific helpers end -- ====================================================================== -- ====================================================================== -- transformation rules begin -- ====================================================================== rule SingletonClass { from s : UML!Class (s.oclIsTypeOf(UML!Class) and s.isSingleton()) to t : UML!Class mapsTo s ( namespace <- s.namespace, isLeaf <- s.isLeaf, isRoot <- s.isRoot, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, isAbstract <- s.isAbstract, isActive <- s.isActive, templateParameter <- s.templateParameter, comment <- s.comment, feature <- s.feature, ownedElement <- s.ownedElement, taggedValue <- s.taggedValue, powertypeRange <- s.powertypeRange, clientDependency <- s.clientDependency, constraint <- s.constraint, targetFlow <- s.targetFlow, generalization <- s.generalization, stereotype <- s.stereotype, sourceFlow <- s.sourceFlow), op : UML!Operation ( name <- 'getInstance', owner <- s, visibility <- #vk_public, ownerScope <- #sk_classifier, isAbstract <- false, concurrency <- #cck_sequential), par : UML!Parameter ( name <- 'return', behavioralFeature <- op, type <- s, kind <- #pdk_return), mbody : UML!ProcedureExpression ( language <- 'java', body <- s.name.javaSingletonBody()), meth : UML!Method ( owner <- s, body <- mbody, specification <- op), instance : UML!Attribute ( name <- 'instance', owner <- s, type <- s, visibility <- #vk_private, ownerScope <- #sk_classifier, changeability <- #ck_changeable, initialValue <- v), v : UML!Expression ( language <- 'java', body <- 'null') } rule Model { from s : UML!Model to t : UML!Model mapsTo s ( isLeaf <- s.isLeaf, isRoot <- s.isRoot, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, isAbstract <- s.isAbstract, templateParameter <- s.templateParameter, elementImport <- s.elementImport, comment <- s.comment, ownedElement <- s.ownedElement, taggedValue <- s.taggedValue, clientDependency <- s.clientDependency, constraint <- s.constraint, targetFlow <- s.targetFlow, generalization <- s.generalization, stereotype <- s.stereotype, sourceFlow <- s.sourceFlow) } rule StateMachine { from s : UML!StateMachine (s.oclIsTypeOf(UML!StateMachine)) to t : UML!StateMachine mapsTo s ( visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, templateParameter <- s.templateParameter, submachineState <- s.submachineState, comment <- s.comment, top <- s.top, taggedValue <- s.taggedValue, transitions <- s.transitions, clientDependency <- s.clientDependency, constraint <- s.constraint, targetFlow <- s.targetFlow, stereotype <- s.stereotype, sourceFlow <- s.sourceFlow, "context" <- s."context") } -- ====================================================================== -- transformation rules end -- ======================================================================