I have a SysML file generated from Enterprise Architect with extension XMI, and I want to parse it to get the object inside SysML file in Java by using EMF, UML2 and Papyrus plugins.
I tried to new a EMF project and import this SysML file, but failed. It said that there is some illegal values inside this file.
Then I tried to write a reader to read this, it also doesn't work. The code as follow:
ResourceSet resourceSet = new ResourceSetImpl();
Registry packageRegistry = resourceSet.getPackageRegistry();
packageRegistry.put(XMI_NAMESPACE, UMLPackage.eINSTANCE);
packageRegistry.put(UML_NAMESPACE, UMLPackage.eINSTANCE);
packageRegistry.put(SysmlPackage.eNS_URI, SysmlPackage.eINSTANCE);
//packageRegistry.put(ADA_NAMESPACE, UMLPackage.eINSTANCE);
//packageRegistry.put(VERILOG_NAMESPACE, UMLPackage.eINSTANCE);
//packageRegistry.put(ARCGIS_NAMESPACE, UMLPackage.eINSTANCE);
//packageRegistry.put(EAUML_NAMESPACE, UMLPackage.eINSTANCE);
//packageRegistry.put(THE_CUSTOMER_PROFILE_NAMESPACE,UMLPackage.eINSTANCE);
// Add the load option
resourceSet.getLoadOptions().put(XMIResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
// Deine the extension to factory map
Map<String, Object> extensionToFactoryMap = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
UMLResourceFactoryImpl umlResourceFactory = new UMLResourceFactoryImpl();
extensionToFactoryMap.put(XMI2UMLResource.FILE_EXTENSION, umlResourceFactory);
URI uri = URI.createFileURI(xmiFile.getPath());
Model umlModel = UML2Util.load(resource, uri, UMLPackage.Literals.MODEL);
System.out.println(umlModel);
This code works with SysML generated by Papyrus, but does not work with the file generated from Enterprise Architect.
As the comments inside, in the head of SysML file, there is a lot of namespaces particular. The namespaces as follow:
<?xml version="1.0" encoding="windows-1252"?>
<xmi:XMI xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/UML/2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:thecustomprofile="http://www.sparxsystems.com/profiles/thecustomprofile/1.0" xmlns:Ada="http://www.sparxsystems.com/profiles/Ada/1.0" xmlns:Verilog="http://www.sparxsystems.com/profiles/Verilog/1.0" xmlns:ArcGIS="http://www.sparxsystems.com/profiles/ArcGIS/1.0" xmlns:sysml="http://www.omg.org/spec/SysML/20080501/SysML-profile" xmlns:SysML="http://www.omg.org/spec/SysML/20120322/SysML" xmlns:EAUML="http://www.sparxsystems.com/profiles/EAUML/1.0">
<xmi:Documentation exporter="Enterprise Architect" exporterVersion="6.5"/>
<uml:Model xmi:type="uml:Model" name="EA_Model" visibility="public">
....
And I want to get the imformation in the tag ....
Could someone helps me?
Edit:
- The plugins I used in my code:
org.eclipse.emf.common;bundle-version="2.11.0",
org.eclipse.emf.ecore;bundle-version="2.11.1",
org.eclipse.emf.mapping;bundle-version="2.9.0",
org.eclipse.uml2.common;bundle-version="2.1.0",
org.eclipse.uml2.uml;bundle-version="5.1.0",
org.apache.log4j;bundle-version="1.2.15",
org.junit;bundle-version="4.12.0",
org.eclipse.papyrus.sysml;bundle-version="1.1.3"
The code I use could parse the SysML generated by Papyrus, and also by IBM Rhapsody. Unfortunately, I need to parse the file generated by EA. In addition, I tried to use Rhapsody to import the SysML generated by EA, and then exported a new SysML file from Rhapsody. This time I could parse the new SysML file.
The errors showed when I parse SysML from EA just like follow:
Line: 3501 : Value 'org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@1ddeb95 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@77270b15 (name: ActivityEdge) (instanceClassName: null) (abstract: false, interface: false)) (mixed: null, anyAttribute: [XMI_2.1:idref=EAID_B206112C_3845_4058_8987_AAB974C081D8])' is not legal. (file:/home/pzhengshuai/workspace-papyrus/SysMLReader/resource/import/export_file_xmi_2.1/eaexample_model.xmi, 3501, 77)
and somes like this
Line: 1989 : Unresolved reference 'EAID_425E703B_8FB1_4be3_9264_C470555CFF8F'. (file:/home/pzhengshuai/workspace-papyrus/SysMLReader/resource/import/export_file_xmi_2.1/eaexample_model.xmi, 1989, 73)
- A guess:
I guess that maybe my code could not recognize the namespaces particular in EA SysML file. If we could find the schemas or somethings define the namespaces in EA, and add them into the SysML file, maybe code will work. But I have not found any files related.