tags:

views:

544

answers:

2

Hi,

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

A: 

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

Ted Johnson
A: 

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

ShiDoiSi
thanks great, now it works, and the model isn't null anymore
ddejmek