Skip to main content



      Home
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 11:16 Go to next message
Eclipse UserFriend
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 12:24] by Moderator

Re: Where is SysMLResourcesUtil.init [message #1855389 is a reply to message #1855384] Tue, 11 October 2022 13:16 Go to previous messageGo to next message
Eclipse UserFriend
I think I determined the output of UMLPlugin.getEPackageNsURIToProfileLocationMap should look like:
http://www.eclipse.org/papyrus/sysml/1.4/SysML : pathmap://SysML14_PROFILES/SysML.profile.uml#SysML
http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks : pathmap://SysML14_PROFILES/SysML.profile.uml#_dZfREJvkEeSpx5CUmLYZ-g
Based on printing out the URI of the loaded sysml profile using EcoreUtil.getURI() and based on how the UML packages are printing from this map.
But I still can't apply a stereotype.

		Class blockClass = model.createOwnedClass("Block", false);
		Stereotype blockStereotype = model.getAppliedProfile("SysML").createOwnedStereotype("Block", false);
		blockClass.applyStereotype(blockStereotype);

java.lang.IllegalArgumentException: stereotype "SysML::Block" has no Ecore definition

Note that as long as I don't try to apply a stereotype, I can still create Block objects and set associations, properties ...
And generate the expected XMI for my standalone application.

e.g.:
<packagedElement xmi:type="uml:Class" xmi:id="_NX5dwEmHEe25eJkVubzkLg" name="Block"/>
...
<Blocks:Block xmi:id="_NX1zYEmHEe25eJkVubzkLg" base_Class="_NX0lQEmHEe25eJkVubzkLg"/>

Is there something that is missing by not applying the stereotype?
Re: Where is SysMLResourcesUtil.init [message #1855391 is a reply to message #1855389] Tue, 11 October 2022 16:05 Go to previous messageGo to next message
Eclipse UserFriend
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 16:09 Go to previous messageGo to next message
Eclipse UserFriend
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 16:09] by Moderator

Re: Where is SysMLResourcesUtil.init [message #1855410 is a reply to message #1855392] Wed, 12 October 2022 16:01 Go to previous messageGo to next message
Eclipse UserFriend
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 16:03] by Moderator

Re: Where is SysMLResourcesUtil.init [message #1855414 is a reply to message #1855410] Wed, 12 October 2022 21:03 Go to previous messageGo to next message
Eclipse UserFriend
I traced the apply profile code and found a few reasons that the stereotypes are not added/returned I am digging into.
Some things are partially initialized currently however and I may be able to continue as is.

I did find another thread where someone reached a similar point and their workaround was to do the following but I don't understand the solution or what they did. It was back in 2014 so I'm not going to reply to the thread.

I don't understand what they are saying. They didn't leave an example:
"I created a template model, that contains the root package. The profiles in question were directly applied. This way the stereotype problem doesn't occur"
That is all that was left in the final message: https://www.eclipse.org/forums/index.php/m/1403459/?srch=sysml+xtend#msg_1403459
Re: Where is SysMLResourcesUtil.init [message #1855421 is a reply to message #1855414] Thu, 13 October 2022 07:55 Go to previous messageGo to next message
Eclipse UserFriend
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 #1855426 is a reply to message #1855421] Thu, 13 October 2022 09:54 Go to previous messageGo to next message
Eclipse UserFriend
Hi, thank you for your response.
Yes, you are correct in your assumptions.
I wanted to import/export SysML (XMI) from our existing Java Application outside of Eclipse. I haven't found many well established open source libraries to choose from.

So I added the libraries and worked through the issues to this point following threads in the forum.

I will not be using the diagramming components (current requirements anyway).

We have a model in the tool. I just wanted to be able to traverse that and build the XMI file.
I might have enough initialized now to do that. I'm not sure why when applying the profile to the model the stereotypes are skipped. Tracing the code it only loads required members, I changed that to false and it then started to try to load the stereotypes but then failed at an eProxy check (something about the resource not being loaded in the api documentation) - sorry I don't have more right now.

So you are right about everything you said.

I might have enough working to do what I set out to.

Is this something I can do: "SysMLFactory.java must be registered programmatically inside an Ecore registry"? If I knew what that looked like I could see if I've tried it already or not.


Re: Where is SysMLResourcesUtil.init [message #1855429 is a reply to message #1855426] Thu, 13 October 2022 12:29 Go to previous messageGo to next message
Eclipse UserFriend
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 12:35] by Moderator

Re: Where is SysMLResourcesUtil.init [message #1855430 is a reply to message #1855429] Thu, 13 October 2022 14:40 Go to previous message
Eclipse UserFriend
My current workaround is to just get the stereotype I want from the Class I created using getApplicableStereotype(QualifiedName)
I then call class.applyStereotype and there are no errors, but when I request getAppliedStereotypes or even getStereotypeApplications the results are empty.

Also, I'm not sure why when I was getting a stereotype using the createOwnedStereotype in either model or profile the class claims they are not applicable. I checked the names and qualified names and they match the stereotype I pulled from class.getApplicableStereotype.

At least I have a Block now and its base class is set and it shows in the XMI output.
Previous Topic:Scientific contribution to refer to for Papyrus and Moka
Next Topic:Change namespace in XMI output
Goto Forum:
  


Current Time: Mon Jul 14 23:13:29 EDT 2025

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

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

Back to the top