de.matthias_burbach.flux
Class StrutsConfigGenerator

java.lang.Object
  extended byde.matthias_burbach.flux.StrutsConfigGenerator

public class StrutsConfigGenerator
extends java.lang.Object

Generates a struts-config-<module>.xml file from both a UML activity model and the previous version of the struts-config-<module>.xml file.

Is configurable by config/flux-config.xml and properties.

Author:
Matthias Burbach

Nested Class Summary
protected  class StrutsConfigGenerator.GeneratorMapping
          Maps from a UML stereotype of a state to a generator plug-in that is registered to generate action mappings from UML states having this stereotype.
 
Field Summary
protected  org.jdom.Document fluxConfigDocument
          The XML configuration of the generator specifiying the plug-ins.
protected  java.util.Properties settings
          The global settings that configure and parameterize the generation process.
 
Constructor Summary
StrutsConfigGenerator(java.util.Properties settings)
          Convenience constructor, calls StrutsConfigGenerator( Properties settings, Document fluxConfigDocument) passing null as second parameter.
StrutsConfigGenerator(java.util.Properties settings, org.jdom.Document fluxConfigDocument)
          Attempts to load config/flux-config.xml if fluxConfigDocument is null.
 
Method Summary
protected  void backupFile(java.lang.String pathAndFile)
          Backs up the file passed in if the settings property 'CreateBackup' is not 'false'.
 void generate()
          Performs the generation process.
protected  void generateActionMappings(StateMachine stateMachine, org.jdom.Document oldDocument, org.jdom.Document newDocument)
          Prepares and drives the actual generation that is performed by the plugged-in generators being registered for stereotyped states.
protected  void generateForStereotype(StateMachine stateMachine, org.jdom.Document oldDocument, org.jdom.Element oldActionMappingsElement, org.jdom.Document newDocument, org.jdom.Element newActionMappingsElement, java.lang.String stereotype, ActionMappingGenerator generator)
          Executes the (begin, (generate)*, end) cycle for the generator passed in and all the states having the specified stereotype.
protected  org.jdom.Element getActionMappingsElement(org.jdom.Document document)
          Extracts the <action-mappings> element from the struts-config document passed in.
protected  java.lang.String getDefaultGeneratorComment()
           
protected  ActionMappingGenerator getGenerator(java.lang.String type)
          Instantiates the ActionMappingGenerator specified by type using the default constructor.
protected  org.jdom.Comment getGeneratorComment()
          If the settings property 'GeneratorComment' is specified its value is returned, else the default comment is returned.
protected  java.util.List getGeneratorMappings()
          Constructs the Java representations of the generator mappings defined in the flux-config XML document.
protected  ModelBuilder getModelBuilder()
          Instantiates the model builder plug-in as specified in the flux-config document.
protected  ModelChecker getModelChecker()
          Instantiates the model checker plug-in as specified in the flux-config document.
static java.lang.String getModelCheckerProblemReport(ModelCheckerException mce)
          Constructs a single, long string from all the detail messages in the model checker exception.
protected  java.lang.String getPathAndFile(java.lang.String fileType)
          Concatenates the two properties <fileType>Path and <fileType>File to construct an absolute path.
protected  StateMachine loadStateMachine()
          Constructs the input path and file from the settings properties 'InputPath' and 'InputFile', lets the model builder build and the model checker check the internal representation of the UML model.
static void log(java.lang.String message)
          Adds a timestamp to the message and logs it to the console.
static void main(java.lang.String[] args)
          Executes the generator in command line mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

settings

protected java.util.Properties settings
The global settings that configure and parameterize the generation process.


fluxConfigDocument

protected org.jdom.Document fluxConfigDocument
The XML configuration of the generator specifiying the plug-ins.

Constructor Detail

StrutsConfigGenerator

public StrutsConfigGenerator(java.util.Properties settings)
                      throws java.lang.Exception
Convenience constructor, calls StrutsConfigGenerator( Properties settings, Document fluxConfigDocument) passing null as second parameter.


StrutsConfigGenerator

public StrutsConfigGenerator(java.util.Properties settings,
                             org.jdom.Document fluxConfigDocument)
                      throws java.lang.Exception
Attempts to load config/flux-config.xml if fluxConfigDocument is null.

Parameters:
settings - the global settings that configure and parameterize the generation process
fluxConfigDocument - the basic configuration of the generator, may be null
Throws:
java.lang.Exception - if anything goes unexpectedly wrong
Method Detail

generate

public void generate()
              throws ModelCheckerException,
                     java.lang.Exception
Performs the generation process.

Throws:
ModelCheckerException - if the model checker detected model constraint violations
java.lang.Exception - if anything goes unexpectedly wrong

