Home » Modeling » Papyrus » Where is SysMLResourcesUtil.init(How to perform SysML initialization in a standalone application)
Where is SysMLResourcesUtil.init [message #1855384] |
Tue, 11 October 2022 15:16 |
Frank Conover Messages: 20 Registered: October 2022 |
Junior Member |
|
|
Hi,
I have been trying to properly initialize the SysML (1.4) jar file in a standalone Java application.
I found several old threads all asking the same thing. Usually with no success. Some claimed to have success but the solutions haven't worked out for me.
I can load the profiles. When I go to apply a stereotype I receive:
"stereotype "SysML::Block" has no Ecore definition"
I see there is still an open ticket:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=531840
I start by initializing the UML libraries.
UMLResourcesUtil.init(resourceSet);
resourceSet = new ResourceSetImpl();
I registered path maps. This allowed me to load the profiles. But the stereotype error still occurred.
protected void registerSysMLPathmaps(URI baseUri) {
URIConverter.URI_MAP.put(URI.createURI(SysMLResource.LIBRARIES_PATHMAP), baseUri.appendSegment("resources").appendSegment("library").appendSegment(""));
URIConverter.URI_MAP.put(URI.createURI(SysMLResource.PROFILES_PATHMAP), baseUri.appendSegment("resources").appendSegment("profile").appendSegment(""));
}
After reading more threads I then wrote the following methods but they made no difference.
initPackageRegistry and
initEPackageNsURIToProfileLocationMap
I'm not sure the output is in the expected format.
Printing out UMLPlugin.getEPackageNsURIToProfileLocationMap() looks like:
http://www.eclipse.org/papyrus/sysml/1.4/SysML : http://www.eclipse.org/papyrus/sysml/1.4/SysML#_Aa0lgJvoEeSpx5CUmLYZ-g
http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks : http://www.eclipse.org/papyrus/sysml/1.4/SysML#_dZfREJvkEeSpx5CUmLYZ-g
Should it be:
http://www.eclipse.org/papyrus/sysml/1.4/SysML : file:/F:/mypath/SysML/resources/profile/SysML.profile.uml#_Aa0lgJvoEeSpx5CUmLYZ-g
http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks : file:/F:/mypath/SysML/resources/profile/SysML.profile.uml#_dZfREJvkEeSpx5CUmLYZ-g
I ask because I had to use the actual file path in registerSysMLPathmaps.
These are my other methods referenced above.
private static void initPackageRegistry(final EPackage.Registry packageRegistry) {
packageRegistry.put(sysmlPackage.eNS_URI, sysmlPackage.eINSTANCE);
packageRegistry.put(BlocksPackage.eNS_URI, BlocksPackage.eINSTANCE);
packageRegistry.put(PortsandflowsPackage.eNS_URI, PortsandflowsPackage.eINSTANCE);
packageRegistry.put(ActivitiesPackage.eNS_URI, ActivitiesPackage.eINSTANCE);
packageRegistry.put(ModelelementsPackage.eNS_URI, ModelelementsPackage.eINSTANCE);
packageRegistry.put(ConstraintblocksPackage.eNS_URI, ConstraintblocksPackage.eINSTANCE);
packageRegistry.put(AllocationsPackage.eNS_URI, AllocationsPackage.eINSTANCE);
packageRegistry.put(RequirementsPackage.eNS_URI, RequirementsPackage.eINSTANCE);
packageRegistry.put(DeprecatedelementsPackage.eNS_URI, DeprecatedelementsPackage.eINSTANCE);
}
private static void initEPackageNsURIToProfileLocationMap(String prefix) {
UMLPlugin.getEPackageNsURIToProfileLocationMap().put(sysmlPackage.eNS_URI, URI.createURI(prefix + "#_Aa0lgJvoEeSpx5CUmLYZ-g"));
UMLPlugin.getEPackageNsURIToProfileLocationMap().put(BlocksPackage.eNS_URI, URI.createURI(prefix + "#_dZfREJvkEeSpx5CUmLYZ-g"));
UMLPlugin.getEPackageNsURIToProfileLocationMap().put(PortsandflowsPackage.eNS_URI, URI.createURI(prefix + "#_fGLcYJvkEeSpx5CUmLYZ-g"));
UMLPlugin.getEPackageNsURIToProfileLocationMap().put(ActivitiesPackage.eNS_URI, URI.createURI(prefix + "#_fya3UJvkEeSpx5CUmLYZ-g"));
UMLPlugin.getEPackageNsURIToProfileLocationMap().put(ModelelementsPackage.eNS_URI, URI.createURI(prefix + "#_gQxnQJvkEeSpx5CUmLYZ-g"));
UMLPlugin.getEPackageNsURIToProfileLocationMap().put(ConstraintblocksPackage.eNS_URI, URI.createURI(prefix + "#_g0eKMJvkEeSpx5CUmLYZ-g"));
UMLPlugin.getEPackageNsURIToProfileLocationMap().put(AllocationsPackage.eNS_URI, URI.createURI(prefix + "#_hUK98JvkEeSpx5CUmLYZ-g"));
UMLPlugin.getEPackageNsURIToProfileLocationMap().put(RequirementsPackage.eNS_URI, URI.createURI(prefix + "#_hzXbYJvkEeSpx5CUmLYZ-g"));
UMLPlugin.getEPackageNsURIToProfileLocationMap().put(DeprecatedelementsPackage.eNS_URI, URI.createURI(prefix + "#_iUUMUJvkEeSpx5CUmLYZ-g"));
}
[Updated on: Tue, 11 October 2022 16:24] Report message to a moderator
|
|
| |
Re: Where is SysMLResourcesUtil.init [message #1855391 is a reply to message #1855389] |
Tue, 11 October 2022 20:05 |
Frank Conover Messages: 20 Registered: October 2022 |
Junior Member |
|
|
I've added a test to confirm they are in the resource.
If I change or remove any of the initialization code I have then this breaks. So that might confirm what I have is correct.
private void test() {
List<String> list = Arrays.asList(new String[] {
"http://www.eclipse.org/papyrus/sysml/1.4/SysML",
"http://www.eclipse.org/papyrus/sysml/1.4/SysML/Activities",
"http://www.eclipse.org/papyrus/sysml/1.4/SysML/Allocations",
"http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks",
"http://www.eclipse.org/papyrus/sysml/1.4/SysML/ConstraintBlocks",
"http://www.eclipse.org/papyrus/sysml/1.4/SysML/DeprecatedElements",
"http://www.eclipse.org/papyrus/sysml/1.4/SysML/PortsAndFlows",
"http://www.eclipse.org/papyrus/sysml/1.4/SysML/ModelElements",
"http://www.eclipse.org/papyrus/sysml/1.4/SysML/Requirements"
});
for(String uri : list) {
URI location = UMLPlugin.getEPackageNsURIToProfileLocationMap().get(uri);
System.out.println(resourceSet.getEObject(location,true));
}
}
org.eclipse.uml2.uml.internal.impl.ProfileImpl@1863d2fe (name: SysML, visibility: <unset>) (URI: http://www.eclipse.org/papyrus/sysml/1.4/SysML)
org.eclipse.emf.ecore.impl.DynamicEObjectImpl@71c5b236 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@5f6722d3 (name: EPackage) (instanceClassName: null) (abstract: false, interface: false))
org.eclipse.emf.ecore.impl.DynamicEObjectImpl@669513d8 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@5f6722d3 (name: EPackage) (instanceClassName: null) (abstract: false, interface: false))
org.eclipse.emf.ecore.impl.DynamicEObjectImpl@1cb3ec38 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@5f6722d3 (name: EPackage) (instanceClassName: null) (abstract: false, interface: false))
org.eclipse.emf.ecore.impl.DynamicEObjectImpl@2f7a7219 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@5f6722d3 (name: EPackage) (instanceClassName: null) (abstract: false, interface: false))
org.eclipse.emf.ecore.impl.DynamicEObjectImpl@4a8a60bc (eClass: org.eclipse.emf.ecore.impl.EClassImpl@5f6722d3 (name: EPackage) (instanceClassName: null) (abstract: false, interface: false))
org.eclipse.emf.ecore.impl.DynamicEObjectImpl@403132fc (eClass: org.eclipse.emf.ecore.impl.EClassImpl@5f6722d3 (name: EPackage) (instanceClassName: null) (abstract: false, interface: false))
org.eclipse.emf.ecore.impl.DynamicEObjectImpl@2cab9998 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@5f6722d3 (name: EPackage) (instanceClassName: null) (abstract: false, interface: false))
org.eclipse.emf.ecore.impl.DynamicEObjectImpl@3a1d593e (eClass: org.eclipse.emf.ecore.impl.EClassImpl@5f6722d3 (name: EPackage) (instanceClassName: null) (abstract: false, interface: false))
|
|
|
Re: Where is SysMLResourcesUtil.init [message #1855392 is a reply to message #1855391] |
Tue, 11 October 2022 20:09 |
Frank Conover Messages: 20 Registered: October 2022 |
Junior Member |
|
|
Is there something I need to do to the profile or model before I can create a stereotype?
I wasn't sure at what stage to define() the profile for example.
All I'm looking to do is build up a model within code and print the XMI.
I have the XMI printing (unless I try to apply a stereotype that is).
Model model = SysMLResource.createSysMLModel(resourceSet, "TestModel.uml", "TestModel");
xmiResourceImpl.getContents().add(model);
Class blockClass = model.createOwnedClass("Block", false);
Stereotype blockStereotype = model.getAppliedProfile("SysML").createOwnedStereotype("Block", false); // even tried "Blocks::Block"
blockClass.applyStereotype(blockStereotype);
public static Model createSysMLModel(ResourceSet resourceSet, String resourceName, String modelName) {
Model model = UMLFactory.eINSTANCE.createModel();
model.setName(modelName);
Resource resource = resourceSet.createResource(URI.createURI(resourceName));
resource.getContents().add(model);
Resource standardProfileResource = resourceSet
.getResource(URI.createURI("pathmap://UML_PROFILES/Standard.profile.uml"), true);
Profile umlStdProfile = (Profile) EcoreUtil.getObjectByType(standardProfileResource.getContents(),
Literals.PACKAGE);
model.applyProfile(umlStdProfile);
Resource sysmlProfileResource = resourceSet
.getResource(URI.createURI("pathmap://SysML14_PROFILES/SysML.profile.uml"), true);
Profile sysmlProfile = (Profile) EcoreUtil.getObjectByType(sysmlProfileResource.getContents(),
Literals.PACKAGE);
model.applyProfile(sysmlProfile);
return model;
}
java.lang.IllegalArgumentException: stereotype "SysML::Block" has no Ecore definition
[Updated on: Tue, 11 October 2022 20:09] Report message to a moderator
|
|
|
Re: Where is SysMLResourcesUtil.init [message #1855410 is a reply to message #1855392] |
Wed, 12 October 2022 20:01 |
Frank Conover Messages: 20 Registered: October 2022 |
Junior Member |
|
|
So I sort of figured it out.
I am loading all the resources correctly.
What I had to do was apply all the subprofiles to my model.
I didn't realize this. I discovered it experimenting with getOwnedMembers on the profile. Printing those. Creating Profiles from them and printing their members. All of the expected elements were there.
So I then did this. It appeared to work on the surface and generated new XMI output when I saved.
Profile profileBlocks = (Profile)model.getAppliedProfile("SysML").getOwnedMember("Blocks");
model.applyProfile(profileBlocks);
Class blockClass = model.createOwnedClass("Block", false);
Stereotype stereotypeBlock = (Stereotype)profileBlocks.getOwnedMember("Block");
blockClass.applyStereotype(stereotypeBlock);
But I am not applying the profile to the model correctly as this returns null:
model.getAppliedProfile("Blocks")
And I am not applying the stereotype correctly as this returns null:
blockClass.getAppliedStereotype("Block")
This returns 0:
blockClass.getAppliedStereotypes
I assume I should not be using getOwnedMember and should be doing:
Stereotype stereotypeBlock = profileBlocks.createOwnedStereotype("Block", true);
But that complains because I never applied the Blocks profile correctly to my model. (stereotype "SysML::Blocks::Block" is not applicable to Class)
(Side note, I can post my SysML resources init code for future developers once I am sure this is working).
[Updated on: Wed, 12 October 2022 20:03] Report message to a moderator
|
|
| |
Re: Where is SysMLResourcesUtil.init [message #1855421 is a reply to message #1855414] |
Thu, 13 October 2022 11:55 |
|
Hello Frank,
it is hard for us to answer to your problem. What I understand is that your are embedding SysML 1.4 + UML + other stuff in a java application outside of Eclipse, right ? I think that the exception "java.lang.IllegalArgumentException: stereotype "SysML::Block" has no Ecore definition" is "normal", because this profile doesn't not embed a definition. It is a "static profile", so its definition is done with java code. I think , as you are outside of Eclipse, you don't benefit of the extension point mechanism, so the SysMLFactory.java must be registered programmatically inside an Ecore registry.
/Vincent
|
|
| |
Re: Where is SysMLResourcesUtil.init [message #1855429 is a reply to message #1855426] |
Thu, 13 October 2022 16:29 |
Frank Conover Messages: 20 Registered: October 2022 |
Junior Member |
|
|
Thanks for the hints. Any input helps, even if it just gets the author rethinking about something.
I went back to the registration portions and found and fixed an issue.
Referencing code from earlier in the post,
I changed:
UMLPlugin.getEPackageNsURIToProfileLocationMap().put(BlocksPackage.eNS_URI, URI.createURI(prefix + "#_dZfREJvkEeSpx5CUmLYZ-g"));
to:
UMLPlugin.getEPackageNsURIToProfileLocationMap().put(BlocksPackage.eNS_URI, URI.createURI(prefix + "#SysML.package_packagedElement_Blocks"));
Which changes the test printout from:
org.eclipse.emf.ecore.impl.DynamicEObjectImpl@669513d8 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@5f6722d3 (name: EPackage) (instanceClassName: null) (abstract: false, interface: false))
to:
org.eclipse.uml2.uml.internal.impl.ProfileImpl@5c44c582 (name: Blocks, visibility: public) (URI: http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks)
Not sure it mattered but it matches the output from the StandardProfile and SysMl profile now.
I now am able to print the expected applied profiles of my model.
I can also access the stereotypes.
I haven't figured out the following though.
If I create a Class and print the Applicable stereotypes I see Block as one of the options.
Class blockClass = model.createOwnedClass("Block", false);
blockClass.getApplicableStereotypes()
...
Block
But when I make a stereotype I get the error:
stereotype "SysML::Blocks::Block" is not applicable to Class
Stereotype stereotypeBlock = model.getAppliedProfile("SysML::Blocks").createOwnedStereotype("Block", true);
I've tried just creating the stereotype from the model but end up with a stereotype "TestModel::Block"
[Updated on: Thu, 13 October 2022 16:35] Report message to a moderator
|
|
| |
Goto Forum:
Current Time: Wed Apr 17 21:44:09 GMT 2024
Powered by FUDForum. Page generated in 0.02399 seconds
|