org.argouml.uml.generator
Class Generator2

java.lang.Object
  extended byorg.argouml.uml.generator.Generator2
All Implemented Interfaces:
ArgoModule, NotationProvider2, Pluggable, PluggableNotation
Direct Known Subclasses:
GeneratorDisplay, GeneratorJava

public abstract class Generator2
extends Object
implements NotationProvider2, PluggableNotation

This class is the abstract super class that defines a code generation framework. It is basically a depth-first traversal of the UML model that generates strings as it goes. This framework should probably be redesigned to separate the traversal logic from the generation logic. See the Visitor design pattern in "Design Patterns", and the Demeter project.

Since:
0.15.6

Field Summary
private static Map generators
           
static String INDENT
          Two spaces used for indenting code in classes.
private  NotationName notationName
           
 
Fields inherited from interface org.argouml.application.api.Pluggable
PLUGIN_PREFIX, PLUGIN_TITLE, PLUGIN_VENDOR
 
Fields inherited from interface org.argouml.application.api.ArgoModule
MODULEFILENAME, MODULEFILENAME_ALTERNATE
 
Constructor Summary
Generator2(NotationName name)
          Constructor that sets the name of this notation.
 
Method Summary
 String generate(Object o)
          Generates code for some modelelement.
abstract  String generateAction(Object m)
          Generate the String representation for an Action.
abstract  String generateAssociation(Object a)
          Generate the String representation for an Association.
abstract  String generateAssociationEnd(Object ae)
          Generate the String representation for an AssociationEnd.
abstract  String generateAttribute(Object attr, boolean documented)
          Generate the String representation for an Attribute.
abstract  String generateClassifier(Object cls)
          Generate the String representation for a Classifier.
 String generateClassifierRef(Object cls)
          Generate the String representation for a ClassifierRef.
abstract  String generateEvent(Object m)
          Generate the String representation for an Event.
 String generateExpression(Object expr)
          Generate the String representation for an Expression.
abstract  String generateExtensionPoint(Object op)
          Generate the String representation for an ExtensionPoint.
abstract  String generateGuard(Object m)
          Generate the String representation for a Guard.
abstract  String generateMessage(Object m)
          Generate the String representation for a Message.
abstract  String generateMultiplicity(Object m)
          Generate the String representation for an Multiplicity.
 String generateName(String n)
          Convert a String to a name.
abstract  String generateObjectFlowState(Object m)
          Generate the String representation for a ObjectFlowState.
abstract  String generateOperation(Object op, boolean documented)
          Generate the String representation for an Operation.
abstract  String generatePackage(Object p)
          Generate the String representation for a Package.
abstract  String generateParameter(Object param)
          Generate the String representation for a Parameter.
abstract  String generateState(Object m)
          Generate the String representation for a State.
 String generateStereotype(Object st)
          Generate the String representation for a Stereotype.
abstract  String generateSubmachine(Object m)
          Generate the String representation for a Submachine.
abstract  String generateTaggedValue(Object s)
          Generate the String representation for a TaggedValue.
abstract  String generateTransition(Object m)
          Generate the String representation for a Transition.
 String generateUninterpreted(String un)
          Make a string non-null.
abstract  String generateVisibility(Object m)
          Generate the String representation for a Visibility.
static String getCodePath(Object me)
          Gets the path of the code base for a model element.
static Generator2 getGenerator(NotationName n)
          Access method that finds the correct generator based on a name.
 Vector getModulePopUpActions(Vector v, Object o)
          Calls all modules to let them add to a popup menu.
 NotationName getNotation()
           
 boolean inContext(Object[] o)
          A function which allows a plug-in to decide if it is available under a specific context.
 boolean initializeModule()
          Method called when Argo is loading a module.
 boolean isModuleEnabled()
          The default for any Generator is to be enabled.
 void setModuleEnabled(boolean enabled)
          Called to enable or disable a module programmatically.
 boolean shutdownModule()
          Method called when Argo is unloading a module.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.argouml.application.api.NotationProvider2
generateActionState, generateAssociationRole, generateStateBody
 
Methods inherited from interface org.argouml.application.api.ArgoModule
getModuleAuthor, getModuleDescription, getModuleKey, getModuleName, getModuleVersion
 

Field Detail

notationName

private NotationName notationName

INDENT

