Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Problem loading a UML model with a profile applied
Problem loading a UML model with a profile applied [message #1015482] Thu, 28 February 2013 16:58 Go to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Hello everybody,

I have the following elements
1)A UML profile saved in a eclipse plugin.
2)Another eclipse plugin loading in Java a UML model with the previously defined UML profile applied.

The eclipse plugin is using the following lines to load the profile

Map<URI,URI> uriMap = set.getURIConverter().getURIMap();
URI uml_resource_uri = URI.createURI("jar:file:/path/to/my/plugin/jar/"); 
uriMap.put(URI.createURI("pathmap://resources/"), uml_resource_uri.appendSegment("resources").appendSegment(""));


where "pathmap://resources/" has been defined in the UML profile plugin

   <extension
         point="org.eclipse.emf.ecore.uri_mapping">
      <mapping
            source="pathmap://resources/"
            target="platform:/plugin/path/to/the/profile">
      </mapping>
   </extension>


This mechanism works, i.e., I am able to load a UML model with the profile applied and to read the stereotypes.
However I want to use a different mechanism to avoid using the path to the profile in the code, i.e. URI uml_resource_uri = URI.createURI("jar:file:/path/to/my/plugin/jar/");

Reading this tutorial it seems possible
http://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_load_a_UML_.28.uml.29_resource_from_a_standalone_application.3F
but I have not been able to do that

Any help? Crying or Very Sad
Thank you

[Updated on: Thu, 28 February 2013 17:00]

Report message to a moderator

