Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » How to load Applied Stereotypes
How to load Applied Stereotypes [message #1720416] Mon, 18 January 2016 14:20 Go to next message
Jean-Marc LARRE is currently offline Jean-Marc LARREFriend
Messages: 5
Registered: January 2016
Junior Member
Hello,

I try, from a standalone Eclipse application to extract the stereotypes applied to a interaction diagram directly with Papyrus.
I found a lot of exemple in this forum and on Eclipse Wiki, I tested all examples but nothing works for me.

See my code :

URI diURI = URI.createFileURI("scenario/checkAllPackage_2_1_002_ErrorYes.uml");
 org.eclipse.uml2.uml.Package package_ = null;

 try {
ResourceSet RESOURCE_SET = new ResourceSetImpl();
UMLResourcesUtil.init(RESOURCE_SET);
Resource resource = RESOURCE_SET.getResource(uri, true);            
           
package_ = (org.eclipse.uml2.uml.Package) EcoreUtil.getObjectByType(resource.getContents(), UMLPackage.Literals.PACKAGE);
            
 } catch (WrappedException we) {
            we.printStackTrace();
            System.exit(1);
 }

EList<Stereotype> list = package_.getModel().getAppliedStereotypes(); :( 


And the "list" is already empty ...

Thank you
Jean-Marc
Re: How to load Applied Stereotypes [message #1720479 is a reply to message #1720416] Mon, 18 January 2016 20:45 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1162
Registered: July 2009
Location: Canada
Senior Member

Hi,

The last statement of your code snippet is:

> EList<Stereotype> list = package_.getModel().getAppliedStereotypes(); :(

which is asking for the stereotypes applied to the nearest element of
type Model that contains the Package retrieved from the contents of the
resource. That model is probably the 'package_', itself, since it is a
root element in the resource.

So, does this particular element actually have stereotypes applied to
it? Or is it elements contained within it (such as elements of the
Interaction) that have stereotypes applied to them? Every element
answers only the stereotypes applied to itself.

HTH,

Christian


On 2016-01-18 20:28:49 +0000, Jean-Marc LARRE said:

> Hello,
>
> I try, from a standalone Eclipse application to extract the stereotypes
> applied to a interaction diagram directly with Papyrus. I found a lot
> of exemple in this forum and on Eclipse Wiki, I tested all examples but
> nothing works for me.
>
> See my code :
>
>
> URI diURI = URI.createFileURI("scenario/checkAllPackage_2_1_002_ErrorYes.uml");
> org.eclipse.uml2.uml.Package package_ = null;
>
> try {
> ResourceSet RESOURCE_SET = new ResourceSetImpl();
> UMLResourcesUtil.init(RESOURCE_SET);
> Resource resource = RESOURCE_SET.getResource(uri, true);
> package_ = (org.eclipse.uml2.uml.Package)
> EcoreUtil.getObjectByType(resource.getContents(),
> UMLPackage.Literals.PACKAGE);
> } catch (WrappedException we) {
> we.printStackTrace();
> System.exit(1);
> }
>
> EList<Stereotype> list = package_.getModel().getAppliedStereotypes(); :(
>
> And the "list" is already empty ...
>
> Thank you
> Jean-Marc
Re: How to load Applied Stereotypes [message #1720539 is a reply to message #1720479] Tue, 19 January 2016 08:52 Go to previous messageGo to next message
Jean-Marc LARRE is currently offline Jean-Marc LARREFriend
Messages: 5
Registered: January 2016
Junior Member
Thank you very much for your answer.

In fact, the stereotype is applied to the interaction diagram (see the screenshot of papyrus).

When I search the stereotype applied to the interaction I don't get any result.

I don't understand how to get the aplied stereotypes ?

Sincerely
Jean-Marc

Re: How to load Applied Stereotypes [message #1720579 is a reply to message #1720539] Tue, 19 January 2016 13:25 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1162
Registered: July 2009
Location: Canada
Senior Member

Hi, Jean-Marc,

If you have the interaction, you just need to ask it for its applied
stereotypes:

Interaction interaction = // ... however you find it in the model tree
doSomethingWith(interaction.getAppliedStereotypes());

The only reasons why this would fail to retrieve all of the stereotypes are:

* the profile application could not resolve the applied profile
* the profile application is out-of-date and the current UML definition
of the profile
does not have the stereotype(s) any longer

The first case is the more likely in the case of code running
stand-alone (outside of the Eclipse run-time environment). Perhaps the
URI scheme of the applied-profile reference is one that requires the
Eclipse context to resolve properly (e.g., if it's a pathmap:// URI,
platform:/plugin/, etc.). This can be addressed by registering URI
mappings with the URIConverter. There are numerous postings on that
subject in this newsgroup.

In any case, debugging the getAppliedStereotypes() call will help you
to understand why no stereotypes are found.

HTH,

Christian


On 2016-01-19 08:52:19 +0000, Jean-Marc LARRE said:

> Thank you very much for your answer.
>
> In fact, the stereotype is applied to the interaction diagram (see the
> screenshot of papyrus).
>
> When I search the stereotype applied to the interaction I don't get any result.
>
> I don't understand how to get the aplied stereotypes ?
>
> Sincerely
> Jean-Marc
>
>
> <image>
icon7.gif  Re: How to load Applied Stereotypes [message #1721177 is a reply to message #1720579] Mon, 25 January 2016 13:43 Go to previous message
Jean-Marc LARRE is currently offline Jean-Marc LARREFriend
Messages: 5
Registered: January 2016
Junior Member
Thank you Christian,

This was my problem. I have resolved my problem to mapping the URI with URIConverter like you said :

URI diURI = URI.createURI("MyUMLFile.uml");
final URL fileURL = new URL(diURI.toString());
final InputStream str = fileURL.openStream();
final URI uri = URI.createURI(fileURL.toString());

ResourceSet resourceSet = new ResourceSetImpl();

		// Standalone Eclipse
		if (!EMFPlugin.IS_ECLIPSE_RUNNING) {
			final Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
			UMLResourcesUtil.init(resourceSet);

			// override wrong pathmap mapping in UMLResourcesUtil
			final URL UMLJarredFileLocation = ResourcesPlugin.class.getResource("ResourcesPlugin.class");
			String UMLJarPath = UMLJarredFileLocation.toString();
			UMLJarPath = UMLJarPath.substring(0, UMLJarPath.indexOf('!'));				
			//uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), URI.createURI(UMLJarPath+ "!/libraries/"));
			//uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), URI.createURI(UMLJarPath+ "!/metamodels/"));				
			uriMap.put(URI.createURI("pathmap://fr.laas.termos.profile/model11.profile.uml"), URI.createURI("file:///Users/jmlarre/ProjetTERMOS/git/fr.laas.termos.profile/model/model11.profile.uml"));
		}

		Resource resource = resourceSet.getResource(uri, true);        

		try {
			resource.load(str, Collections.emptyMap());
		} catch (IOException e) {
			e.printStackTrace();
		}
str.close();


Jean-Marc
Previous Topic:Generate big UML state charts ?
Next Topic:contains an unresolved proxy '<null-named-ProfileImpl>
Goto Forum:
  


Current Time: Tue Jan 23 04:04:16 GMT 2018

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

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