Skip to main content



      Home
Home » Modeling » UML2 » Reading SysML model from XMI(I would like to read a SysML file exported to XMI)
Reading SysML model from XMI [message #1867497] Thu, 27 June 2024 00:10 Go to next message
Eclipse UserFriend
cHello,

I am trying to read a SySML model from XMI but kind of stuck halfway and I think the problem might be around the name spaces and their resolve. The way I understand that the ecore file of sysml consists of packages like activities, allocations, blocks, etc. Each of the packages have a custom URI for example blocks has www.omg.org/spec/SysML/20161101/SysML/Blocks.

However, it seems that if I have just the global namespace in the xml file like:

<xmi:XMI xmi:version="20131001" xmlns:xmi="www.omg.org/spec/XMI/20131001" xmlns:sysml="www.omg.org/spec/SysML/201611>
... 


Then a standard
sysml:Block
tag cannot be resolved because it is not being searched recursively.

I am wondering what the solution is given I have seen the similar format in multiple tools (Cameo, Astah, etc.) so there should be a way to read such files.

My code looks like the following way:

public static void main(String[] args) {

		UMLResourcesUtil.initGlobalRegistries();

		var registry = Resource.Factory.Registry.INSTANCE;
		var m = registry.getExtensionToFactoryMap();
		m.put("xmi", new XMIResourceFactoryImpl());

		var resourceSet = new ResourceSetImpl();
		SysMLPackageImpl.init();

		loadFile(resourceSet);
	}

	private static void loadFile(ResourceSet resourceSet) {
		var resource = resourceSet.createResource(URI.createFileURI("sysml_2.xmi"));

		try {
			resource.load(Collections.emptyMap());
			var contents = resource.getContents();
			System.out.println(contents);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}


What am I missing?
Re: Reading SysML model from XMI [message #1867680 is a reply to message #1867497] Wed, 03 July 2024 15:21 Go to previous messageGo to next message
Eclipse UserFriend
Have you tried adding the expected namespaces and profile applications to the file before importing?

xmlns:Blocks="http://www.eclipse.org/papyrus/sysml/1.4/SysML/Blocks"

        <profileApplication xmi:type="uml:ProfileApplication" xmi:id="_XsKK2d4oEe6a8Kc8eqfwRA">
          <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_XsKK2t4oEe6a8Kc8eqfwRA" source="http://www.eclipse.org/uml2/2.0.0/UML">
            <references xmi:type="ecore:EPackage" href="http://www.eclipse.org/papyrus/sysml/1.4/SysML#//blocks"/>
          </eAnnotations>
          <appliedProfile xmi:type="uml:Profile" href="pathmap://SysML14_PROFILES/SysML.profile.uml#SysML.package_packagedElement_Blocks"/>
        </profileApplication>
Re: Reading SysML model from XMI [message #1868202 is a reply to message #1867680] Mon, 15 July 2024 07:30 Go to previous message
Eclipse UserFriend
When UML 2.5 was in the offing, I developed an additional initialization to allow the prototype UML 2.5 models to be read by the pre-UML 2.5 Eclipse UML2. It was very hard since Eclipse UML2 had pretty much moved to UML 2.3.1 only. The better UMLUtil.init made life better, but only for a limited suite of known namespaces. UML 2.5. is again a challenge since the namespaces are not known and strange fallbacks give confusing diagnostics. Eclipse UML2 awaits funding to provide more recent support than UML 2.5.

Since for most purposes the newer namespaces are the same as their predecessors, the simplest solution is to edit your*.xmi files into *.uml files whose headers look much like regular Eclipse UML2 files.

If you need to do this regularly a simple sed script can probably do the job.

If you are more enthusiastic, you might use my UML 2.5 support work in https://git.eclipse.org/c/ocl/org.eclipse.ocl.git/tree/examples/org.eclipse.ocl.examples.uml25 as a source of some inspiration. NB this code has never been part of an OCL release; it just contains code that sometimes contributes to regression tests.
Previous Topic:How to get stereotypes after loading XMI resource
Next Topic:Accessing value of inherited tags
Goto Forum:
  


Current Time: Fri Jul 11 05:45:46 EDT 2025

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

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

Back to the top