Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Papyrus SysML model to text(Some help requested with registration of SysML resources/profile)
Papyrus SysML model to text [message #1795548] Tue, 25 September 2018 08:09 Go to next message
Robbert Jongeling is currently offline Robbert JongelingFriend
Messages: 3
Registered: September 2018
Junior Member
Hi,

I'm trying to create a model-to-text transformation from a Papyrus SysML model-to-text using Xtend (input is a model.uml file). The problem I'm encountering is that I cannot access the stereotypes of the elements in the resource. For example, I can get a Class, but not a Block.

Searching on the Papyrus forums and here leads me to believe that my problem may be related to the registration of SysML resources. As far as I know, there is no built-in way to register SysML resources for stand-alone applications, similar to UMLResourcesUtil.init (https://bugs.eclipse.org/bugs/show_bug.cgi?id=531840).
Therefore, I'm manually registering the resources, but I'm having difficulty understanding what exactly I'm doing, how to debug what I'm doing and in general how to get it working.

I do the following steps to register the UML resources:
Resource$Factory.Registry.INSTANCE.extensionToFactoryMap.put("uml", new UMLResourceFactoryImpl)  		
resourceSet = new ResourceSetImpl 			  		
UMLResourcesUtil.init(resourceSet)


Then, I call the following three functions to register the SysML resources:
1)
def void initPackageRegistry() {
	val packageRegistry = EPackage.Registry.INSTANCE
	packageRegistry.put(sysmlPackage.eNS_URI, sysmlPackage.eINSTANCE)
	packageRegistry.put(BlocksPackage.eNS_URI, BlocksPackage.eINSTANCE)
	packageRegistry.put(PortsandflowsPackage.eNS_URI, PortsandflowsPackage.eINSTANCE)
	packageRegistry.put(DeprecatedelementsPackage.eNS_URI, DeprecatedelementsPackage.eINSTANCE)
}


2)
def void initURIConverterURIMap() {
	val baseUri = URI.createURI("jar:file:/Applications/Eclipse-P2.app/Contents/Eclipse/plugins/org.eclipse.papyrus.sysml14_1.3.0.jar!/")
	val um = URIConverter.URI_MAP
	um.put(URI.createURI(SysMLResource.PROFILES_PATHMAP), baseUri.appendSegment("model").appendSegment(""))
	um.put(URI.createURI(SysMLResource.LIBRARIES_PATHMAP), baseUri.appendSegment("libraries").appendSegment(""))
}


3)
def void initProfileLocationMap() {
	val plm = UMLPlugin.EPackageNsURIToProfileLocationMap
	plm.put(sysmlPackage.eNS_URI, URI.createURI(SysMLResource.PROFILE_URI + "#_Sg5BQL5BEeiU9bakHvTSew"))
	plm.put(BlocksPackage.eNS_URI, URI.createURI(SysMLResource.PROFILE_URI + "#_ShCyQr5BEeiU9bakHvTSew"))
	plm.put(PortsandflowsPackage.eNS_URI, URI.createURI(SysMLResource.PROFILE_URI + "#_ShEAYr5BEeiU9bakHvTSew"))
	plm.put(DeprecatedelementsPackage.eNS_URI, URI.createURI(SysMLResource.PROFILE_URI + "#_ShDZUr5BEeiU9bakHvTSew"))
}


In the last method, the "#..." strings correspond to the xmi:id's of the profileApplications in the uml file.

I have attached a zip of my project, including an example uml file and the complete Xtend code.

