Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Standalone program : error loading old model (ns=http://www.eclipse.org/uml2/2.1.0/UML)
Standalone program : error loading old model (ns=http://www.eclipse.org/uml2/2.1.0/UML) [message #1774659] Wed, 18 October 2017 11:27 Go to next message
German Vega is currently offline German VegaFriend
Messages: 44
Registered: December 2015
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 16 times)
  • Attachment: model.old.uml
    (Size: 0.32KB, Downloaded 23 times)

[Updated on: Wed, 18 October 2017 11:34]

Report message to a moderator

Re: Standalone program : error loading old model (ns=http://www.eclipse.org/uml2/2.1.0/UML) [message #1774660 is a reply to message #1774659] Wed, 18 October 2017 11:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5585
Registered: July 2009
Senior Member
Hi

As you have discovered, UMLResourcesUtil.init does many good things that once requirde every 'correct' standalone UML programmer to be an expert. It should do everything, but it may well be imperfect. Please raise a Bugzilla; patch welcome. Are you sure you have initialized all relevant ResourceSets? IIRC initialization of global/local ResourceSets is not an area where all contributors agreed and can lead to some occlusions wrt contentType since when contentTypes were added, EMF added them compatibly at a lower priority than extensions even though a content type is a more precise control.

Writing non-current UML is not supported. It's only software, but rather tricky and would not be much used. I suspect that an M2M transformation may be a better way to go. (And if performance is a concern QVTd is getting increasingly credible as a generator of transformations that execute as Java.)

Regards

Ed Willink
Re: Standalone program : error loading old model (ns=http://www.eclipse.org/uml2/2.1.0/UML) [message #1774668 is a reply to message #1774660] Wed, 18 October 2017 13:22 Go to previous messageGo to next message
German Vega is currently offline German VegaFriend
Messages: 44
Registered: December 2015
Member
Hi Ed,

Thanks for your answer

Quote:

As you have discovered, UMLResourcesUtil.init does many good things that once requirde every 'correct' standalone UML programmer to be an expert.


yes, it has been a neat progress from the previous nightmare ...

Quote:
Are you sure you have initialized all relevant ResourceSets? IIRC initialization of global/local ResourceSets is not an area where all contributors agreed


I am not sure to fully understand your remark, but the exception happens in a resourceSet that is created internally by the resource factory for loading the ecore2xml mapping, not in my resource sets. ... that is why I had to do a global mapping in the workaround ...

Quote:
Please raise a Bugzilla


done, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=526217

I will try to setup a development environment with the UML2 sources to be able to do a patch ... are there any instructions on how to do this?

Quote:
Writing non-current UML is not supported


Ok, I will see what can I do in my transformation

Thanks again

German

Re: Standalone program : error loading old model (ns=http://www.eclipse.org/uml2/2.1.0/UML) [message #1774689 is a reply to message #1774668] Wed, 18 October 2017 15:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5585
Registered: July 2009
Senior Member
Hi

https://bugs.eclipse.org/bugs/show_bug.cgi?id=365026 seems very close to your use case. It should work.

I don't see any instructions for using UML2 sources. It's easy. One plugin at a time by import plugins with sources, or check out all not-deprecated plugins from git://git.eclipse.org/gitroot/uml2/org.eclipse.uml2.git There are quite a few earlier name style. Alternatively just close projects with unhelpful looking errors.

The only real gotcha is codegen, where the JET templates occasionally pop-up a build failed diagnostic. You can just ignore them. IIRC the diagnostics stop if you put emf.codegen.ecore in your workspace.

Regards

Ed Willink
Re: Standalone program : error loading old model (ns=http://www.eclipse.org/uml2/2.1.0/UML) [message #1774696 is a reply to message #1774689] Wed, 18 October 2017 16:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5585
Registered: July 2009
Senior Member
Hi

Again IIRC UMLResourcesUtil arose from my problems in exploiting UML 2.4. Eclipse UML2 was nominally flexible but had stabilized for many years to be almost UML 2.2 only. Co-existence of UML 2.2/2.4 was really painful for users and I insisted on a UMLResourcesUtil. This then required no user side changes for migration to UML 2.5. If you are looking at UML 2.1 you may be looking at a version that was not really considered. You might like to change your example to UML 2.2 and see if that then works.

Regards

Ed Willink
Re: Standalone program : error loading old model (ns=http://www.eclipse.org/uml2/2.1.0/UML) [message #1774748 is a reply to message #1774696] Thu, 19 October 2017 09:45 Go to previous messageGo to next message
German Vega is currently offline German VegaFriend
Messages: 44
Registered: December 2015
Member
Hi ed,

The problem is the same for UML2.2 model files.

But your comment about EcorePlugin.ExtensionProcessor and StandaloneProjectMap in https://bugs.eclipse.org/bugs/show_bug.cgi?id=526217 put me in the right direction.

Indeed, if I use any of the utilities that scans the classpath to register extensions and map plugin URIs , everything works OK.

I have refrained in the past from using EcorePlugin.ExtensionProcessor, because I have users that embed my tool inside OSGi
platforms (like felix and karaf) and I got a lot of problems with EcorePlugin having dependencies on eclipse runtime and equinox
specific bundles ... but there has been progress in that front too : https://bugs.eclipse.org/bugs/show_bug.cgi?id=328227 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=434490

Now I have a solution that works well for eclipse and standalone "main" users, so I just have to figure out the specificities of felix users.

Please consider this as solved.

Thank you a lot

German Vega
Re: Standalone program : error loading old model (ns=http://www.eclipse.org/uml2/2.1.0/UML) [message #1774750 is a reply to message #1774748] Thu, 19 October 2017 10:25 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5585
Registered: July 2009
Senior Member
Hi

One of my integration attempts for UMLResourcesUtil used a full classpath scan; rather expensive. I think that you will find that UMLResourcesUtil.mapUMLResourceURIs is the much more pragmatic equivalent for just a path of interest. You have uncovered another path of interest, so perhaps the need for EcorePlugin.ExtensionProcessor would go away with another UMLResourcesUtil.mapUMLResourceURIs call or two. Patch welcome.

Regards

Ed Willink
Previous Topic:Writing XML file from UML Model misses some data
Next Topic:Standalone: load profile from Papyrus models
Goto Forum:
  


Current Time: Mon Jan 22 20:34:56 GMT 2018

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

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