简体   繁体   中英

Eclipse Modelling Framework (EMF): How to get the DomainModel from a Magicdraw UML2 Export

I want to use the EMF for Code Generation, so I wrote some methods to load my UML2 File which I generated myself. This works fine with the following code:

protected void registerResources() {
    resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);

    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

    Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
    String resourcesJarPath = Thread.currentThread().getContextClassLoader().getResource("org.eclipse.uml2.uml.resources_2.2.0.v200805131030").toExternalForm();
    URI baseUri = URI.createURI(resourcesJarPath);
    uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), baseUri.appendSegment("libraries").appendSegment(""));
    uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), baseUri.appendSegment("metamodels").appendSegment(""));
    uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), baseUri.appendSegment("profiles").appendSegment(""));
}

public Package loadPackage(URI uri) {
    Resource resource = resourceSet.getResource(uri, true);
    return (Package) EcoreUtil.getObjectByType(resource.getContents(), UMLPackage.Literals.PACKAGE);
}

But now, I wanted to export an Magicdraw-Domainmodel to an EMF UML2 XMI, and there I get 5 Files. One project.uml and 4 Profile Files (UML_Standard_Profile.MagicDraw_Profile.DSL_Customization.profile.uml, UML_Standard_Profile.MagicDraw_Profile.profile.uml, UML_Standard_Profile.UML_Standard_Profile.profile.uml, UML_Standard_Profile.Validation_Profile.profile.uml). So if I want to load the project.uml with the loadPackageclass, my Package is null.

Does anyone have an example app, how to load an MagicDraw-exported UML DomainModel?

Dominik

Could you show us the first few lines of the UML model from MagicDraw (as XMI)? Here, for some models I need an additional

resourceSet.getPackageRegistry().put("http://www.eclipse.org/uml2/2.0.0/UML", UMLPackage.eINSTANCE);

to load those models (which admittedly come from an older MD version, in Eclipse 3.4.2).

Source: http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.uml2/msg01517.html

For EMF UML :

import org.eclipse.uml2.uml.util.UMLUtil; Profile myProfile = UMLUtil.getProfile(MyProfilePackage.eINSTANCE, ... )

In the email chain I found on this they also showed how to hook it to a model - which should be helpful to you as well.

The question asker did not seem to get it, but it makes sense to me and is similar to the methods you use for IBM RSA.

IBM RSA:

File f = new File(...); Profile p = UMLModeler.openProfile(f.getAbsolutePath());

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