Pregunta

I use UML2 to parse a XMI file which contains an UML shema.

Here is the content of my .uml generated by Modelio :

<?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>

You can notice that in the User class, the type of login is defined according to :

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

So my question is : How to manage this case ? Indeed, I try to parse this document in this way :

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);

But after that the type of my Property named login is null.

Thanks for help :)

¿Fue útil?

Solución

This is a common issue. From the MDT/UML2 FAQ :

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(""));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top