Papyrus SysML model to text [message #1795548] |
Tue, 25 September 2018 08:09 |
Robbert Jongeling 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 #1795737 is a reply to message #1795672] |
Thu, 27 September 2018 14:28 |
Robbert Jongeling 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04698 seconds