public static final String INDENT
Two spaces used for indenting code in classes.

See Also:
Constant Field Values

generators

private static Map generators
Constructor Detail

Generator2

public Generator2(NotationName name)
Constructor that sets the name of this notation.

Parameters:
name - The name.
Method Detail

getGenerator

public static Generator2 getGenerator(NotationName n)
Access method that finds the correct generator based on a name.

Parameters:
n - The name.
Returns:
a generator (or null if not found).

getNotation

public NotationName getNotation()
Specified by:
getNotation in interface NotationProvider2
Returns:
The name of this notation.
See Also:
NotationProvider2.getNotation()

generate

public String generate(Object o)
Generates code for some modelelement. Subclasses should implement this to generate code for different notations.

Parameters:
o - the element to be generated
Returns:
String the generated code

generateExtensionPoint

public abstract String generateExtensionPoint(Object op)
Description copied from interface: NotationProvider2
Generate the String representation for an ExtensionPoint.

Specified by:
generateExtensionPoint in interface NotationProvider2
Parameters:
op - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateExtensionPoint(Object)

generateOperation

public abstract String generateOperation(Object op,
                                         boolean documented)
Description copied from interface: NotationProvider2
Generate the String representation for an Operation.

Specified by:
generateOperation in interface NotationProvider2
Parameters:
op - Object to generate representation for.
documented - true if documentation shall be generated.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateOperation(Object, boolean)

generateAttribute

public abstract String generateAttribute(Object attr,
                                         boolean documented)
Description copied from interface: NotationProvider2
Generate the String representation for an Attribute.

Specified by:
generateAttribute in interface NotationProvider2
Parameters:
attr - Object to generate representation for.
documented - true if documentation shall be generated.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateAttribute(Object, boolean)

generateParameter

public abstract String generateParameter(Object param)
Description copied from interface: NotationProvider2
Generate the String representation for a Parameter.

Specified by:
generateParameter in interface NotationProvider2
Parameters:
param - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateParameter(Object)

generatePackage

public abstract String generatePackage(Object p)
Description copied from interface: NotationProvider2
Generate the String representation for a Package.

Specified by:
generatePackage in interface NotationProvider2
Parameters:
p - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generatePackage(Object)

generateClassifier

public abstract String generateClassifier(Object cls)
Description copied from interface: NotationProvider2
Generate the String representation for a Classifier.

Specified by:
generateClassifier in interface NotationProvider2
Parameters:
cls - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateClassifier(Object)

generateTaggedValue

public abstract String generateTaggedValue(Object s)
Description copied from interface: NotationProvider2
Generate the String representation for a TaggedValue.

Specified by:
generateTaggedValue in interface NotationProvider2
Parameters:
s - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateTaggedValue(Object)

generateAssociation

public abstract String generateAssociation(Object a)
Description copied from interface: NotationProvider2
Generate the String representation for an Association.

Specified by:
generateAssociation in interface NotationProvider2
Parameters:
a - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateAssociation(Object)

generateAssociationEnd

public abstract String generateAssociationEnd(Object ae)
Description copied from interface: NotationProvider2
Generate the String representation for an AssociationEnd.

Specified by:
generateAssociationEnd in interface NotationProvider2
Parameters:
ae - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateAssociationEnd(Object)

generateMultiplicity

