Reading and Writing Enterprise Architect Data

Connectors

Model Readers:

Model Writers:

Reading data from Enterprise Architect

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);

Reading a specific Package

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.

Reader Options

All available option names are defined in the class com.sodius.mdw.metamodel.uml21.io.ea.Options

Reading Diagrams from Enterprise Architect

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();

Reading Enterprise Architect XMI Extensions

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();

Writing data directly to Enterprise Architect

The "Enterprise Architect Application" model writer enables to connect to the active Enterprise Architect application to write the model in the currently loaded project.

Writing into a specific Package

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

Controlling XMI IDs and GUIDs

Enterprise Architect identifies elements through their GUIDs. XMI IDs are reflecting the GUIDs in an xmi file:

Usecases

APIs for controlling XMI IDs

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.

Logging information to Enterprise Architect

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");

Getting additional information from Enterprise Architect application

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:

Available information

Related reference
MDAccess for UML API Reference
MDAccess for Enterprise Architect API Reference