de.matthias_burbach.flux
Class XmiModelBuilder

java.lang.Object
  extended byde.matthias_burbach.flux.XmiModelBuilder
All Implemented Interfaces:
ModelBuilder

public class XmiModelBuilder
extends java.lang.Object
implements ModelBuilder

Builds the internal UML model representation from an XMI 1.1 UML 1.3 file.

Has been developed for and tested with input files that were created with Rational Rose v2002 and exported with the UniSys XMI 1.1 / UML 1.3 add-in. Other tools or versions are likely to produce (slightly) incompatible XMI results. In such cases a different implementation of ModelBuilder must be used. If there are only minor differences to what this implementation can process a pre-transformation might solve the problem most easily (e. g. using XSLT).

Author:
Matthias Burbach

Constructor Summary
XmiModelBuilder()
           
 
Method Summary
protected  void addActionsToState(org.jdom.Element stateElement, State state)
          Adds actions to the state that result from the following XPath select (relative to the state element):
'UML:State.doActivity/ UML:ActionSequence/ UML:ActionSequence.action/ UML:UninterpretedAction'
protected  void assignStereotypesToClasses(org.jdom.Element modelElement, java.util.HashMap classes)
           
protected  void assignStereotypesToStates(org.jdom.Element modelElement, java.util.HashMap states)
          Reads stereotypes using the XPath select 'descendant::UML:Stereotype' (relative to modelElement) and assigns them to the states they are linked to by refIds listed in the extendedElement attribute.
protected  void assignTransitionsToStates(org.jdom.Element modelElement, java.util.HashMap states, java.util.HashMap events)
          Creates UML transitions from the XPath select 'descendant::UML:Transition' (relative to modelElement) and assigns them to the states they are linked to.
protected  void assignVariablesToStates(java.util.HashMap states, java.util.Vector variables)
           
 Model build(java.lang.String sourceUrl)
          Loads the XMI document from the sourceUrl and builds the model from it.
protected  Model buildModelFromXmiDocument(org.jdom.Document xmiDocument)
          Builds the model from the XMI document.
protected  java.util.Vector createAttributesForClass(org.jdom.Element classElement)
          Creates UML attributes from the XPath select 'descendant::UML:Attribute' (relative to classElement)
protected  java.util.HashMap createClasses(org.jdom.Element modelElement)
          Creates UML classes from the XPath select 'descendant::UML:Class' (relative to modelElement)
protected  java.util.HashMap createEvents(org.jdom.Element modelElement)
          Creates UML events from the XPath select 'descendant::UML:SignalEvent' (relative to modelElement)
protected  java.util.HashMap createStates(org.jdom.Element modelElement)
          Creates UML states from the following XPath selects (relative to modelElement): 'descendant::UML:SimpleState' 'descendant::UML:ActionState' 'descendant::UML:FinalState'
protected  java.util.HashMap createStatesForPath(org.jdom.Element modelElement, java.lang.String xPathExpression)
          Creates states from the state elements that can be selected with the xPathExpression (relative to modelElement);
protected  java.util.Vector createVariables(org.jdom.Element modelElement)
          Creates variables from classes with stereotype 'Variable'.
protected  Variable findVariableByName(java.util.Vector variables, java.lang.String variableName)
           
protected  java.util.List getSortedStates(java.util.Collection states)
          Sorts the states passed in by name (the order of states will affect the order of generated <action> elements).
protected  void sortTransitions(State state)
          Sorts the outbound transitions of state by label, i. e. event name or guard condition if the event name is not defined.
protected  void sortTransitionsForEachState(java.util.Collection states)
          Sorts the transitions for each state by label, i. e. event name or guard condition if the event name is not defined (the order of transitions will affect the order of several generated <action> and <forward> elements).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmiModelBuilder

public XmiModelBuilder()
Method Detail

build

public Model build(java.lang.String sourceUrl)
            throws java.lang.Exception
Loads the XMI document from the sourceUrl and builds the model from it.

Specified by:
build in interface ModelBuilder
Parameters:
sourceUrl - the location of the file to build from
Returns:
the model built
Throws:
java.lang.Exception - if anything goes wrong unexpectedly.

buildModelFromXmiDocument

protected Model buildModelFromXmiDocument(org.jdom.Document xmiDocument)
                                   throws java.lang.Exception
Builds the model from the XMI document.

Parameters:
xmiDocument - the XMI 1.1 UML 1.3 document that contains exactly one activity diagram modelling the web application module
Returns:
the UML model
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

assignVariablesToStates

protected void assignVariablesToStates(java.util.HashMap states,
                                       java.util.Vector variables)
Parameters:
states - the states variables are to be assigned to
variables - the variables to be assigned to 0, 1 or more states

findVariableByName