getPathAndFile

protected java.lang.String getPathAndFile(java.lang.String fileType)
Concatenates the two properties <fileType>Path and <fileType>File to construct an absolute path.

Parameters:
fileType - the common prefix of the two file properties to be concatenated
Returns:
the concatenated path and name of the file

backupFile

protected void backupFile(java.lang.String pathAndFile)
                   throws java.lang.Exception
Backs up the file passed in if the settings property 'CreateBackup' is not 'false'.

The backup is copied to the same directory the original is in. It is named '<original-file-name>.old'.

Parameters:
pathAndFile - the file to be backed up
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

generateActionMappings

protected void generateActionMappings(StateMachine stateMachine,
                                      org.jdom.Document oldDocument,
                                      org.jdom.Document newDocument)
                               throws java.lang.Exception
Prepares and drives the actual generation that is performed by the plugged-in generators being registered for stereotyped states.

Parameters:
stateMachine - the state machine to generate from
oldDocument - the previous version of the generated struts-config
newDocument - the new struts-config being generated
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

getGeneratorMappings

protected java.util.List getGeneratorMappings()
                                       throws java.lang.Exception
Constructs the Java representations of the generator mappings defined in the flux-config XML document.

Returns:
the list of generator mappings of type StrutsConfigGenerator.GeneratorMapping
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

getGenerator

protected ActionMappingGenerator getGenerator(java.lang.String type)
                                       throws java.lang.Exception
Instantiates the ActionMappingGenerator specified by type using the default constructor.

Parameters:
type - the fully qualified name of the class to be instantiated
Returns:
the instantiated object
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

getActionMappingsElement

protected org.jdom.Element getActionMappingsElement(org.jdom.Document document)
                                             throws java.lang.Exception
Extracts the <action-mappings> element from the struts-config document passed in.

Parameters:
document - the struts-config document
Returns:
the <action-mappings> from the document
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

generateForStereotype

protected void generateForStereotype(StateMachine stateMachine,
                                     org.jdom.Document oldDocument,
                                     org.jdom.Element oldActionMappingsElement,
                                     org.jdom.Document newDocument,
                                     org.jdom.Element newActionMappingsElement,
                                     java.lang.String stereotype,
                                     ActionMappingGenerator generator)
                              throws java.lang.Exception
Executes the (begin, (generate)*, end) cycle for the generator passed in and all the states having the specified stereotype.

Parameters:
stateMachine - the state machine to be generated from
oldDocument - the previous version of the struts-config document
oldActionMappingsElement - the previous version of the element
newDocument - the new document under construction
newActionMappingsElement - the new element under construction
stereotype - the stereotype of states to be considered
generator - the generator plug-in to be called
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

loadStateMachine

protected StateMachine loadStateMachine()
                                 throws ModelCheckerException,
                                        java.lang.Exception
Constructs the input path and file from the settings properties 'InputPath' and 'InputFile', lets the model builder build and the model checker check the internal representation of the UML model.

Returns:
the UML state machine of the built and checked UML model
Throws:
ModelCheckerException - if the model checker finds model constraint violations
java.lang.Exception - if anything goes unexpectedly wrong

getModelBuilder

protected ModelBuilder getModelBuilder()
                                throws java.lang.Exception
Instantiates the model builder plug-in as specified in the flux-config document.

Returns:
the plugged-in model builder instance
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

getModelChecker

protected ModelChecker getModelChecker()
                                throws java.lang.Exception
Instantiates the model checker plug-in as specified in the flux-config document.

Returns:
the plugged-in model checker instance
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

getGeneratorComment

protected org.jdom.Comment getGeneratorComment()
If the settings property 'GeneratorComment' is specified its value is returned, else the default comment is returned.

Returns:
the introductory XML comment of the generator

getDefaultGeneratorComment

protected java.lang.String getDefaultGeneratorComment()
Returns:
the time stamped default introductory comment of the generator

main

public static void main(java.lang.String[] args)
Executes the generator in command line mode. Writes normal operation messages to stdout and errors to stderr. Exits with return code 0 if executed successfully and with return code 1 if errors occurred.

Usage: java [..] StrutsConfigGenerator <command line parameters>

Mandatory command line parameters:
  1. the absolute path of the settings property file

Parameters:
args - the command line parameters as described above

log

public static void log(java.lang.String message)
Adds a timestamp to the message and logs it to the console.

Parameters:
message - the message to be logged

getModelCheckerProblemReport

public static java.lang.String getModelCheckerProblemReport(ModelCheckerException mce)
Constructs a single, long string from all the detail messages in the model checker exception.

Parameters:
mce - the model checker exception to read the details from
Returns:
the concatenated problem report