Re: Load profile in Eclipse plugin project [message #1015484 is a reply to message #1015482] Thu, 28 February 2013 17:08 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

See

https://bugs.eclipse.org/bugs/show_bug.cgi?id=382342

and

https://bugs.eclipse.org/bugs/show_bug.cgi?id=401682

Regards

Ed Willink


On 28/02/2013 16:58, Alfredo Motta wrote:
> Hello everybody,
>
> I have the following elements
> 1)A UML profile saved in a eclipse plugin.
> 2)Another eclipse plugin loading using Java a UML model with the
> previously defined UML profile.
>
> The eclipse plugin is using the following lines to load the profile
>
>
> Map<URI,URI> uriMap = set.getURIConverter().getURIMap();
> URI uml_resource_uri =
> URI.createURI("jar:file:/path/to/my/plugin/jar/");
> uriMap.put(URI.createURI("pathmap://resources/"),
> uml_resource_uri.appendSegment("resources").appendSegment(""));
>
>
> where "pathmap://resources/" has been defined in the UML profile plugin
>
>
> <extension
> point="org.eclipse.emf.ecore.uri_mapping">
> <mapping
> source="pathmap://resources/"
> target="platform:/plugin/path/to/the/profile">
> </mapping>
> </extension>
>
>
> This mechanism works, i.e., I am able to load a UML model with the
> profile applied and to read the stereotypes.
> However I want to use a different mechanism to avoid using the path to
> the profile in the code, i.e. URI uml_resource_uri =
> URI.createURI("jar:file:/path/to/my/plugin/jar/");
>
> Reading this tutorial it seems possible
> http://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_load_a_UML_.28.uml.29_resource_from_a_standalone_application.3F
>
> but I have not been able to do that
>
> Any help? :cry: Thank you
>
>
Re: Load profile in Eclipse plugin project [message #1015493 is a reply to message #1015484] Thu, 28 February 2013 19:03 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Dear Ed,

thank you for your help. I read your links but I am not sure I got the point.

My application that is loading the UML model is an Eclipse plugin, not a simple standalone Java application. Does this make any difference?

From the wiki my understanding is that in the plugin reading the model I can use these extension points

* org.eclipse.emf.ecore.generated_package
* org.eclipse.emf.ecore.extension_parser
* and org.eclipse.emf.ecore.uri_mapping

to skip these lines

Map<URI,URI> uriMap = set.getURIConverter().getURIMap();
URI uml_resource_uri = 
URI.createURI("jar:file:/path/to/my/plugin/jar/"); 
uriMap.put(URI.createURI("pathmap://resources/"), 
uml_resource_uri.appendSegment("resources").appendSegment(""));


This is the text of the wiki I am referring to

Quote:

In order to load a UML (.uml) resource, the package (schema), resource factory, and "pathmaps" for UML need to be registered. On the Eclipse platform, this is done through the org.eclipse.emf.ecore.generated_package, org.eclipse.emf.ecore.extension_parser, and org.eclipse.emf.ecore.uri_mapping extension points (see the plug-in manifests for the org.eclipse.uml2.uml and org.eclipse.uml2.uml.resources plug-ins).


am I wrong?
Thank you

[Updated on: Thu, 28 February 2013 19:05]

Report message to a moderator

Re: Load profile in Eclipse plugin project [message #1015497 is a reply to message #1015482] Thu, 28 February 2013 19:42 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I've no idea what on earth you're trying to do.

But "jar:file:/path/to/my/plugin/jar/" only makes sense in a standalone
context for which I provided some links.

I completely agree that those lines are stupid in an Eclipse context.

Regards

Ed Willink

On 28/02/2013 16:58, Alfredo Motta wrote:
> Hello everybody,
>
> I have the following elements
> 1)A UML profile saved in a eclipse plugin.
> 2)Another eclipse plugin loading using Java a UML model with the
> previously defined UML profile.
>
> The eclipse plugin is using the following lines to load the profile
>
>
> Map<URI,URI> uriMap = set.getURIConverter().getURIMap();
> URI uml_resource_uri =
> URI.createURI("jar:file:/path/to/my/plugin/jar/");
> uriMap.put(URI.createURI("pathmap://resources/"),
> uml_resource_uri.appendSegment("resources").appendSegment(""));
>
>
> where "pathmap://resources/" has been defined in the UML profile plugin
>
>
> <extension
> point="org.eclipse.emf.ecore.uri_mapping">
> <mapping
> source="pathmap://resources/"
> target="platform:/plugin/path/to/the/profile">
> </mapping>
> </extension>
>
>
> This mechanism works, i.e., I am able to load a UML model with the
> profile applied and to read the stereotypes.
> However I want to use a different mechanism to avoid using the path to
> the profile in the code, i.e. URI uml_resource_uri =
> URI.createURI("jar:file:/path/to/my/plugin/jar/");
>
> Reading this tutorial it seems possible
> http://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_load_a_UML_.28.uml.29_resource_from_a_standalone_application.3F
>
> but I have not been able to do that
>
> Any help? :cry: Thank you
>
>
Re: Load profile in Eclipse plugin project [message #1015577 is a reply to message #1015497] Fri, 01 March 2013 09:25 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Quote:
I've no idea what on earth you're trying to do.


I started using a standalone Java application to load my models and now I am trying to move away and use the Eclipse platform (but I have no big expertise on that).

Quote:
But "jar:file:/path/to/my/plugin/jar/" only makes sense in a standalone
context for which I provided some links.

I completely agree that those lines are stupid in an Eclipse context.


What should I do then? I have no clue on how to use org.eclipse.emf.ecore.generated_package, org.eclipse.emf.ecore.extension_parser, and org.eclipse.emf.ecore.uri_mapping. Any documentation/tutorial around?

This is what I tried out to leave out the same lines for the UML metamodel/libraries/profiles, but I did not succeed.
I replaced this code

ResourceSet set = new ResourceSetImpl();	
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
URI uml_resource_uri = URI.createURI("jar:file:/C:/Users/motta/Desktop/Dottorato/UML2ZOT/eu.mades.uml2zot/lib/org.eclipse.uml2.uml.resources_4.0.0.v20120604-0919.jar!/"); // for example
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uml_resource_uri.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uml_resource_uri.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uml_resource_uri.appendSegment("profiles").appendSegment(""));


with the previously mentioned extensions in my plugin.xml

   <extension
         id="pathmap://UML_LIBRARIES/"
         point="org.eclipse.emf.ecore.uri_mapping">
      <mapping
            source="pathmap://UML_LIBRARIES/"
            target="platform:/plugin/org.eclipse.uml2.uml.resources/libraries/">
      </mapping>
   </extension>
   <extension
         point="org.eclipse.emf.ecore.uri_mapping">
      <mapping
            source="pathmap://UML_PROFILES/"
            target="platform:/plugin/org.eclipse.uml2.uml.resources/profiles/">
      </mapping>
   </extension>
   <extension
         point="org.eclipse.emf.ecore.uri_mapping">
      <mapping
            source="pathmap://UML_METAMODELS/"
            target="platform:/plugin/org.eclipse.uml2.uml.resources/metamodels/">
      </mapping>
   </extension>
   <extension
         point="org.eclipse.emf.ecore.extension_parser">
      <parser
            class="org.eclipse.uml2.uml.internal.resource.UMLResourceFactoryImpl"
            type="uml">
      </parser>
   </extension>
   <extension
         point="org.eclipse.emf.ecore.generated_package">
      <package
            class="org.eclipse.uml2.uml.UMLPackage"
            uri="http://www.eclipse.org/uml2/4.0.0/UML">
      </package>
   </extension>


