简体   繁体   中英

IllegalValue when reading .uml file with eclipse MDT UML2

I have created a simple state machine model in Enterprise Architect and exported it to a file, which I want to read into a standalone Java/Scala program based on Eclipse's MDT UML2 implementation.

I managed to get this partially working, but still have two remaining problems:

  1. The exported XMI file from EA contains more than just the <uml:Model></...> part, in which case I only get AnyTypeImpl objects after parsing. For now, I've manually changed the file and reduced it the UML model tag only, though it would be nice to be able to use the XMI file out of the (EA export) box somehow.

  2. I get an IllegalValueException for different attributes, like isOrthogonal="true" . The stack trace for it looks something like this:

    org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.IllegalValueException: Value 'true' is not legal. (file:src/test/resources/test.uml, 7, 111) at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315) at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274) at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)

This is the code (in Scala, but it's pretty much the same as in Java at this point) I am using in order to load the model file right now:

val resSet = new ResourceSetImpl
resSet.getPackageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE)
resSet.getResourceFactoryRegistry.getExtensionToFactoryMap.put("*", UMLResource.Factory.INSTANCE)
resSet.getResource(URI.createURI("file:myfile.uml"), true)

I do not believe anything is wrong with the model file at this point (orthogonal states in state machines are quite straightforward normal stuff after all), so I guess I have not managed to set up MDT/UML2 correctly here. Googling has brought up the point of having to register the corresponding factory, which seems to have worked, as otherwise I would get a more straightforward error about the missing factory. But now that the factory is registered I am unsure what's missing and the error message is not very helpful to me here.

To check if a model file having a *.uml extension is valid with UML2 you only need to download the UML Editor. It is not an UML tool but only a plug-in which allows you to manipulate the UML model within a tree editor. If you click on an element in the tree you have menus. The UML editor is adding a graphical view and manipulation of the model but this plugin is working directly at the model/metamodel level.

If the .uml can be loaded then you have passed the first test. You file is compatible with UML2. Click on the project name and select Check model option. You will know if your model is 100% correct.

Hope this help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM