Standalone program : error loading old model (ns=http://www.eclipse.org/uml2/2.1.0/UML) [message #1774659] |
Wed, 18 October 2017 11:27 |
German Vega Messages: 104 Registered: December 2015 Location: Grenoble, France |
Senior Member |
|
|
Hello
I work in a stand-alone tool that transforms UML models. I setup my environment using UMLResourcesUtil.init.
Everything worked nicely, until one of my users tried to transform and old UML2 file (created with Topcased, namespace http://www.eclipse.org/uml2/2.1.0/UML), and
there I got an exception loading the resource :
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: java.net.MalformedURLException: unknown protocol: platform
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
at org.eclipse.uml2.uml.internal.resource.UML212UMLResourceFactoryImpl.createResource(UML212UMLResourceFactoryImpl.java:96)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:434)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandCreateResource(ResourceSetImpl.java:243)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:400)
at Main.main(Main.java:60)
Debugging the code, I noticed that the good content type is registered for namespace http://www.eclipse.org/uml2/2.1.0/UML, so it finds the good factory UML212UMLResourceFactoryImpl. But the factory tries (see code below) to load an ecore2xml file with an platform:/plugin URI that is not mapped by
UMLResourcesUtil
Ecore2XMLRegistry ecore2xmlRegistry = new Ecore2XMLRegistryImpl(
Ecore2XMLRegistry.INSTANCE);
ecore2xmlRegistry
.put(
UML212UMLResource.UML_METAMODEL_NS_URI,
EcoreUtil
.getObjectByType(
resourceSet
.getResource(
URI
.createURI("platform:/plugin/org.eclipse.uml2.uml/model/UML21_2_UML.ecore2xml"), //$NON-NLS-1$
true).getContents(),
Ecore2XMLPackage.Literals.XML_MAP));
I think the same problem will happen for XMI and CMOF files, as all the factories have similar code.
As a workaround, I have added in my program a mapping to the ecore2xml models directory :
/*
* This is the workaround for loading legacy uml2 models.
*
* Notice that the mapping is added to the global registry, because the factory is trying to load
* the ecore2xml model in a private resourceSet (not in ours)
*/
boolean workaround = true;
if (workaround) {
try {
URI umlMetamodel = URI.createPlatformPluginURI("/org.eclipse.uml2.uml/model/UML.ecore",true);
URL umlMetamodelLocation = UMLPlugin.class.getResource("/model/"+umlMetamodel.lastSegment());
URI umlMetamodelPhysicalURI = URI.createURI(umlMetamodelLocation.toURI().toString(),true);
URIConverter.URI_MAP.put(umlMetamodel.trimSegments(1).appendSegment(""),umlMetamodelPhysicalURI.trimSegments(1).appendSegment(""));
}
catch (URISyntaxException ignored) {}
}
the workaround is working. So the question is if this is a bug (some corner case not considered in UMLResourcesUtil.init) or am I missing the invocation of some other
method responsible of doing this mapping?
I join my test program (with the workaround) and a test file, I have tested in UML2 5.2.4 (but browsing the 5.3 sources I see the same code).
Another, unrelated, question, is there a way to save the resource with the old namespace and XMI format? currently when I save the resource (even using the UMLResource.UML_2_1_0_CONTENT_TYPE_IDENTIFIER content type), it is automatically upgraded to the new metamodel (http://www.eclipse.org/uml2/5.0.0/UML). See
the end of the attached Main file for my saving code. My user has some legacy tool that works only with topcased so it will be good if I preserve the format. My tool
modifies the model, but mainly by adding annotations and stereotypes, no structural changes.
Thanks for the help
German Vega
-
Attachment: Main.java
(Size: 3.44KB, Downloaded 212 times) -
Attachment: model.old.uml
(Size: 0.32KB, Downloaded 295 times)
[Updated on: Wed, 18 October 2017 11:34] Report message to a moderator
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03470 seconds