简体   繁体   English

使用Eclipse MDT UML2读取.uml文件时为IllegalValue

[英]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. 我已经在Enterprise Architect中创建了一个简单的状态机模型,并将其导出到文件中,我想将其读取到基于Eclipse的MDT UML2实现的独立Java / Scala程序中。

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. 从EA导出的XMI文件不仅包含<uml:Model></...>部分,在这种情况下,在解析后我仅获得AnyTypeImpl对象。 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. 现在,我已经手动更改了文件并仅将其减少为UML模型标签,尽管能够以某种方式在(EA导出)框中使用XMI文件会很好。

  2. I get an IllegalValueException for different attributes, like isOrthogonal="true" . 我为不同的属性(例如isOrthogonal="true"获得了IllegalValueException 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. org.eclipse.emf.ecore.resource.impl.ResourceSetImpl $ 1DiagnosticWrappedException:org.eclipse.emf.ecore.xmi.IllegalValueException:值'true'不合法。 (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) (file:src / test / resources / test.uml,7,111)在org.eclipse.emf.ecore.resource上的org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315) .impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)在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: 这是我现在用来加载模型文件的代码(在Scala中,但目前与Java中的代码几乎相同):

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. 我不认为此时模型文件有什么问题(毕竟状态机中的正交状态毕竟是非常简单的普通信息),所以我想我在这里没有正确设置MDT / UML2。 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. Googling提出了必须注册相应工厂的观点,该工厂似乎已经奏效,否则我将对缺失的工厂得到更直接的错误。 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. 要检查扩展名为* .uml的模型文件对UML2是否有效,您只需下载UML编辑器。 It is not an UML tool but only a plug-in which allows you to manipulate the UML model within a tree editor. 它不是UML工具,而是一个插件,可让您在树编辑器中操作UML模型。 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. UML编辑器正在添加模型的图形视图和操作,但是此插件直接在模型/元模型级别工作。

If the .uml can be loaded then you have passed the first test. 如果可以加载.uml,则说明您已通过第一项测试。 You file is compatible with UML2. 您的文件与UML2兼容。 Click on the project name and select Check model option. 单击项目名称,然后选择检查模型选项。 You will know if your model is 100% correct. 您将知道您的模型是否100%正确。

Hope this help 希望这个帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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