I would greatly appreciate any hints that can help me understand what I'm missing to implement this model-to-text transformation completely.
Re: Papyrus SysML model to text [message #1795669 is a reply to message #1795548] Wed, 26 September 2018 14:59 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 687
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Sorry I won't have the time to look into the example. If "Block" is your stereotype, then you won't have a class "Block", just a Stereotype instance that is applied on the Class, and from which you can access the tagged values with the Stereotype instance.

Project Xpand (predecessor of Xtend) as a dynamic UML typesystem. You may get some ideas from that how to handle that. Since the project is dormant I don't know how current handling UML models differs today from what it does, but I guess the basics did not change so much.

http://git.eclipse.org/c/m2t/org.eclipse.xpand.git/tree/plugins/org.eclipse.xtend.typesystem.uml2/src/org/eclipse/xtend/typesystem/uml2

Re: Papyrus SysML model to text [message #1795672 is a reply to message #1795669] Wed, 26 September 2018 15:30 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6439
Registered: July 2009
Senior Member
Hi

Well done for finding the Bugzilla. Your code may be an indication of what should be in the fix.

resourceSet = new ResourceSetImpl
UMLResourcesUtil.init(resourceSet)

looks wrong on two counts.

a) UML requires the global registries to be initialized using a null ResourceSet.
b) new ResourceSetImpl creates a new ResourceSet. You should initialize the ResourceSet that the rest of your code uses.

Regards

Ed Willink
Re: Papyrus SysML model to text [message #1795737 is a reply to message #1795672] Thu, 27 September 2018 14:28 Go to previous messageGo to next message
Robbert Jongeling is currently offline Robbert JongelingFriend
Messages: 3
Registered: September 2018
Junior Member
Hi Ed,

Thank you for your reply.

I'm not sure I understand you correctly about statement a, there seems to be no difference between calling UMLResourceUtil.init with a non-initialized vs an initialized resourceset.

Anyway, I have now made some progress towards a solution that allows me to obtain the stereotypes that I expected to get, which I'm sharing below in case it is useful to someone else (and attached zip file).

I removed most of the setup code that I had.
What remains is the following:

A global variable.
ResourceSetImpl resourceSet


A function performing the resource setup (for now using hardcoded locations)
UMLResourcesUtil.init(resourceSet)
resourceSet = new ResourceSetImpl()
		
resourceSet.packageRegistry.put(sysmlPackage.eNS_URI, sysmlPackage.eINSTANCE)
val prefix = "jar:file:/Applications/Eclipse-P2.app/Contents/Eclipse/plugins/org.eclipse.papyrus.sysml14_1.3.0.jar!/resources/profile/SysML.profile.uml"; 
UMLPlugin.EPackageNsURIToProfileLocationMap.put(sysmlPackage.eNS_URI, URI.createURI(prefix + "#SysML"))


Then, when I load a uml model using
val resource = resourceSet.getResource(URI.createURI(file), true)

(where file is the path to a Papyrus model.uml file)

I can get the applied stereotypes of the example.uml using:
for (model : resource.contents.filter(org.eclipse.uml2.ml.Model)) {
    for (clazz : model.allOwnedElements.filter(org.eclipse.uml2.uml.Class)) {
        val blockST = clazz.getAppliedStereotype("SysML::Blocks::Block")
        val block = clazz.getStereotypeApplication(blockStereotype)

        for(port : clazz.allOwnedElements().filter(org.eclipse.uml2.uml.Port)) {
            val flowportST = port.getAppliedStereotype("SysML::DeprecatedElements::FlowPort")
            val flowport = port.getStereotypeApplication(flowportST)
        }
    }
}

And similarly for FullPort and ProxyPort of the example uml using "SysML::PortsAndFlows::FullPort" and "SysML::PortsAndFlows::ProxyPort".

My current state is that this works when I run it in Eclipse, meaning that the variable block is a BlockImpl and the variable flowport is a FlowPortImpl.
The next step is to try to make it work completely stand-alone.

Regards, Robbert

Re: Papyrus SysML model to text [message #1795748 is a reply to message #1795737] Thu, 27 September 2018 16:47 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6439
Registered: July 2009
Senior Member
Hi

"there seems to be no difference between calling UMLResourceUtil.init with a non-initialized vs an initialized resourceset". Yes you are right, the code has changed since I influenced it's development. The Javadoc still says "(and/or the global registries)" but the "or" support has been removed.

Regards

Ed Willink
Previous Topic:Papyrus SysML model to text
Next Topic:[Acceleo] Problem of type with empty collections
Goto Forum:
  


Current Time: Wed Aug 21 15:57:11 GMT 2019

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

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

Back to the top