Hi,
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:
Quote: |
java.net.MalformedURLException: 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="http://schema.omg.org/spec/XMI/2.1" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/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="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage" href="../../../workspace/org.objectteams.obtero/Obtero.profile.uml#_cpUIoKYUEd6r-NpAuJ3b6A"/>
</eAnnotations>
<appliedProfile href="../../../workspace/org.objectteams.obtero/Obtero.profile.uml#_dBLoUKYPEd6r-NpAuJ3b6A"/>
</profileApplication>
</uml:Model>
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();
model.setName("TestModel");
model.createNestedPackage("fooPackage");
// 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);
model.applyProfile(obteroProfile);
// 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);
aResource.getContents().add(model);
aResource.save(Collections.EMPTY_MAP);
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="http://schema.omg.org/spec/XMI/2.1" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/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="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage" href="file:/D:/Programme/Master/eclipses/eclipseMaster/workspace/org.objectteams.obtero/Obtero.profile.uml#_cpUIoKYUEd6r-NpAuJ3b6A"/>
</eAnnotations>
<appliedProfile href="file:/D:/Programme/Master/eclipses/eclipseMaster/workspace/org.objectteams.obtero/Obtero.profile.uml#_dBLoUKYPEd6r-NpAuJ3b6A"/>
</profileApplication>
</uml:Model>
So how can I programmaticly add the profile correctly, so the the reference to the profile is correct?
Thank you