Reading SysML model from XMI [message #1867497] |
Thu, 27 June 2024 00:10  |
Eclipse User |
|
|
|
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 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 #1868202 is a reply to message #1867680] |
Mon, 15 July 2024 07:30  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.17326 seconds