But this way is not working anymore, i.e. my imports are not resolved (for example if I refer to an Integer primitive type in my model, he is not able to find it)

Is it the correct way of using these extensions?
Thank you for your help

[Updated on: Fri, 01 March 2013 09:26]

Report message to a moderator

Re: Load profile in Eclipse plugin project [message #1015644 is a reply to message #1015577] Fri, 01 March 2013 14:04 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Alfredo,

In the Eclipse context, EMF's and UML's plug-in extensions do
everything for you. Your code is going out of the way to undo what
Eclipse is already doing.

You can reduce your latest code excerpt to just this:

-------- 8< --------

ResourceSet set = new ResourceSetImpl();

-------- >8 --------

You don't need to add any URI mapping, extension parser, generated
package, or other extensions in your own plugin.xml. These are already
provided by the UML plug-in.

HTH,

Christian


On 2013-03-01 09:25:41 +0000, Alfredo Motta said:

> Quote:
>> I've no idea what on earth you're trying to do.
>
>
> I started using a standalone Java application to read my models and now
> I am trying to move away and use the Eclipse platform (but I have no
> big expertise on that).
>
> Quote:
>> But "jar:file:/path/to/my/plugin/jar/" only makes sense in a standalone
>> context for which I provided some links.
>>
>> I completely agree that those lines are stupid in an Eclipse context.
>
>
> What should I do then? I have no clue on how to use
> org.eclipse.emf.ecore.generated_package,
> org.eclipse.emf.ecore.extension_parser, and
> org.eclipse.emf.ecore.uri_mapping. Any documentation/tutorial around?
>
> This is what I tried out to leave out the same lines for the UML
> metamodel/libraries/profiles, but I did not succeed.
> I replaced this code
>
>
> ResourceSet set = new ResourceSetImpl();
> set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
> set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> URI uml_resource_uri =
> URI.createURI("jar:file:/C:/Users/motta/Desktop/Dottorato/UML2ZOT/eu.mades.uml2zot/lib/org.eclipse.uml2.uml.resources_4.0.0.v20120604-0919.jar!/");
> // for example
> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
> uml_resource_uri.appendSegment("libraries").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
> uml_resource_uri.appendSegment("metamodels").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
> uml_resource_uri.appendSegment("profiles").appendSegment(""));
>
>
> with the previously mentioned extensions in my plugin.xml
>
>
> <extension
> id="pathmap://UML_LIBRARIES/"
> point="org.eclipse.emf.ecore.uri_mapping">
> <mapping
> source="pathmap://UML_LIBRARIES/"
>
> target="platform:/plugin/org.eclipse.uml2.uml.resources/libraries/">
> </mapping>
> </extension>
> <extension
> point="org.eclipse.emf.ecore.uri_mapping">
> <mapping
> source="pathmap://UML_PROFILES/"
> target="platform:/plugin/org.eclipse.uml2.uml.resources/profiles/">
> </mapping>
> </extension>
> <extension
> point="org.eclipse.emf.ecore.uri_mapping">
> <mapping
> source="pathmap://UML_METAMODELS/"
>
> target="platform:/plugin/org.eclipse.uml2.uml.resources/metamodels/">
> </mapping>
> </extension>
> <extension
> point="org.eclipse.emf.ecore.extension_parser">
> <parser
>
> class="org.eclipse.uml2.uml.internal.resource.UMLResourceFactoryImpl"
> type="uml">
> </parser>
> </extension>
> <extension
> point="org.eclipse.emf.ecore.generated_package">
> <package
> class="org.eclipse.uml2.uml.UMLPackage"
> uri="http://www.eclipse.org/uml2/4.0.0/UML">
> </package>
> </extension>
>
>
> But this way is not working anymore, i.e. my imports are not resolved
> (for example if I refer to an Integer primitive type in my model, he is
> not able to find it)
>
> Is it the correct way of using these extensions? Thank you for your help
Re: Load profile in Eclipse plugin project [message #1015659 is a reply to message #1015577] Fri, 01 March 2013 15:02 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
I solved like this

//A collection of related persistent documents.
ResourceSet set = new ResourceSetImpl();
		
//Register the UML Package
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.PROFILE_FILE_EXTENSION, UMLResource.Factory.INSTANCE );
		
