Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 Tools » Programmaticly load a profile and apply it to a model
Programmaticly load a profile and apply it to a model [message #624873] Sun, 20 September 2009 20:32
No real name is currently offline No real nameFriend
Messages: 61
Registered: July 2009

I want to create an uml-model and apply a profile to it.

Unfortunatly my code does not create the right references to the profile. If I use my code, I get this error when I try to open my model in the editor:
> Unsupported "platform:" protocol variation "workspace".

The created test-model consists only of a package "foobar" and is trying to apply the profile on the root-package (the "Model"-element):

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="" xmlns:ecore="" xmlns:uml="" xmi:id="_ekONwKYiEd6SSq16ArdipQ" name="TestModel">
<packagedElement xmi:type="uml:Package" xmi:id="_ekONwaYiEd6SSq16ArdipQ" name="fooPackage"/>
<profileApplication xmi:id="_ekONwqYiEd6SSq16ArdipQ">
<eAnnotations xmi:id="_ekONw6YiEd6SSq16ArdipQ" source="">
<references xmi:type="ecore:EPackage" href=" ../../../workspace/org.objectteams.obtero/Obtero.profile.uml #_cpUIoKYUEd6r-NpAuJ3b6A "/>
<appliedProfile href=" ../../../workspace/org.objectteams.obtero/Obtero.profile.uml #_dBLoUKYPEd6r-NpAuJ3b6A "/>

Here is the code, which creates this model, loads the profile, applies the profile to the model and saves the model:

ResourceSet resourceSet = new ResourceSetImpl();
UMLFactory umlFac = UMLFactory.eINSTANCE;
IProject project = selectedFolder.getCorrespondingResource().getProject();

// create model

Model model = umlFac.createModel();

// apply obtero-profile

URL modelURL = FileLocator.find(Activator.getDefault().getBundle(), new Path("Obtero.profile.uml"), null);
modelURL = FileLocator.toFileURL(modelURL);
String absolutePath = modelURL.getPath();
URI uri = URI.createFileURI(absolutePath);

Resource resource = resourceSet.getResource(uri, true);
Profile obteroProfile = (Profile) EcoreUtil.getObjectByType(resource.getContents(), UMLPackage.Literals.PACKAGE);

// save model

IPath sourcePath = Path.fromPortableString("model");
if( !project.getFolder(sourcePath).exists() )
project.getFolder(sourcePath).create(true, true, null);
IFolder modelFolder = project.getFolder(sourcePath);

String fileName = model.getName() + ".uml";
IFile file = modelFolder.getFile(fileName);
String path = file.getLocation().toFile().getAbsolutePath();
URI fileURI = URI.createFileURI(path);
Resource aResource = resourceSet.createResource(fileURI);

It works if I comment out the line "model.applyProfile(obteroProfile);" (and thus not applying the profile in code) and then apply the profile manually (by using "UML Editor"->"Load Ressource" for loading the profile-model and then "UML Editor"->"Package"->"Apply Profile" for applying the profile). Then the (correct) model looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="" xmlns:ecore="" xmlns:uml="" xmi:id="_5OajAKYjEd6SSq16ArdipQ" name="TestModel">
<packagedElement xmi:type="uml:Package" xmi:id="_5OajAaYjEd6SSq16ArdipQ" name="fooPackage"/>
<profileApplication xmi:id="_9M4jsKYjEd6SSq16ArdipQ">
<eAnnotations xmi:id="_9M5KwKYjEd6SSq16ArdipQ" source="">
<references xmi:type="ecore:EPackage" href=" file:/D:/Programme/Master/eclipses/eclipseMaster/workspace/o rg.objectteams.obtero/Obtero.profile.uml#_cpUIoKYUEd6r-NpAuJ 3b6A "/>
<appliedProfile href=" file:/D:/Programme/Master/eclipses/eclipseMaster/workspace/o rg.objectteams.obtero/Obtero.profile.uml#_dBLoUKYPEd6r-NpAuJ 3b6A "/>

So how can I programmaticly add the profile correctly, so the the reference to the profile is correct?

Thank you
Previous Topic:Programmaticly load a profile and apply it to a model
Next Topic:Re: Create UML diagrams programatically
Goto Forum:

Current Time: Fri May 26 21:01:38 GMT 2017

Powered by FUDForum. Page generated in 0.03064 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software