Browse DevX
Sign up for e-mail newsletters from DevX


Tracking Dependencies with Components and XMI : Page 2

XMI is a great technology for anyone who builds applications from models, allowing you to use information contained in those models for big upside. But if you want your model data to be effective, components are an essential building block. Learn to get your dependencies straight by making traceable components.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Differentiating Components and Component Instances
In the next example I will add a component instance with the same name as the component from the previous example. This provides for some interesting XMI. The only difference in XMI between an instantiated component and an abstract component is one encapsulated XMI statement:

<UML:TaggedValue tag="classifier" value="EAID_3603F7AF_F6B4_4393_A23A_4F138829F673"/>

For those that use Sparx Systems' Enterprise Architect the classifier statement makes this unique. However, if exported to another tool (without the EA extensions), there is no way to tell the difference between the component and component instance.

Figure 3. Adding Traceability: The Payments executable has the Payments development software as its classifier. This adds traceability with the reference architecture for the Payments executable.

To separate the two components I will have to check for the tag. Because the tag is encapsulated in the Component XMI this is easy enough. There is one other small problem: There is a version tag in both components, but they mean two different things. In the instantiated component the version tag refers to the component, and in the abstract component it refers to the language version. So to separate the components I have to identify them as being either abstract or instantiated. In code I've added a few fields to the component object to differentiate between the component and component instance:

public string Classifier { get { if (!_Instance) { return " "; } return _Classifier; } set { if (!_Instance) { _Classifier = " "; }else { _Classifier = value; } } }

I need to check whether the component is an instance before assigning a value to the classifier. This seems obvious but the tendancy is to assume that the code using the Component class checks for the _Instance flag before getting _Classifier.

Figure 4. Comparing Tags: The output demonstrates that the only difference between the two components is the classifier tag and the component ID. Without this tag they would be indistinguishable. Notice that the classifier tag in the second component refers to the original component ID. Also the component and component instance have the same name but different XMI IDs.
In the addComponent method I check the XMI to see if a component is an instance and then assign it as a clasifier if it is.

private void AddComponent(XmlTextReader p_readXMI) { string componentID; string componentName; string stereotypeName; Component component; componentName = p_readXMI.GetAttribute("name"); componentID = p_readXMI.GetAttribute("xmi.id"); component = new Component(componentID); component.Name = componentName; while (p_readXMI.Read() && (p_readXMI.NodeType == XmlNodeType.Element || p_readXMI.NodeType == XmlNodeType.Whitespace)) { switch (p_readXMI.LocalName) { case "ModelElement.stereotype": while (p_readXMI.Read() && (p_readXMI.NodeType == XmlNodeType.Element || p_readXMI.NodeType == XmlNodeType.Whitespace)) { if (p_readXMI.LocalName == "Stereotype") { stereotypeName = p_readXMI.GetAttribute("name"); component.Stereotype = stereotypeName; } } break; case "ModelElement.taggedValue": while (p_readXMI.Read() && (p_readXMI.NodeType == XmlNodeType.Element || p_readXMI.NodeType == XmlNodeType.Whitespace)) { if ((p_readXMI.LocalName == "TaggedValue")&& (p_readXMI.GetAttribute("tag") == "classifier")) { component.Instance = true; component.Classifier = p_readXMI.GetAttribute("value"); } } break; } } _components.Add(componentID, component); }

The final output (see Figure 4) has one abstract component without a classifier ID and one instantiated component with the classifier for the abstract component to which it refers.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date