Pregunta

I have loaded an xmi file with an uml diagram. As a result I get an org.eclipse.uml2.uml.Package.

Now I want to programmatically convert it to Ecore (ePackage).

I've already taken a look at the UML2EcoreConverter from org.eclipse.uml2.uml.util.UMLUtil. But it's convert-method is not clear to me.

¿Fue útil?

Solución

Instead of going directly for the UML2EcoreConverter, take a look at

org.eclipse.uml2.uml.util.UMLUtil.convertToEcore(Package, Map)

It takes a package and a Map of options and returns the converted EPackage(s). The options map can be fed the options from UMLUtil.UML2EcoreConverter.OPTION__* as keys. Possible values are UMLUtil.OPTION_DISCARD/OPTION_IGNORE/OPTION_PROCESS/OPTION_REPORT. All options default to OPTION__IGNORE.

Most of these options are for processing concepts of UML2 class diagrams that don't map cleanly to Ecore, so you can control how they should be handled.

For extended feature mapping (subset/union, redefines ...), see OPTION_REDEFINING*, OPTION_SUBSETTING*, OPTION__UNION_PROPERTIES, OPTION_DUPLICATE*. It should be okay to set all of these to OPTION_PROCESS.

One option you might want to disable is OPTION__SUPER_CLASS_ORDER. This will reorder the generalizations and interface realizations in alphabetical order, which might cause implementation concerns when you want to inherit a specific super implementation. Another one is OPTION__CAMEL_CASE_NAMES, which will process class and feature names to force a strict camel case scheme. This only makes sense in cases where your UML artifacts don't have valid java names. Just set them to OPTION_IGNORE, or, to see where they would change something, to OPTION_REPORT.

There's also a convertFromEcore(...) for the reverse.

In case you would like to understand the inner workings of UML2EcoreConverter better: It's basically a simple recursive visitor that traverses the UML model, converting each artifact to its Ecore equivalent and doing some cleaning up. It extends UMLSwitch to handle the different metaclasses. So to see for example how a UML Property is converted to an EStructuralFeature, have a look at caseProperty(...)

Otros consejos

You can only convert one way from Ecore to UML.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top