de.matthias_burbach.flux
Class ChameleonModelBuilder

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

public class ChameleonModelBuilder
extends java.lang.Object
implements ModelBuilder

Builds the internal UML model representation from an XML file that was exported with the Rational Rose add in 'Chameleon'.

Has been developed for and tested with input files that were created with Rational Rose v2002 and exported with the Chameleon add-in, which is part of the Flux distribution since Flux version 1.1.0. Chameleon supersedes the Unisys XMI export add in as the preferred way of exporting Rational Rose models because the XMI add in does not export the documentation property of transitions in state/activity diagrams. As a solution was required to support multi instance modelling in Rose Chameleon was created and became part of Flux.

Author:
Matthias Burbach

Constructor Summary
ChameleonModelBuilder()
           
 
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):
'DoAction'
protected  void assignTransitionsToStates(org.jdom.Element modelElement, java.util.HashMap states)
          Creates UML transitions from the XPath select 'descendant::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 Chameleon XML document from the sourceUrl and builds the model from it.
protected  Model buildModelFromXmlDocument(org.jdom.Document xmlDocument)
          Builds the model from the Chameleon XML document.
protected  java.util.Vector createAttributesForClass(org.jdom.Element classElement)
          Creates UML attributes from the XPath select 'descendant::Attribute' (relative to classElement)
protected  java.util.List createClasses(org.jdom.Element modelElement)
          Creates UML classes from the XPath select 'descendant::Class' (relative to modelElement)
protected  java.util.HashMap createStates(org.jdom.Element modelElement)
          Creates UML states from the following XPath selects (relative to modelElement): 'descendant::State' 'descendant::Activity'
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 all 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

ChameleonModelBuilder

public ChameleonModelBuilder()
Method Detail

build

public Model build(java.lang.String sourceUrl)
            throws java.lang.Exception
Loads the Chameleon XML 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.

buildModelFromXmlDocument

protected Model buildModelFromXmlDocument(org.jdom.Document xmlDocument)
                                   throws java.lang.Exception
Builds the model from the Chameleon XML document.

Parameters:
xmlDocument - the Chameleon XML document that contains exactly one activity diagram modelling the web application module plus optional classes that model mode variables
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

createVariables

protected java.util.Vector createVariables(org.jdom.Element modelElement)
                                    throws java.lang.Exception
Creates variables from all 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)
                                  throws java.lang.Exception
Creates UML transitions from the XPath select 'descendant::Transition' (relative to modelElement) and assigns them to the states they are linked to. Creates all events and attaches them 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
Throws:
java.lang.Exception

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 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 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):
'DoAction'

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

createClasses

protected java.util.List createClasses(org.jdom.Element modelElement)
                                throws java.lang.Exception
Creates UML classes from the XPath select 'descendant::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::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