public abstract String generateMultiplicity(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for an Multiplicity.

Specified by:
generateMultiplicity in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateMultiplicity(Object)

generateObjectFlowState

public abstract String generateObjectFlowState(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a ObjectFlowState.

Specified by:
generateObjectFlowState in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateObjectFlowState(Object)

generateState

public abstract String generateState(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a State.

Specified by:
generateState in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateState(Object)

generateSubmachine

public abstract String generateSubmachine(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a Submachine.

Specified by:
generateSubmachine in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateSubmachine(Object)

generateTransition

public abstract String generateTransition(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a Transition.

Specified by:
generateTransition in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateTransition(Object)

generateAction

public abstract String generateAction(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for an Action.

Specified by:
generateAction in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateAction(Object)

generateGuard

public abstract String generateGuard(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a Guard.

Specified by:
generateGuard in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateGuard(Object)

generateMessage

public abstract String generateMessage(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a Message.

Specified by:
generateMessage in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateMessage(Object)

generateEvent

public abstract String generateEvent(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for an Event.

Specified by:
generateEvent in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateEvent(Object)

generateVisibility

public abstract String generateVisibility(Object m)
Description copied from interface: NotationProvider2
Generate the String representation for a Visibility.

Specified by:
generateVisibility in interface NotationProvider2
Parameters:
m - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateVisibility(Object)

generateExpression

public String generateExpression(Object expr)
Description copied from interface: NotationProvider2
Generate the String representation for an Expression.

Specified by:
generateExpression in interface NotationProvider2
Parameters:
expr - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateExpression(Object)

generateName

public String generateName(String n)
Description copied from interface: NotationProvider2
Convert a String to a name.

TODO: What is the purpose of this function? Is it really needed?

Specified by:
generateName in interface NotationProvider2
Parameters:
n - The String to be converted.
Returns:
The name.
See Also:
NotationProvider2.generateName(String)

generateUninterpreted

public String generateUninterpreted(String un)
Make a string non-null.

What is the purpose of this function? Shouldn't it be private static?

Parameters:
un - The String.
Returns:
a non-null string.

generateClassifierRef

public String generateClassifierRef(Object cls)
Description copied from interface: NotationProvider2
Generate the String representation for a ClassifierRef.

Specified by:
generateClassifierRef in interface NotationProvider2
Parameters:
cls - Object to generate representation for.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateClassifierRef(Object)

generateStereotype

public String generateStereotype(Object st)
Description copied from interface: NotationProvider2
Generate the String representation for a Stereotype.

Specified by:
generateStereotype in interface NotationProvider2
Parameters:
st - Object to generate representation for. This can also be a Collection with all stereotypes.
Returns:
The String representation of the object.
See Also:
NotationProvider2.generateStereotype(Object)

getModulePopUpActions

public Vector getModulePopUpActions(Vector v,
                                    Object o)
Description copied from interface: ArgoModule
Calls all modules to let them add to a popup menu.

Specified by:
getModulePopUpActions in interface ArgoModule
Parameters:
v - Vector of actions
o - which the actions are valid for
Returns:
Vector containing pop-up actions
See Also:
ArgoModule.getModulePopUpActions( Vector, Object)

shutdownModule

public boolean shutdownModule()
Description copied from interface: ArgoModule
Method called when Argo is unloading a module.

Specified by:
shutdownModule in interface ArgoModule
Returns:
true if the module terminated properly.
See Also:
ArgoModule.shutdownModule()

initializeModule

public boolean initializeModule()
Description copied from interface: ArgoModule
Method called when Argo is loading a module.

Specified by:
initializeModule in interface ArgoModule
Returns:
true if the module initialized properly.
See Also:
ArgoModule.initializeModule()

setModuleEnabled

public void setModuleEnabled(boolean enabled)
Description copied from interface: ArgoModule
Called to enable or disable a module programmatically.

Specified by:
setModuleEnabled in interface ArgoModule
Parameters:
enabled - true to enable module, false to disable
See Also:
ArgoModule.setModuleEnabled(boolean)

inContext

public boolean inContext(Object[] o)
Description copied from interface: Pluggable
A function which allows a plug-in to decide if it is available under a specific context. One example of a plugin with multiple criteria is the PluggableMenu. PluggableMenu requires the first context to be a JMenuItem which wants the PluggableMenu attached to as the context, so that it can determine that it would attach to a menu. The second context is an internal (non-localized) description of the menu such as "File" or "View" so that the plugin can further decide.

Specified by:
inContext in interface Pluggable
Parameters:
o - An identification of the context. The interpretation of criteria is specific to the plug-in type, but must be consistent across that type. The plug-in must want to be exposed to all contexts.
Returns:
True if the plug-in wants to make itself available for this context, otherwise false.
See Also:
Pluggable.inContext(Object[])

getCodePath

public static String getCodePath(Object me)
Gets the path of the code base for a model element.

If empty or not existing return null.

Parameters:
me - The model element
Returns:
String representation of "src_path" tagged value.

isModuleEnabled

public boolean isModuleEnabled()
The default for any Generator is to be enabled.

Specified by:
isModuleEnabled in interface ArgoModule
Returns:
that this module is enabled.
See Also:
ArgoModule.isModuleEnabled()


ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook