Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Unable to read the stereotypes from Papyrus SysML model in standalone mode(The applied stereotypes list is always empty when reading a papyrus SysML model, in standalone mode)
icon5.gif  Unable to read the stereotypes from Papyrus SysML model in standalone mode [message #875878] Wed, 23 May 2012 09:43 Go to next message
premshaw kaliyamoorthi is currently offline premshaw kaliyamoorthi
Messages: 2
Registered: May 2012
Junior Member
Hi All,

I am trying to parse and understand a Papyrus SysML model in standalone mode. I have included my java code as well as the test model.

I am not able to read the stereotype information of a UML class which is modeled as a SysML Block.
'type.getAppliedStereotypes()'
always returns empty list.

Initially all the SysML profiles appeared to be proxy except the standard when I loaded the model. '
getOwnedStereotypes()'
method returned empty list for all the SysML profiles(Blocks,...) found in the model.

I am not sure how to resolve these proxies (
'org.eclipse.uml2.uml.internal.impl.ProfileImpl@1461b5b (eProxyURI: platform:/plugin/com.cea.papyrus.uml4sysml.extension/model/SysML.profile.uml#_Gx8MgLX7EduFmqQsrNB9lw)' ).


'EcoreUtil.resolveAll(resourceSet)'
did not resolve anything.

I tried something stupid quickly, I added the following two lines,

'uriMap.put(URI.createURI("platform:/plugin/com.cea.papyrus.uml4sysml.extension/model/"), uri_sysml.appendSegment("model").appendSegment(""));
		uriMap.put(URI.createURI("platform:/plugin/com.cea.papyrus.uml4sysml.extension/libraries/"), uri_sysml.appendSegment("libraries").appendSegment(""));'


It appeared to have resolved the proxy issue.
'getOwnedStereotypes()'
method returned a list of stereotypes for all the SysML profiles. But still
'type.getAppliedStereotypes()'
returned empty list in the model.

I tried my best to ensure that the package registry, URI map and the extension maps are initialized properly (I used the plugin properties of all the resource jars and forum to do it).

Please refer the .classpath file in my attachments for the list of jar files and their versions.

Any help is greatly appreciated. Thanks in advance.

Cheers,
Prem.

standalone app code:
public static void main(String[] args) throws IOException {
		
		ResourceSet resourceSet = new ResourceSetImpl();
		
		resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.eclipse.org/uml2/2.0.0/UML", UMLPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.eclipse.org/uml2/2.1.0/UML", UMLPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.eclipse.org/uml2/1.0.0/UML", UMLPackage.eINSTANCE);
		
		resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.eclipse.org/emf/2003/XMLType", XMLTypePackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.w3.org/XML/1998/namespace", XMLNamespacePackage.eINSTANCE);
		
		resourceSet.getPackageRegistry().put("http:\\www.eclipse.org/uml2/schemas/Ecore/5", EcorePackage.eINSTANCE);
		resourceSet.getPackageRegistry().put( Ecore2XMLPackage.eNS_URI, Ecore2XMLPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put( Ecore2EcorePackage.eNS_URI, Ecore2EcorePackage.eINSTANCE);		
		
		
		resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/UML/2.2", UMLPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/UML/2.1", UMLPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/UML/2.1.1", UMLPackage.eINSTANCE);
				
		resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/MOF/2.0/cmof.xml", UMLPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/mof/2.0/emof.xml", UMLPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/MOF/2.0/emof.xml", UMLPackage.eINSTANCE);
		
		resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/1", SysmlPackage.eINSTANCE);		
		resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Blocks/1", BlocksPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/PortAndFlows/1", PortandflowsPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Constraints/1", ConstraintsPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Activities/1", ActivitiesPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Allocations/1", AllocationsPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Requirements/1", RequirementsPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Interactions/1", InteractionsPackage.eINSTANCE);
		resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/StateMachines/1", StatemachinesPackage.eINSTANCE);							
				
		Map<String, Object> extensionToFactoryMap = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
		
		extensionToFactoryMap.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
		extensionToFactoryMap.put(UMLResource.PROFILE_FILE_EXTENSION, UMLResource.Factory.INSTANCE );
		
		extensionToFactoryMap.put("xmi", XMI2UMLResource.Factory.INSTANCE);
		extensionToFactoryMap.put("profile.xmi", XMI2UMLResource.Factory.INSTANCE );
		
		extensionToFactoryMap.put("ecore", new EcoreResourceFactoryImpl());
		
		extensionToFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,Ecore2XMLResource.Factory.INSTANCE);
		extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,UML22UMLResource.Factory.INSTANCE);
		//extensionToFactoryMap.put(UML212UMLResource.FILE_EXTENSION,UML212UMLResource.Factory.INSTANCE);
		
		extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, UMLResource.Factory.INSTANCE);		
				
		Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
		
		String rootdirPath = ..................;
		
		/**
		 * registering URI map for UML resources.
		 */
		URI uri = URI.createURI("jar:file:/"+ rootdirPath + "/lib/eclipse_lib/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar!/");
		uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
		uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
		uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));		
		
		/**
		 * registering URI map for SysML resources.
		 */
		URI uri_sysml = URI.createURI("jar:file:/"+ rootdirPath + "/lib/eclipse_lib/com.cea.papyrus.uml4sysml.extension_1.2.0.jar!/");		
		uriMap.put(URI.createURI("pathmap://SysML_PROFILES/"), uri_sysml.appendSegment("model").appendSegment(""));
		uriMap.put(URI.createURI("pathmap://SysML_LIBRARIES/"), uri_sysml.appendSegment("libraries").appendSegment(""));
		
		uriMap.put(URI.createURI("platform:/plugin/com.cea.papyrus.uml4sysml.extension/model/"), uri_sysml.appendSegment("model").appendSegment(""));
		uriMap.put(URI.createURI("platform:/plugin/com.cea.papyrus.uml4sysml.extension/libraries/"), uri_sysml.appendSegment("libraries").appendSegment(""));
		
	
		Resource resource = resourceSet.getResource(URI.createFileURI("................\\umlExample1.uml"), true);		
		
		EcoreUtil.resolveAll(resourceSet);
		
		TreeIterator itr = EcoreUtil.getAllContents(resource, true);
	
		while (itr.hasNext()) {			
		
			Object type_1 = itr.next();
			if (type_1 instanceof EObject)
				EcoreUtil.resolveAll((EObject)type_1);
			if (type_1 instanceof NamedElement) {
				NamedElement type = (NamedElement) type_1;				
				System.out.println(type.getName() + " : " + type.getAppliedStereotypes().size());	
			}
			if (type_1 instanceof ProfileApplication) {
				ProfileApplication type = (ProfileApplication) type_1;				
				System.out.println(type.getAppliedProfile().getName() + ":" + type.getAppliedProfile().eIsProxy() +  " : " + type.getAppliedStereotypes().size()
						 + " : " + type.getAppliedProfile().getOwnedStereotypes().size());				
			}
			
			if (type_1 instanceof AnyTypeImpl) {
				
				System.out.println("AnyType : " + ((AnyTypeImpl)type_1).toString());
			}
			
			System.out.println(type_1.toString());
		}		
	}
  • Attachment: umlExample1.di2
    (Size: 0.60KB, Downloaded 97 times)
  • Attachment: Test.java
    (Size: 8.10KB, Downloaded 87 times)
  • Attachment: umlExample1.uml
    (Size: 6.57KB, Downloaded 87 times)
  • Attachment: .classpath
    (Size: 13.80KB, Downloaded 111 times)
