Model Readers:
Model Writers:
The "Enterprise Architect Application" model reader enables to connect to the active Enterprise Architect application to read the currently loaded project. The process ask Enterprise Architect to export a temporary XMI file that is read back in MDAccess. Options can be used to control the export of the temporary XMI file.
import com.sodius.mdw.metamodel.uml21.io.ea.Options; ... Map<String, Object> options = new HashMap<String, Object>(); options.put(Options.OPTION_APP_XMI_VERSION, EAXMIVersion.EA241); MDWorkbench workbench = MDWorkbenchFactory.create(); Model umlModel = workbench.getMetamodelManager().getMetamodel("uml21").createModel(); umlModel.read("Enterprise Architect Application", "", options); ... umlModel.clear();
In the same way "Enterprise Architect EAP" can connect to Enterprise Architect. In the difference with "Enterprise Architect Application", it doesn't need an instance of Enterprise Architect opened. The connector URI should point to an EAP file, this is then to the responsability of the connector to instance Enterprise Architect in silent mode. "Enterprise Architect EAP" shares the same options than other readers.
umlModel.read("Enterprise Architect EAP", "path/to/model.eap", options);
The uri parameter of "Enterprise Architect Application" reader can be used for selecting a specific package to read. Two format of uri are allowed:
Note that empty uri means reading of the whole project.
All available option names are defined in the class com.sodius.mdw.metamodel.uml21.io.ea.Options
EAAnnotations
.
false
EAAnnotations
.
Only listed properties will be extracted. Properties should be described by a qualifiedName category.propertyKey
The value could be a Collection of String, or a String containing all qualified names separated by a comma.
null
true
com.sodius.mdw.metamodel.uml21.io.ea.com.EAXMIVersion
EA21
, EA211
, EA212
, EA22
, EA23
, EA24
, EA241
EA241
false
, the entire content is on one line only.
true
false
com.sodius.mdw.metamodel.uml21.io.ea.com.DiagramXMLExport
NO_EXPORT
, EXPORT
, EXPORT_ALONG_ALTERNATE_IMAGES
NO_EXPORT
com.sodius.mdw.metamodel.uml21.io.ea.com.DiagramImageFormat
.
Note that the option OPTION_APP_DIAGRAM_XML_EXPORT
must be set to EXPORT_ALONG_ALTERNATE_IMAGES
so that images can be exported.
NONE
, EMF
, BMP
, GIF
, JPG
, PNG
NONE
The "Enterprise Architect Application" model reader enables to read diagram information. It also, optionally, enables to get diagram images. Note that the export of diagram images from Enterprise Architect takes a certain amount of time, depending on the number of diagrams.
import com.sodius.mdw.metamodel.uml21.io.ea.Options; ... Map<String, Object> options = new HashMap<String, Object>(); options.put(Options.OPTION_APP_DIAGRAM_XML_EXPORT, DiagramXMLExport.EXPORT_ALONG_ALTERNATE_IMAGES); options.put(Options.OPTION_APP_DIAGRAM_IMAGE_FORMAT, DiagramImageFormat.PNG); MDWorkbench workbench = MDWorkbenchFactory.create(); Model umlModel = workbench.getMetamodelManager().getMetamodel("uml21").createModel(); umlModel.read("Enterprise Architect Application", "", options); // loop on all diagrams for (Diagram diagram : model.<Diagram>getInstances("Diagram")) { System.out.println("Diagram: " + diagram.getName()); // query the diagram image DiagramFileImage image = (DiagramFileImage) model.getDiagram(diagram, new DiagramOptions()); System.out.println("Image: " + image.getFile()); image.dispose(); } ... umlModel.clear();
Enterprise Architect stores information in XMI extensions,
notably for data that is modelized in the tool but that is not part of the UML standard.
You can access such extra data using the EAAnnotations
class.
For example, consider the following declarations in Enterprise Architect XMI file:
<model ea_guid="{B776A356-A0B4-4a4d-95B1-FEF6E4E1E991}" ea_localid="2"/> <type type="void" const="false" static="false" isAbstract="false" synchronised="0" pure="0" isQuery="false"/>
This extra data can accessed using the following code:
import com.sodius.mdw.metamodel.uml21.io.ea.EAAnnotations; import com.sodius.mdw.metamodel.uml21.io.ea.Options; ... Map<String, Object> options = new HashMap<String, Object>(); options.put(Options.OPTION_XMI_READ_EXTENSIONS, true); MDWorkbench workbench = MDWorkbenchFactory.create(); Model umlModel = workbench.getMetamodelManager().getMetamodel("uml21").createModel(); umlModel.read("Enterprise Architect Application", "", options); Operation myOperation = ...; String static = EAAnnotations.getProperties(myOperation, "type").getProperty("static"); Strig uid = EAAnnotations.getProperties(myOperation, "model").getProperty("ea_guid"); ... umlModel.clear(); workbench.shutdown();
The "Enterprise Architect Application" model writer enables to connect to the active Enterprise Architect application to write the model in the currently loaded project.
The uri parameter of "Enterprise Architect Application" writer can be used for selecting a specific package into which the writing will start. Two uri formats are allowed:
Note that empty uri means writing in the root
Enterprise Architect identifies elements through their GUIDs. XMI IDs are reflecting the GUIDs in an xmi file:
Notes: deterministic XMIID generation is useful for usecases requiring multiple writings. This ensure the stability of XMI IDs over generations. A perfect seed is a seed which identify the element : it needs to be stable over time, and unique compared to other elements.
A logger enables to output information directly into the active Enterprise Architect application Output view:
import com.sodius.mdw.metamodel.uml21.io.ea.com.EAApplicationLogger; ... EAApplicationLogger logger = new EAApplicationLogger("MyTab"); logger.clear(); // clear existing entries in the tab logger.info("Logging a message") logger.error("Logging an issue");
Enterprise Architect native XMI import and export operations can be automated using the EAApplication
class, e.g.:
import com.sodius.mdw.metamodel.uml21.io.ea.com.EAApplication; ... EAApplication application = EAApplication.getActiveApplication(); try { application.exportXMI(outputXMIFile, packageIDToExport); } finally { application.dispose(); }
Automating Enterprise Architect supports two different modes:
EAApplication.getActiveApplication()
method
to connect to the active Enterprise Architect application.
EAApplication.createApplication(File)
method
to create a new hidden Enterprise Architect application and to load an EAP file.
Available information
MDAccess for UML API Reference
MDAccess for Enterprise Architect API Reference