Reading Extensions

An Enterprise Architect model, exported from Enterprise Architect, can be divided into two parts:

Here is a sample xml file exported from Enterprise Architect:
<uml:Model xmi:type="uml:Model" name="EA_Model" visibility="public">
...
</uml:Model>
<xmi:Extension extender="Enterprise Architect" extenderID="6.5">
...
</xmi:Extension>
To better manage the Extensions reading, two Options have been introduced:

Options.OPTION_XMI_READ_EXTENSIONS

This options determines whether Enterprise Architect specific extensions in the XMI file must be parsed. By default, they are not parsed.
Here is a sample code that shows how to read the Enterprise Architect extensions:

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

Options.OPTION_XMI_READ_EXTENSIONS_SUBSET

If the Extensions are parsed, it is possible to determine whether Enterprise Architect specific extensions in the XMI file must be parsed.
Properties should be described by a qualifiedName category.propertyKey.
Here is a sample xml file exported from Enterprise Architect:

<xmi:Extension extender="Enterprise Architect" extenderID="6.5">
       <elements>...</elements>
       <connectors>...</connectors>
       ...
</xmi:Extension>
   <element xmi:idref="EAID_19A79944_2484_4e77_A373_D50FE935071B" xmi:type="uml:Text" name="Text" scope="public">
    <model package="EAPK_1FA6553F_CF5C_486f_BD38_8E7C24F0D7CE" tpos="0" ea_localid="2164" ea_eleType="element" name="Text"/>
    <properties documentation="Using Images on Elements" isSpecification="false" sType="Text" nType="0" scope="public"/>
    <project version="1.0" phase="1.0" created="2005-10-19 16:55:09" modified="2005-10-19 16:55:48" complexity="1" status="Proposed"/>
    <code gentype="<none>"/>
    <style appearance="BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=8388608;VSwimLanes=1;HSwimLanes=1;BorderStyle=0;"/>
    <modelDocument/>
    <tags/>
    <xrefs/>
    <extendedProperties tagged="0" package_name="Modeling Basics"/>
     <attributes>
     <attribute xmi:idref="EAID_E2EBF98D_C6F1_4013_9E54_793F8B7BAAA6" name="m_Author" scope="Public">
       <initial/>
       <documentation value="Author of the book."/>
     </attributes>
   </element>
The option Options.OPTION_XMI_READ_EXTENSIONS_SUBSET set to "properties.documentation,documentation.value" will parse

Using Images on Elements and Author of the book.

<xmi:Extension extender="Enterprise Architect" extenderID="6.5">
       <elements>...</elements>
       <connectors>...</connectors>
       ...
</xmi:Extension>
   <element xmi:idref="EAID_19A79944_2484_4e77_A373_D50FE935071B" xmi:type="uml:Text" name="Text" scope="public">
    <model package="EAPK_1FA6553F_CF5C_486f_BD38_8E7C24F0D7CE" tpos="0" ea_localid="2164" ea_eleType="element" name="Text"/>
    <properties documentation="Using Images on Elements" isSpecification="false" sType="Text" nType="0" scope="public"/>
    <project version="1.0" phase="1.0" created="2005-10-19 16:55:09" modified="2005-10-19 16:55:48" complexity="1" status="Proposed"/>
    <code gentype="<none>"/>
    <style appearance="BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=8388608;VSwimLanes=1;HSwimLanes=1;BorderStyle=0;"/>
    <modelDocument/>
    <tags/>
    <xrefs/>
    <extendedProperties tagged="0" package_name="Modeling Basics"/>
     <attributes>
     <attribute xmi:idref="EAID_E2EBF98D_C6F1_4013_9E54_793F8B7BAAA6" name="m_Author" scope="Public">
       <initial/>
       <documentation value="Author of the book."/>
     </attributes>
   </element>

Managing Extensions

The Class EAAnnotations can be used to manage the Extensions Read.

Getting Properties for a Category

Here is a sample code that show how to get the Properties corresponding to a Category

Properties properties = EAAnnotations.getProperties(text, "project");
For the following Enterprise Architect Extension:
<xmi:Extension extender="Enterprise Architect" extenderID="6.5">
       <elements>...</elements>
       <connectors>...</connectors>
       ...
</xmi:Extension>
   <element xmi:idref="EAID_19A79944_2484_4e77_A373_D50FE935071B" xmi:type="uml:Text" name="Text" scope="public">
    <model package="EAPK_1FA6553F_CF5C_486f_BD38_8E7C24F0D7CE" tpos="0" ea_localid="2164" ea_eleType="element" name="Text"/>
    <properties documentation="Using Images on Elements" isSpecification="false" sType="Text" nType="0" scope="public"/>
    <project version="1.0" phase="1.0" created="2005-10-19 16:55:09" modified="2005-10-19 16:55:48" complexity="1" status="Proposed"/>
    <code gentype="<none>"/>
    <style appearance="BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=8388608;VSwimLanes=1;HSwimLanes=1;BorderStyle=0;"/>
    <modelDocument/>
    <tags/>
    <xrefs/>
    <extendedProperties tagged="0" package_name="Modeling Basics"/>
     <attributes>
     <attribute xmi:idref="EAID_E2EBF98D_C6F1_4013_9E54_793F8B7BAAA6" name="m_Author" scope="Public">
       <initial/>
       <documentation value="Author of the book."/>
     </attributes>
   </element>
This will return the following Properties:
	version="1.0"
	phase="1.0"
	created="2005-10-19 16:55:09"
	modified="2005-10-19 16:55:48"
	complexity="1"
	status="Proposed"

Getting a Property for a qualified Category

Here is a sample code that show how to get the Properties corresponding to a Category

String value = EAAnnotations.getProperty(text, "project.version");
For the following Enterprise Architect Extension:
<xmi:Extension extender="Enterprise Architect" extenderID="6.5">
       <elements>...</elements>
       <connectors>...</connectors>
       ...
</xmi:Extension>
   <element xmi:idref="EAID_19A79944_2484_4e77_A373_D50FE935071B" xmi:type="uml:Text" name="Text" scope="public">
    <model package="EAPK_1FA6553F_CF5C_486f_BD38_8E7C24F0D7CE" tpos="0" ea_localid="2164" ea_eleType="element" name="Text"/>
    <properties documentation="Using Images on Elements" isSpecification="false" sType="Text" nType="0" scope="public"/>
    <project version="1.0" phase="1.0" created="2005-10-19 16:55:09" modified="2005-10-19 16:55:48" complexity="1" status="Proposed"/>
    <code gentype="<none>"/>
    <style appearance="BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=8388608;VSwimLanes=1;HSwimLanes=1;BorderStyle=0;"/>
    <modelDocument/>
    <tags/>
    <xrefs/>
    <extendedProperties tagged="0" package_name="Modeling Basics"/>
     <attributes>
     <attribute xmi:idref="EAID_E2EBF98D_C6F1_4013_9E54_793F8B7BAAA6" name="m_Author" scope="Public">
       <initial/>
       <documentation value="Author of the book."/>
     </attributes>
   </element>
This will return the value: 1.0.

Setting a Property

Here is a sample code that show how to set a Property

EAAnnotations.setProperty(element, "extendedProperties", "reusesProperty", EAXMIIDManager.convertXMIID2GUID(elementID));

Related tasks
Reading UML Data
Reading Enterprise Architect Data
Programming the Reader Configuration
Reading a Package
Managing Ids

Related references
MDAccess UML API Reference
MDAccess for MagicDraw API Reference