[英]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.