Re: Unable to read the stereotypes from Papyrus SysML model in standalone mode [message #875948 is a reply to message #875878] Wed, 23 May 2012 11:46 Go to previous messageGo to next message
Hela Hakim is currently offline Hela Hakim
Messages: 20
Registered: May 2012
Junior Member
Hello all,
I apologize if I'm not in the right place this is my first visit, in fact I wanted to ask how to model Stereotypes Jacobson (UML2) as papyrus and thank you in advance.
Re: Unable to read the stereotypes from Papyrus SysML model in standalone mode [message #875949 is a reply to message #875948] Wed, 23 May 2012 11:47 Go to previous messageGo to next message
Hela Hakim is currently offline Hela Hakim
Messages: 20
Registered: May 2012
Junior Member
No Message Body
Re: Unable to read the stereotypes from Papyrus SysML model in standalone mode [message #877163 is a reply to message #875878] Fri, 25 May 2012 21:27 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
Hi,

See some replies in-line, below.

HTH,

Christian


On 2012-05-23 13:43:40 +0000, premshaw kaliyamoorthi said:

> Hi All,
>
> I am trying to parse and understand a Papyrus SysML model in standalone
> mode. I have included my java code as well as the test model.
>
> I am not able to read the stereotype information of a UML class which
> is modeled as a SysML Block. 'type.getAppliedStereotypes()' always
> returns empty list.
>
> Initially all the SysML profiles appeared to be proxy except the
> standard when I loaded the model. 'getOwnedStereotypes()' method
> returned empty list for all the SysML profiles(Blocks,...) found in the
> model.
>
> I am not sure how to resolve these proxies (
> 'org.eclipse.uml2.uml.internal.impl.ProfileImpl@1461b5b (eProxyURI:
> platform:/plugin/com.cea.papyrus.uml4sysml.extension/model/SysML.profile.uml#_Gx8MgLX7EduFmqQsrNB9lw)'
> ).

Resolving references to objects in other resources requires providing
the EMF run-time with the means to resolve the resource URIs to
"physical" URIs of some kind that are supported by the Java platform
via URL connections. Typically, these are "file", "http", and "jar:"
URIs. In an Eclipse context, we have also "platform:" scheme, but
you're running stand-alone.

So, any references to "platform:" scheme URIs have to be mapped using a
URIConverter's URI map to a "physical URI". In your case, that would
be a "jar:" scheme URI to locate the resource within one of Papyrus's
SysML plug-in JARs.


> 'EcoreUtil.resolveAll(resourceSet)' did not resolve anything.

It can only resolve proxies that reference resources that the EMF
run-time knows how to locate. All that it does is to pre-empt a
process of lazily loading referenced objects.


> I tried something stupid quickly, I added the following two lines,
>
> 'uriMap.put(URI.createURI("platform:/plugin/com.cea.papyrus.uml4sysml.extension/model/"),
> uri_sysml.appendSegment("model").appendSegment(""));
>
> uriMap.put(URI.createURI("platform:/plugin/com.cea.papyrus.uml4sysml.extension/libraries/"),
> uri_sysml.appendSegment("libraries").appendSegment(""));'

You don't explain what the uri_sysml variable stores. Is that a "jar:"
scheme URI for a resource in the com.cea.papyrus.uml4sysml.extension
plug-in JAR?

And what is com.cea.papyrus? Is this a very old version of Papyrus the
pre-dates its initial contribution to Eclipse? Because there's an
org.eclipse.papyrus project that is some years old, now.

If you're asking questions about a propriety/closed product from CEA,
then the Eclipse forum is probably not an appropriate venue.


> It appeared to have resolved the proxy issue. 'getOwnedStereotypes()'
> method returned a list of stereotypes for all the SysML profiles. But
> still 'type.getAppliedStereotypes()' returned empty list in the model.

Well, yes, if you can load the profile, then getOwnedStereotypes()
invoked on the profile will work because the stereotypes will have been
loaded with the rest of the resource.

The UML2 API requires the EObjects representing stereotype applications
are traceable to Stereotypes in a Profile via their EClass, which
traces to an "Ecore definition" of the Profile, which then must be
applied to some package containing the element. I'd suggest stepping
through the ElementOperations::getAppliedStereotypes(Element) method in
the debugger to see what EObject applications it finds referencing an
element that you know has stereotypes applied, and see what the
getStereotype(EObject) method finds.


> I tried my best to ensure that the package registry, URI map and the
> extension maps are initialized properly (I used the plugin properties
> of all the resource jars and forum to do it).
>
> Please refer the .classpath file in my attachments for the list of jar
> files and their versions.

Sorry, I don't have time to look through so much material. Stepping
through the code I indicated above should help to find the reasons why
you're not getting applied stereotypes.


> Any help is greatly appreciated. Thanks in advance.
>
> Cheers,
> Prem.
>
> standalone app code:
>
> public static void main(String[] args) throws IOException {
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.eclipse.org/uml2/2.0.0/UML",
> UMLPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.eclipse.org/uml2/2.1.0/UML",
> UMLPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.eclipse.org/uml2/1.0.0/UML",
> UMLPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI,
> EcorePackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.eclipse.org/emf/2003/XMLType",
> XMLTypePackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.w3.org/XML/1998/namespace",
> XMLNamespacePackage.eINSTANCE);
>
>
> resourceSet.getPackageRegistry().put("http:\\www.eclipse.org/uml2/schemas/Ecore/5",
> EcorePackage.eINSTANCE);
> resourceSet.getPackageRegistry().put( Ecore2XMLPackage.eNS_URI,
> Ecore2XMLPackage.eINSTANCE);
> resourceSet.getPackageRegistry().put( Ecore2EcorePackage.eNS_URI,
> Ecore2EcorePackage.eINSTANCE);
>
>
>
> resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/UML/2.2",
> UMLPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/UML/2.1",
> UMLPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/UML/2.1.1",
> UMLPackage.eINSTANCE);
>
>
> resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/MOF/2.0/cmof.xml",
> UMLPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/mof/2.0/emof.xml",
> UMLPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\schema.omg.org/spec/MOF/2.0/emof.xml",
> UMLPackage.eINSTANCE);
>
>
> resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/1",
> SysmlPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Blocks/1",
> BlocksPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/PortAndFlows/1",
> PortandflowsPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Constraints/1",
> ConstraintsPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Activities/1",
> ActivitiesPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Allocations/1",
> AllocationsPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Requirements/1",
> RequirementsPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/Interactions/1",
> InteractionsPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put("http:\\www.papyrusuml.org/SysML/StateMachines/1",
> StatemachinesPackage.eINSTANCE);
>
> Map<String, Object> extensionToFactoryMap =
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
>
> extensionToFactoryMap.put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> extensionToFactoryMap.put(UMLResource.PROFILE_FILE_EXTENSION,
> UMLResource.Factory.INSTANCE );
>
> extensionToFactoryMap.put("xmi", XMI2UMLResource.Factory.INSTANCE);
> extensionToFactoryMap.put("profile.xmi", XMI2UMLResource.Factory.INSTANCE );
>
> extensionToFactoryMap.put("ecore", new EcoreResourceFactoryImpl());
>
>
> extensionToFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,Ecore2XMLResource.Factory.INSTANCE);
>
>
> extensionToFactoryMap.put(UML22UMLResource.FILE_EXTENSION,UML22UMLResource.Factory.INSTANCE);
>
>
> //extensionToFactoryMap.put(UML212UMLResource.FILE_EXTENSION,UML212UMLResource.Factory.INSTANCE);
>
>
>
> extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();
>
> String rootdirPath = ..................;
>
> /**
> * registering URI map for UML resources.
> */
> URI uri = URI.createURI("jar:file:/"+ rootdirPath +
> "/lib/eclipse_lib/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar!/");
>
> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
> uri.appendSegment("libraries").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
> uri.appendSegment("metamodels").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
> uri.appendSegment("profiles").appendSegment(""));
>
> /**
> * registering URI map for SysML resources.
> */
> URI uri_sysml = URI.createURI("jar:file:/"+ rootdirPath +
> "/lib/eclipse_lib/com.cea.papyrus.uml4sysml.extension_1.2.0.jar!/");
> uriMap.put(URI.createURI("pathmap://SysML_PROFILES/"),
> uri_sysml.appendSegment("model").appendSegment(""));
> uriMap.put(URI.createURI("pathmap://SysML_LIBRARIES/"),
> uri_sysml.appendSegment("libraries").appendSegment(""));
>
>
> uriMap.put(URI.createURI("platform:/plugin/com.cea.papyrus.uml4sysml.extension/model/"),
> uri_sysml.appendSegment("model").appendSegment(""));
>
> uriMap.put(URI.createURI("platform:/plugin/com.cea.papyrus.uml4sysml.extension/libraries/"),
> uri_sysml.appendSegment("libraries").appendSegment(""));
>
>
> Resource resource =
> resourceSet.getResource(URI.createFileURI("................\\umlExample1.uml"),
> true);
>
> EcoreUtil.resolveAll(resourceSet);
>
> TreeIterator itr = EcoreUtil.getAllContents(resource, true);
>
> while (itr.hasNext()) {
>
> Object type_1 = itr.next();
> if (type_1 instanceof EObject)
> EcoreUtil.resolveAll((EObject)type_1);
> if (type_1 instanceof NamedElement) {
> NamedElement type = (NamedElement) type_1;
> System.out.println(type.getName() + " : " +
> type.getAppliedStereotypes().size());
> }
> if (type_1 instanceof ProfileApplication) {
> ProfileApplication type = (ProfileApplication) type_1;
> System.out.println(type.getAppliedProfile().getName() + ":" +
> type.getAppliedProfile().eIsProxy() + " : " +
> type.getAppliedStereotypes().size()
> + " : " + type.getAppliedProfile().getOwnedStereotypes().size());
> }
>
> if (type_1 instanceof AnyTypeImpl) {
>
> System.out.println("AnyType : " + ((AnyTypeImpl)type_1).toString());
> }
>
> System.out.println(type_1.toString());
> }
> }
> <image><image><image><image>
Re: Unable to read the stereotypes from Papyrus SysML model in standalone mode [message #877164 is a reply to message #875948] Fri, 25 May 2012 21:30 Go to previous message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
Hi,

Are you asking how to use the Eclipse Papyrus editor to create UML
Profiles? Hopefully the Papyrus project has user documentation,
tutorials, etc. to assist with that. Otherwise, the eclipse.papyrus
newsgroup is probably a better place to ask.

If you're asking about how to design a UML2 profile for the Jacobson
O-O design method, then I don't know how to help.

HTH,

Christian


On 2012-05-23 15:46:11 +0000, Hela Hakim said:

> Hello all,
> I apologize if I'm not in the right place this is my first visit, in
> fact I wanted to ask how to model Stereotypes Jacobson (UML2) as
> papyrus and thank you in advance.
Previous Topic:UML Component creation
Next Topic:packageImport
Goto Forum:
  


Current Time: Mon Sep 01 21:55:51 EDT 2014

Powered by FUDForum. Page generated in 0.02535 seconds