繁体   English   中英

使用UML2解析XMI文件,如何处理href属性?

[英]Using UML2 to parse a XMI file, how to handle href properties?

我使用UML2解析包含UML shema的XMI文件。

这是Modelio生成的.uml的内容:

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_PuKnYPqnEeKOHL0-05J3_Q" name="xmitojava">
  <eAnnotations xmi:id="_PuKnYfqnEeKOHL0-05J3_Q" source="Objing">
    <contents xmi:type="uml:Property" xmi:id="_PuKnYvqnEeKOHL0-05J3_Q" name="exporterVersion">
      <defaultValue xmi:type="uml:LiteralString" xmi:id="_PuKnY_qnEeKOHL0-05J3_Q" value="2.2"/>
    </contents>
  </eAnnotations>
  <ownedComment xmi:id="_PuKnZPqnEeKOHL0-05J3_Q">
    <body></body>
  </ownedComment>
  <packagedElement xmi:type="uml:Class" xmi:id="_PuKnZfqnEeKOHL0-05J3_Q" name="User">
    <ownedAttribute xmi:id="_PuKnZvqnEeKOHL0-05J3_Q" name="login" visibility="protected" isUnique="false" isReadOnly="true">
      <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
    </ownedAttribute>
  </packagedElement>
  <packagedElement xmi:type="uml:Class" xmi:id="_PuKnZ_qnEeKOHL0-05J3_Q" name="Group"/>
</uml:Model>

您会注意到,在User类中, login类型是根据定义的:

 <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>

所以我的问题是:如何处理此案? 确实,我尝试以这种方式解析此文档:

URI typesUri = URI.createFileURI(pathToMyUmlFile);

ResourceSet set = new ResourceSetImpl();
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
set.createResource(typesUri);

Resource r = set.getResource(typesUri, true);

Model model = (Model) EcoreUtil.getObjectByType(r.getContents(), UMLPackage.Literals.MODEL);

但是之后,名为login的我的Property类型为null。

感谢帮助 :)

这是一个普遍的问题。 来自MDT / UML2常见问题解答

resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);

resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Map uriMap = resourceSet.getURIConverter().getURIMap();
URI uri = URI.createURI("jar:file:/C:/eclipse/plugins/org.eclipse.uml2.uml.resources_<version>.jar!/"); // for example
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));

暂无
暂无

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

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