Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » 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 #873946] Sat, 19 May 2012 14:54
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 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.uml
    (Size: 6.57KB, Downloaded 144 times)
  • Attachment: Test.java
    (Size: 8.10KB, Downloaded 155 times)
  • Attachment: .classpath
    (Size: 13.80KB, Downloaded 177 times)
  • Attachment: umlExample1.di2
    (Size: 0.60KB, Downloaded 122 times)
Previous Topic:[Solved] Apply a default profile ?
Next Topic:Customize Papyrus Perspective
Goto Forum:
  


Current Time: Fri Sep 19 15:52:26 GMT 2014

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

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