| 1 |
<?xml version = '1.0' encoding = 'UTF-8' ?> |
|---|
| 2 |
|
|---|
| 3 |
<?python |
|---|
| 4 |
from gaphor.application import Application |
|---|
| 5 |
import time |
|---|
| 6 |
import |
|---|
| 7 |
|
|---|
| 8 |
element_factory = Application.get_service('element_factory') |
|---|
| 9 |
|
|---|
| 10 |
topLevelPackage = [element for element in element_factory.select() if not getattr(element, 'package', True)][0] |
|---|
| 11 |
|
|---|
| 12 |
def modelProcessNode(node): |
|---|
| 13 |
className = type(node).__name__ |
|---|
| 14 |
try: |
|---|
| 15 |
return eval("process%s(node)"%className, globals(), locals()) |
|---|
| 16 |
except NameError: |
|---|
| 17 |
return '' |
|---|
| 18 |
|
|---|
| 19 |
def getPackageChildNodes(package): |
|---|
| 20 |
return [node for node in element_factory.select() if |
|---|
| 21 |
hasattr(node, 'package') and node.package==package] |
|---|
| 22 |
|
|---|
| 23 |
def getLowerAndUpperValuesFromAssociationEnd(end): |
|---|
| 24 |
values=('lower','upper') |
|---|
| 25 |
attributes = {} |
|---|
| 26 |
for value in values: |
|---|
| 27 |
try: |
|---|
| 28 |
data=getattr(end, '%sValue'%value).value |
|---|
| 29 |
except AttributeError: |
|---|
| 30 |
data='1' # FIXME! |
|---|
| 31 |
if str(data)=='*': |
|---|
| 32 |
attributes['lower']='0' |
|---|
| 33 |
attributes['upper']='-1' |
|---|
| 34 |
return attributes |
|---|
| 35 |
elif data is None: |
|---|
| 36 |
data='1' |
|---|
| 37 |
attributes[value]=data |
|---|
| 38 |
return attributes |
|---|
| 39 |
|
|---|
| 40 |
from gaphor.misc.uniqueid import generate_id |
|---|
| 41 |
|
|---|
| 42 |
taggedValues = [] |
|---|
| 43 |
|
|---|
| 44 |
def registerTaggedValue(taggedValue): |
|---|
| 45 |
taggedValues.append(taggedValue) |
|---|
| 46 |
return taggedValue |
|---|
| 47 |
|
|---|
| 48 |
?> |
|---|
| 49 |
|
|---|
| 50 |
<XMI |
|---|
| 51 |
xmlns:py="http://purl.org/kid/ns#" |
|---|
| 52 |
xmi.version = '1.2' xmlns:UML = 'org.omg.xmi.namespace.UML' xmlns:UML2 = 'org.omg.xmi.namespace.UML2' |
|---|
| 53 |
timestamp = 'Sun Oct 09 09:01:33 CEST 2005' py:attrs="timestamp=time.strftime('%a %b %d %H:%M:%S %Z %Y')"> |
|---|
| 54 |
|
|---|
| 55 |
<XMI.header><XMI.documentation> |
|---|
| 56 |
<XMI.exporter>Gaphor Kid XMI Writer</XMI.exporter> |
|---|
| 57 |
<XMI.exporterVersion>0.1</XMI.exporterVersion> |
|---|
| 58 |
<XMI.metaModelVersion>1.4.2</XMI.metaModelVersion></XMI.documentation> |
|---|
| 59 |
</XMI.header> |
|---|
| 60 |
<XMI.content> |
|---|
| 61 |
|
|---|
| 62 |
<UML:Model |
|---|
| 63 |
xmi.id = 'I48de81cbm106d41f950cmm7f54' name = 'topModel' isSpecification = 'false' |
|---|
| 64 |
isRoot = 'false' isLeaf = 'false' isAbstract = 'false' |
|---|
| 65 |
py:attrs="{'xmi.id':topLevelPackage.id, 'name':topLevelPackage.name}"> |
|---|
| 66 |
|
|---|
| 67 |
<UML:Classifier.feature py:def="processClassifierFeature(item)"> |
|---|
| 68 |
|
|---|
| 69 |
<UML:Namespace.ownedElement> |
|---|
| 70 |
<UML:Class py:for="cls in [a.typeValue for a in item.ownedAttribute if a.typeValue]" |
|---|
| 71 |
visibility='public' isSpecification='false' isRoot='false' isAbstract='false' |
|---|
| 72 |
isActive='false' |
|---|
| 73 |
py:attrs="{'xmi.id': cls.id, 'name':cls.value}"/> |
|---|
| 74 |
</UML:Namespace.ownedElement> |
|---|
| 75 |
|
|---|
| 76 |
<UML:Attribute xmi.id = 'I48de81cbm106d41f950cmm7f35' name = 'someAttribute' |
|---|
| 77 |
visibility = 'private' isSpecification = 'false' ownerScope = 'instance' |
|---|
| 78 |
changeability = 'changeable' |
|---|
| 79 |
py:for="attribute in [a for a in item.ownedAttribute if a.typeValue]" |
|---|
| 80 |
py:attrs="{'xmi.id':attribute.id, 'name':attribute.name}"> |
|---|
| 81 |
<UML:ModelElement.taggedValue |
|---|
| 82 |
py:for="taggedValue in attribute.taggedValue" |
|---|
| 83 |
py:content="registerTaggedValue(taggedValue)"> |
|---|
| 84 |
</UML:ModelElement.taggedValue> |
|---|
| 85 |
<UML:StructuralFeature.type> |
|---|
| 86 |
<UML:Class xmi.idref = 'I48de81cbm106d41f950cmm7f24' |
|---|
| 87 |
py:attrs="{'xmi.idref':attribute.typeValue.id}"/> |
|---|
| 88 |
</UML:StructuralFeature.type> |
|---|
| 89 |
</UML:Attribute> |
|---|
| 90 |
|
|---|
| 91 |
<UML:Operation xmi.id = 'I48de81cbm106d41f950cmm7f11' name = 'someMethod' |
|---|
| 92 |
visibility = 'public' isSpecification = 'false' ownerScope = 'instance' |
|---|
| 93 |
isQuery = 'false' concurrency = 'sequential' isRoot = 'false' isLeaf = 'false' |
|---|
| 94 |
isAbstract = 'false' |
|---|
| 95 |
py:for="operation in item.ownedOperation" |
|---|
| 96 |
py:attrs="{'xmi.id':operation.id, 'name':operation.name}"> |
|---|
| 97 |
<UML:ModelElement.taggedValue |
|---|
| 98 |
py:for="taggedValue in operation.taggedValue" |
|---|
| 99 |
py:content="registerTaggedValue(taggedValue)"> |
|---|
| 100 |
</UML:ModelElement.taggedValue> |
|---|
| 101 |
<UML:BehavioralFeature.parameter> |
|---|
| 102 |
<UML:Parameter xmi.id = 'I48de81cbm106d41f950cmm7ee1' name = 'return' isSpecification = 'false' |
|---|
| 103 |
kind = 'return' |
|---|
| 104 |
py:for="parameter in operation.formalParameter" |
|---|
| 105 |
py:attrs="{'xmi.id':parameter.id, 'name':parameter.name, 'kind':parameter.kind}"> |
|---|
| 106 |
<UML:Parameter.type> |
|---|
| 107 |
<UML:DataType xmi.idref = 'I48de81cbm106d41f950cmm7f36' |
|---|
| 108 |
py:attrs="{'xmi.idref':parameter.typeValue.id}"/> |
|---|
| 109 |
</UML:Parameter.type> |
|---|
| 110 |
</UML:Parameter> |
|---|
| 111 |
</UML:BehavioralFeature.parameter> |
|---|
| 112 |
</UML:Operation> |
|---|
| 113 |
|
|---|
| 114 |
<UML:Method xmi.id = 'I48de81cbm106d41f950cmm7f0f' isSpecification = 'false' |
|---|
| 115 |
isQuery = 'false'> |
|---|
| 116 |
<UML:Method.body> |
|---|
| 117 |
<UML:ProcedureExpression xmi.id = 'I48de81cbm106d41f950cmm7f10' language = 'java' |
|---|
| 118 |
body = ''/> |
|---|
| 119 |
</UML:Method.body> |
|---|
| 120 |
<UML:Method.specification> |
|---|
| 121 |
<UML:Operation xmi.idref = 'I48de81cbm106d41f950cmm7f11'/> |
|---|
| 122 |
</UML:Method.specification> |
|---|
| 123 |
</UML:Method> |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
</UML:Classifier.feature> |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
<UML:TagDefinition py:def="processTagDefinition(taggedValue)" |
|---|
| 131 |
xmi.id = 'I5bd6b6fm106dbda4889mm7f24' name = 'someTag' |
|---|
| 132 |
py:attrs="{'xmi.id':taggedValue.id+'ref', 'name':taggedValue.value.split('=')[0]}" |
|---|
| 133 |
isSpecification = 'false'> |
|---|
| 134 |
<UML:TagDefinition.multiplicity> |
|---|
| 135 |
<UML:Multiplicity xmi.id = 'I5bd6b6fm106dbda4889mm7f23' |
|---|
| 136 |
py:attrs="{'xmi.id':taggedValue.id+'multi'}"> |
|---|
| 137 |
<UML:Multiplicity.range> |
|---|
| 138 |
<UML:MultiplicityRange xmi.id = 'I5bd6b6fm106dbda4889mm7f22' lower = '1' |
|---|
| 139 |
upper = '1' |
|---|
| 140 |
py:attrs="{'xmi.id':taggedValue.id+'multirange'}"/> |
|---|
| 141 |
</UML:Multiplicity.range> |
|---|
| 142 |
</UML:Multiplicity> |
|---|
| 143 |
</UML:TagDefinition.multiplicity> |
|---|
| 144 |
</UML:TagDefinition> |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
<UML:TaggedValue py:def="processTaggedValue(taggedValue)" |
|---|
| 148 |
xmi.id = 'I5bd6b6fm106dbda4889mm7f21' isSpecification = 'false' |
|---|
| 149 |
py:attrs="{'xmi.id':taggedValue.id}"> |
|---|
| 150 |
<UML:TaggedValue.dataValue |
|---|
| 151 |
py:content="taggedValue.value.split('=')[1]">someTagValue</UML:TaggedValue.dataValue> |
|---|
| 152 |
<UML:TaggedValue.type> |
|---|
| 153 |
<UML:TagDefinition xmi.idref = 'I5bd6b6fm106dbda4889mm7f24' |
|---|
| 154 |
py:attrs="{'xmi.idref':taggedValue.id+'ref'}"/> |
|---|
| 155 |
</UML:TaggedValue.type> |
|---|
| 156 |
</UML:TaggedValue> |
|---|
| 157 |
|
|---|
| 158 |
<UML:Abstraction py:def="processImplementation(abstraction)" |
|---|
| 159 |
xmi.id = 'I48de81cbm106d41f950cmm7e5d' isSpecification = 'false' |
|---|
| 160 |
py:attrs="{'xmi.id':abstraction.id}"> |
|---|
| 161 |
<UML:Dependency.client> |
|---|
| 162 |
<UML:Class xmi.idref = 'I48de81cbm106d41f950cmm7ead' |
|---|
| 163 |
py:for="client in abstraction.client" |
|---|
| 164 |
py:attrs="{'xmi.idref':client.id}"/> |
|---|
| 165 |
</UML:Dependency.client> |
|---|
| 166 |
<UML:Dependency.supplier> |
|---|
| 167 |
<UML:Interface xmi.idref = 'I48de81cbm106d41f950cmm7e73' |
|---|
| 168 |
py:for="supplier in abstraction.supplier" |
|---|
| 169 |
py:attrs="{'xmi.idref':supplier.id}"/> |
|---|
| 170 |
</UML:Dependency.supplier> |
|---|
| 171 |
</UML:Abstraction> |
|---|
| 172 |
|
|---|
| 173 |
<UML:Generalization py:def="processGeneralization(generalization)" |
|---|
| 174 |
xmi.id = 'I48de81cbm106d41f950cmm7eb4' isSpecification = 'false' |
|---|
| 175 |
py:attrs="{'xmi.id':generalization.id}"> |
|---|
| 176 |
<UML:Generalization.child> |
|---|
| 177 |
<UML:Class xmi.idref = 'I48de81cbm106d41f950cmm7ec7' |
|---|
| 178 |
py:attrs="{'xmi.idref':generalization.specific.id}"/> |
|---|
| 179 |
</UML:Generalization.child> |
|---|
| 180 |
<UML:Generalization.parent> |
|---|
| 181 |
<UML:Class xmi.idref = 'I48de81cbm106d41f950cmm7f4c' |
|---|
| 182 |
py:attrs="{'xmi.idref':generalization.general.id}"/> |
|---|
| 183 |
</UML:Generalization.parent> |
|---|
| 184 |
</UML:Generalization> |
|---|
| 185 |
|
|---|
| 186 |
<UML:Interface py:def="processInterface(interface)" |
|---|
| 187 |
xmi.id = 'I48de81cbm106d41f950cmm7e73' name = 'SomeInterface' |
|---|
| 188 |
visibility = 'public' isSpecification = 'false' isRoot = 'false' isLeaf = 'false' |
|---|
| 189 |
isAbstract = 'false' |
|---|
| 190 |
py:attrs="{'xmi.id':interface.id, 'name':interface.name}"> |
|---|
| 191 |
<UML:ModelElement.taggedValue |
|---|
| 192 |
py:for="taggedValue in interface.taggedValue" |
|---|
| 193 |
py:content="registerTaggedValue(taggedValue)"> |
|---|
| 194 |
</UML:ModelElement.taggedValue> |
|---|
| 195 |
<UML:Classifier.feature py:replace="processClassifierFeature(interface)"/> |
|---|
| 196 |
</UML:Interface> |
|---|
| 197 |
|
|---|
| 198 |
<UML:Class py:def="processClass(cls)" |
|---|
| 199 |
py:if="cls.name not in ('Class','Interface','Package')" |
|---|
| 200 |
xmi.id = 'I48de81cbm106d41f950cmm7f4c' name = 'AbstractBaseClass' |
|---|
| 201 |
visibility = 'public' isSpecification = 'false' isRoot = 'false' isLeaf = 'false' |
|---|
| 202 |
isAbstract = 'true' isActive = 'false' |
|---|
| 203 |
py:attrs="{'xmi.id':cls.id, 'name':cls.name, |
|---|
| 204 |
'isAbstract':cls.isAbstract and 'true' or 'false'}"> |
|---|
| 205 |
|
|---|
| 206 |
<UML:ModelElement.taggedValue |
|---|
| 207 |
py:for="taggedValue in cls.taggedValue" |
|---|
| 208 |
py:content="registerTaggedValue(taggedValue)"> |
|---|
| 209 |
</UML:ModelElement.taggedValue> |
|---|
| 210 |
|
|---|
| 211 |
<UML:ModelElement.stereotype py:if="cls.appliedStereotype"> |
|---|
| 212 |
<UML:Stereotype xmi.idref = 'I48de81cbm106d41f950cmm7e0c' |
|---|
| 213 |
py:for="stereotype in cls.appliedStereotype"/> |
|---|
| 214 |
</UML:ModelElement.stereotype> |
|---|
| 215 |
|
|---|
| 216 |
<UML:ModelElement.clientDependency py:if="cls.supplierDependency"> |
|---|
| 217 |
<UML:Abstraction xmi.idref = 'I48de81cbm106d41f950cmm7e5d' |
|---|
| 218 |
py:for="interface in cls.supplierDependency" |
|---|
| 219 |
py:attrs="{'xmi.idref':interface.id}"/> |
|---|
| 220 |
</UML:ModelElement.clientDependency> |
|---|
| 221 |
|
|---|
| 222 |
<UML:GeneralizableElement.generalization py:if="cls.generalization"> |
|---|
| 223 |
<UML:Generalization xmi.idref = 'I48de81cbm106d41f950cmm7eb4' |
|---|
| 224 |
py:for="generalization in cls.generalization" |
|---|
| 225 |
py:attrs="{'xmi.idref':generalization.id}"/> |
|---|
| 226 |
</UML:GeneralizableElement.generalization> |
|---|
| 227 |
|
|---|
| 228 |
<UML:Classifier.feature py:replace="processClassifierFeature(cls)"/> |
|---|
| 229 |
</UML:Class> |
|---|
| 230 |
|
|---|
| 231 |
<UML:Stereotype py:def="processStereotype(stereotype)" |
|---|
| 232 |
xmi.id = 'I48de81cbm106d41f950cmm7e0c' name = 'stereotypeTest' |
|---|
| 233 |
visibility = 'public' isSpecification = 'false' isRoot = 'false' isLeaf = 'false' |
|---|
| 234 |
isAbstract = 'false' |
|---|
| 235 |
py:attrs="{'xml.id':stereotype.id, 'name':stereotype.name}"> |
|---|
| 236 |
<UML:ModelElement.taggedValue |
|---|
| 237 |
py:for="taggedValue in stereotype.taggedValue" |
|---|
| 238 |
py:content="registerTaggedValue(taggedValue)"> |
|---|
| 239 |
</UML:ModelElement.taggedValue> |
|---|
| 240 |
<UML:Stereotype.baseClass py:content="stereotype.ownedAttribute.type.name">Class</UML:Stereotype.baseClass> |
|---|
| 241 |
</UML:Stereotype> |
|---|
| 242 |
|
|---|
| 243 |
<UML:Package py:def="processPackage(package)" |
|---|
| 244 |
xmi.id = 'I48de81cbm106d41f950cmm7e01' name = 'aPackage' visibility = 'public' |
|---|
| 245 |
isSpecification = 'false' isRoot = 'false' isLeaf = 'false' isAbstract = 'false' |
|---|
| 246 |
py:attrs="{'xmi.idref':package.id, 'name':package.name}"> |
|---|
| 247 |
<UML:ModelElement.taggedValue |
|---|
| 248 |
py:for="taggedValue in package.taggedValue" |
|---|
| 249 |
py:content="registerTaggedValue(taggedValue)"> |
|---|
| 250 |
</UML:ModelElement.taggedValue> |
|---|
| 251 |
<UML:Namespace.ownedElement> |
|---|
| 252 |
<packageContent py:for="item in getPackageChildNodes(package=package)" |
|---|
| 253 |
py:replace="modelProcessNode(item)"/> |
|---|
| 254 |
</UML:Namespace.ownedElement> |
|---|
| 255 |
</UML:Package> |
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
<UML:Association py:def="processAssociation(association)" |
|---|
| 259 |
py:if="len(association.memberEnd)==2" |
|---|
| 260 |
xmi.id = 'I48de81cbm106d41f950cmm7d2f' isSpecification = 'false' |
|---|
| 261 |
isRoot = 'false' isLeaf = 'false' isAbstract = 'false' |
|---|
| 262 |
py:attrs="{'xmi.id':association.id, 'name':association.name}"> |
|---|
| 263 |
<UML:ModelElement.taggedValue |
|---|
| 264 |
py:for="taggedValue in association.taggedValue" |
|---|
| 265 |
py:content="registerTaggedValue(taggedValue)"> |
|---|
| 266 |
</UML:ModelElement.taggedValue> |
|---|
| 267 |
<UML:Association.connection> |
|---|
| 268 |
<UML:AssociationEnd xmi.id = 'I48de81cbm106d41f950cmm7d35' visibility = 'public' |
|---|
| 269 |
isSpecification = 'false' isNavigable = 'false' ordering = 'unordered' aggregation = 'none' |
|---|
| 270 |
targetScope = 'instance' changeability = 'changeable' |
|---|
| 271 |
py:for="(i,end) in enumerate(association.memberEnd)" |
|---|
| 272 |
py:attrs="{'xmi.id':end.id, 'isNavigable': end.class_ and 'true' or 'false', |
|---|
| 273 |
'aggregation':association.memberEnd[1-i]}"> |
|---|
| 274 |
<UML:AssociationEnd.multiplicity> |
|---|
| 275 |
<UML:Multiplicity xmi.id = 'I48de81cbm106d41f950cmm7d33' |
|---|
| 276 |
py:attrs="{'xmi.id':end.id+'_%s'%i}"> |
|---|
| 277 |
<UML:Multiplicity.range> |
|---|
| 278 |
<UML:MultiplicityRange xmi.id = 'I48de81cbm106d41f950cmm7d34' lower = '1' |
|---|
| 279 |
upper = '1' |
|---|
| 280 |
py:attrs="{'xmi.id':end.id+'_range_%s'%i, |
|---|
| 281 |
'lower':getLowerAndUpperValuesFromAssociationEnd(end)['lower'], |
|---|
| 282 |
'upper':getLowerAndUpperValuesFromAssociationEnd(end)['upper']}"/> |
|---|
| 283 |
</UML:Multiplicity.range> |
|---|
| 284 |
</UML:Multiplicity> |
|---|
| 285 |
</UML:AssociationEnd.multiplicity> |
|---|
| 286 |
<UML:AssociationEnd.participant> |
|---|
| 287 |
<UML:Class xmi.idref = 'I48de81cbm106d41f950cmm7ddb' |
|---|
| 288 |
py:attrs="{'xmi.idref':end.type.id}"/> |
|---|
| 289 |
</UML:AssociationEnd.participant> |
|---|
| 290 |
</UML:AssociationEnd> |
|---|
| 291 |
</UML:Association.connection> |
|---|
| 292 |
</UML:Association> |
|---|
| 293 |
|
|---|
| 294 |
<UML:Namespace.ownedElement> |
|---|
| 295 |
<UML:ModelElement.taggedValue |
|---|
| 296 |
py:for="taggedValue in topLevelPackage.taggedValue" |
|---|
| 297 |
py:content="registerTaggedValue(taggedValue)"> |
|---|
| 298 |
</UML:ModelElement.taggedValue> |
|---|
| 299 |
<packageContent py:for="item in getPackageChildNodes(package=topLevelPackage)" |
|---|
| 300 |
py:replace="modelProcessNode(item)"/> |
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
<UML:TagDefinition py:for="tagDef in taggedValues" |
|---|
| 304 |
py:replace="processTagDefinition(tagDef)"/> |
|---|
| 305 |
|
|---|
| 306 |
</UML:Namespace.ownedElement> |
|---|
| 307 |
</UML:Model> |
|---|
| 308 |
</XMI.content> |
|---|
| 309 |
</XMI> |
|---|