Map<URI,URI> uriMap = set.getURIConverter().getURIMap();
URI uml_resource_uri = URI.createPlatformPluginURI("org.mycompanyname.profileplugin", true);
uriMap.put(URI.createURI("pathmap://resources/"), uml_resource_uri.appendSegment("resources").appendSegment(""));
		
uml_resource_uri = URI.createPlatformPluginURI("org.eclipse.uml2.uml.resources", true);
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uml_resource_uri.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uml_resource_uri.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uml_resource_uri.appendSegment("profiles").appendSegment(""));


With this code and running the application as an Eclipse application
I am able to load the model correctly with my profile and the UML metamodel/libraries/profiles.

The code is not anymore dependent on the paths of my machine

Thank you for your help

PS: an alternative is to use the extensions of the plugin.xml as I said previously, but I have to check. Previously I was not running my code as an Ecliplse application, therefore it was not working. My fault.

[Updated on: Fri, 01 March 2013 15:05]

Report message to a moderator

Re: Load profile in Eclipse plugin project [message #1015696 is a reply to message #1015659] Fri, 01 March 2013 19:14 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Alfredo,

I'm glad that it's working for you now, but none of this is necessary
in an Eclipse plug-in. You can save a lot of code!

cW


On 2013-03-01 15:02:41 +0000, Alfredo Motta said:

> I solved like this
>
>
> //A collection of related persistent documents.
> ResourceSet set = new ResourceSetImpl();
>
> //Register the UML Package
> set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
> set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.PROFILE_FILE_EXTENSION,
> UMLResource.Factory.INSTANCE );
>
> Map<URI,URI> uriMap = set.getURIConverter().getURIMap();
> URI uml_resource_uri =
> URI.createPlatformPluginURI("org.mycompanyname.profileplugin", true);
> uriMap.put(URI.createURI("pathmap://resources/"),
> uml_resource_uri.appendSegment("resources").appendSegment(""));
>
> uml_resource_uri =
> URI.createPlatformPluginURI("org.eclipse.uml2.uml.resources", true);
> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
> uml_resource_uri.appendSegment("libraries").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
> uml_resource_uri.appendSegment("metamodels").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
> uml_resource_uri.appendSegment("profiles").appendSegment(""));
>
>
> With this code and running the application as an Eclipse application I
> am able to load the model correctly with my profile and the UML
> metamodel/libraries/profiles.
>
> The code is not anymore dependent on the paths of my machine
>
> Thank you for your help
Re: Load profile in Eclipse plugin project [message #1015723 is a reply to message #1015696] Fri, 01 March 2013 21:45 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Indeed, all these registrations are performed automatically through
plugin extensions when running within Eclipse.

Kenn

On 13-03-01 2:14 PM, Christian W. Damus wrote:
> Hi, Alfredo,
>
> I'm glad that it's working for you now, but none of this is necessary in
> an Eclipse plug-in. You can save a lot of code!
>
> cW
>
>
> On 2013-03-01 15:02:41 +0000, Alfredo Motta said:
>
>> I solved like this
>>
>>
>> //A collection of related persistent documents.
>> ResourceSet set = new ResourceSetImpl();
>>
>> //Register the UML Package
>> set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>> set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
>> UMLResource.Factory.INSTANCE);
>> set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.PROFILE_FILE_EXTENSION,
>> UMLResource.Factory.INSTANCE );
>>
>> Map<URI,URI> uriMap = set.getURIConverter().getURIMap();
>> URI uml_resource_uri =
>> URI.createPlatformPluginURI("org.mycompanyname.profileplugin", true);
>> uriMap.put(URI.createURI("pathmap://resources/"),
>> uml_resource_uri.appendSegment("resources").appendSegment(""));
>>
>> uml_resource_uri =
>> URI.createPlatformPluginURI("org.eclipse.uml2.uml.resources", true);
>> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
>> uml_resource_uri.appendSegment("libraries").appendSegment(""));
>> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
>> uml_resource_uri.appendSegment("metamodels").appendSegment(""));
>> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
>> uml_resource_uri.appendSegment("profiles").appendSegment(""));
>>
>>
>> With this code and running the application as an Eclipse application I
>> am able to load the model correctly with my profile and the UML
>> metamodel/libraries/profiles.
>>
>> The code is not anymore dependent on the paths of my machine
>>
>> Thank you for your help
>
>
Previous Topic:Re: CacheAdapter performance issue
Next Topic:Create Papyrus Project From UML file Using Java
Goto Forum:
  


Current Time: Thu Mar 28 21:43:33 GMT 2024

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

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

Back to the top