protected Variable findVariableByName(java.util.Vector variables,
                                      java.lang.String variableName)
Parameters:
variables - the set of variables to search in
variableName - the name of the variable to be found
Returns:
the variable found or null

assignStereotypesToClasses

protected void assignStereotypesToClasses(org.jdom.Element modelElement,
                                          java.util.HashMap classes)
                                   throws java.lang.Exception
Parameters:
modelElement -
classes -
Throws:
java.lang.Exception

createVariables

protected java.util.Vector createVariables(org.jdom.Element modelElement)
                                    throws java.lang.Exception
Creates variables from classes with stereotype 'Variable'.

Parameters:
modelElement - the model element to select from
Returns:
the variables of type Variable
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

getSortedStates

protected java.util.List getSortedStates(java.util.Collection states)
Sorts the states passed in by name (the order of states will affect the order of generated <action> elements).

Parameters:
states - the states built from the model file that are to be sorted
Returns:
the sorted list of states

sortTransitionsForEachState

protected void sortTransitionsForEachState(java.util.Collection states)
Sorts the transitions for each state by label, i. e. event name or guard condition if the event name is not defined (the order of transitions will affect the order of several generated <action> and <forward> elements).

Parameters:
states - the states whose outbound transitions are to be sorted

sortTransitions

protected void sortTransitions(State state)
Sorts the outbound transitions of state by label, i. e. event name or guard condition if the event name is not defined.

Parameters:
state - the state whose outbound transitions are to be sorted

assignTransitionsToStates

protected void assignTransitionsToStates(org.jdom.Element modelElement,
                                         java.util.HashMap states,
                                         java.util.HashMap events)
                                  throws java.lang.Exception
Creates UML transitions from the XPath select 'descendant::UML:Transition' (relative to modelElement) and assigns them to the states they are linked to. Creates unnamed but guarded events and attaches them together with the named but unguarded events passed in to the transitions. Sets the transition's action if specified (not to be confounded with an action activity!).

Parameters:
modelElement - the model element to select from
states - the states transitions are to be assigned to
events - the named events that need to be attached to the transitions
Throws:
java.lang.Exception

createEvents

protected java.util.HashMap createEvents(org.jdom.Element modelElement)
                                  throws java.lang.Exception
Creates UML events from the XPath select 'descendant::UML:SignalEvent' (relative to modelElement)

Parameters:
modelElement - the model element to select from
Returns:
the events of type Event hashed by their event element counterpart's xmi.id
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

createStates

protected java.util.HashMap createStates(org.jdom.Element modelElement)
                                  throws java.lang.Exception
Creates UML states from the following XPath selects (relative to modelElement):

Parameters:
modelElement - the model element to select from
Returns:
the states of type State hashed by their state element counterpart's xmi.id
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

createStatesForPath

protected java.util.HashMap createStatesForPath(org.jdom.Element modelElement,
                                                java.lang.String xPathExpression)
                                         throws java.lang.Exception
Creates states from the state elements that can be selected with the xPathExpression (relative to modelElement);

Parameters:
modelElement - the model element to select from
xPathExpression - the select path
Returns:
the states of type State hashed by their state element counterpart's xmi.id
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

addActionsToState

protected void addActionsToState(org.jdom.Element stateElement,
                                 State state)
                          throws java.lang.Exception
Adds actions to the state that result from the following XPath select (relative to the state element):
 'UML:State.doActivity/
      UML:ActionSequence/
          UML:ActionSequence.action/
              UML:UninterpretedAction'
 

Parameters:
stateElement - the state element to select from
state - the state to add the actions to
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

assignStereotypesToStates

protected void assignStereotypesToStates(org.jdom.Element modelElement,
                                         java.util.HashMap states)
                                  throws java.lang.Exception
Reads stereotypes using the XPath select 'descendant::UML:Stereotype' (relative to modelElement) and assigns them to the states they are linked to by refIds listed in the extendedElement attribute.

Parameters:
modelElement - the model element to select from
states - the states stereotypes get assigned to
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

createClasses

protected java.util.HashMap createClasses(org.jdom.Element modelElement)
                                   throws java.lang.Exception
Creates UML classes from the XPath select 'descendant::UML:Class' (relative to modelElement)

Parameters:
modelElement - the model element to select from
Returns:
the classes of type Class hashed by their class element counterpart's xmi.id
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

createAttributesForClass

protected java.util.Vector createAttributesForClass(org.jdom.Element classElement)
                                             throws java.lang.Exception
Creates UML attributes from the XPath select 'descendant::UML:Attribute' (relative to classElement)

Parameters:
classElement - the class element to select from
Returns:
the attributes of type String
Throws:
java.lang.Exception - if anything goes unexpectedly wrong