com.ashridgetech.jamda.transform
Class UmlTypeCreator

java.lang.Object
  |
  +--com.ashridgetech.jamda.transform.UmlTypeCreator
All Implemented Interfaces:
ElementTransformer
Direct Known Subclasses:
UmlClassCreator, UmlInterfaceCreator

public abstract class UmlTypeCreator
extends java.lang.Object
implements ElementTransformer

Base class for classes which create a StructuredType from a given source StructuredType. Each instance may only be used to generate one element. Subclasses may wish to override getNewName() or getPackage().

Author:
Paul Boocock version 1.0

Nested Class Summary
 class UmlTypeCreator.PropertyDetails
          Holds references to the ModelElement objects for the field, getter and setter generated for a property.
 
Constructor Summary
UmlTypeCreator()
          Construct a UmlTypeCreator for a Java class or interface.
 
Method Summary
protected  Operation addOperation(java.lang.String name)
          Make a new Operation belonging to the new type, with a void return type.
protected  Operation addOperation(java.lang.String name, StandardTypeDef returnTypeDef)
          Make a new Operation belonging to the new type.
protected  Operation addOperation(java.lang.String name, Type returnType)
          Make a new Operation belonging to the new type.
protected  UmlTypeCreator.PropertyDetails addProperty(Property property)
          Make a new single or pair of Operations belonging to the new type, which are getter and setter (if writable) for a property.
protected  void checkReadyToCreate()
          Check that this UmlTypeCreator has the minimum settings needed to create a new element.
protected abstract  java.util.Set extraStandardDefClasses()
          Get the extra Classes which contain definitions of the standard elements needed for this class to operate on the model, in the form of StandardElementDef constants.
 Model getModel()
          Get the Model in which the new ClassType is being created.
 java.lang.String getNewName()
          Get the name of the class being created.
 StructuredType getNewType()
          Get the new StructuredType being created.
 ModelPackage getPackage()
          Get the ModelPackage of the class being generated.
 java.lang.String getPackageName()
          Get the name of the package of the class being generated.
 StructuredType getSource()
          Get the source StructuredType from which this UmlTypeCreator is generating an element.
 java.lang.String getSuffix()
          Get the suffix for the new class name.
 void logChange(java.lang.String description)
          Log a change made to the Model so that the generation process can be traced.
 void logCreate(ModelElement newElement)
          Log the creation of a new element so that the generation process can be traced.
protected  org.apache.log4j.Logger logger()
           
protected abstract  StructuredType makeNewType()
          Make a new StructuredType element.
 void setModel(Model model)
          Get the Model in which the new ClassType is being created.
 void setPackageName(java.lang.String name)
          Set the name of the package to which the class being created belongs.
 void setSource(StructuredType source)
          Construct a UmlTypeCreator for a Java class of interface.
 void setSuffix(java.lang.String suffix)
          Set the suffix for the new class name.
protected abstract  void setup()
          Set up the characteristics and features of the new element.
 java.util.Set standardElementDefClasses()
          Get the Classes which contain definitions of the standard elements needed for this class to operate on the model, in the form of StandardElementDef constants.
 java.lang.String toString()
           
 void transform(ModelElement element)
          Add the generated element to the output Model (which is set to be the same one as the source element belongs to).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UmlTypeCreator

public UmlTypeCreator()
Construct a UmlTypeCreator for a Java class or interface.

Method Detail

getSource

public StructuredType getSource()
Get the source StructuredType from which this UmlTypeCreator is generating an element.

Returns:
the source element

setSource

public void setSource(StructuredType source)
Construct a UmlTypeCreator for a Java class of interface.


getNewType

public StructuredType getNewType()
Get the new StructuredType being created. Only valid after transform(com.ashridgetech.jamda.uml.ModelElement) has called makeNewType().

Returns:
the new element

getModel

public Model getModel()
Get the Model in which the new ClassType is being created. Only valid after transform(com.ashridgetech.jamda.uml.ModelElement) or a client has set the model using setModel(com.ashridgetech.jamda.uml.Model).

Returns:
the new element

setModel

public void setModel(Model model)
Get the Model in which the new ClassType is being created. Only valid after transform(com.ashridgetech.jamda.uml.ModelElement) or a client has set the model using setModel(com.ashridgetech.jamda.uml.Model).

Returns:
the new element

transform

public void transform(ModelElement element)
Add the generated element to the output Model (which is set to be the same one as the source element belongs to). This method may only be called once. Calls setup().

Specified by:
transform in interface ElementTransformer
Parameters:
element - the ModelElement on which to operate
Throws:
java.lang.IllegalStateException - if this method has already been called

standardElementDefClasses

public java.util.Set standardElementDefClasses()
Get the Classes which contain definitions of the standard elements needed for this class to operate on the model, in the form of StandardElementDef constants. An example of such a class is UmlTypes.

Returns:
a Set of Class objects

checkReadyToCreate

protected void checkReadyToCreate()
Check that this UmlTypeCreator has the minimum settings needed to create a new element.

Throws:
java.lang.IllegalStateException - if the instance is not ready

extraStandardDefClasses

protected abstract java.util.Set extraStandardDefClasses()
Get the extra Classes which contain definitions of the standard elements needed for this class to operate on the model, in the form of StandardElementDef constants. An example of such a class is UmlTypes. This set does not need to include UmlTypes, UmlStereotypes or UmlTags, as these will be added by standardElementDefClasses()

Returns:
a Set of Class objects - may be empty

setup

protected abstract void setup()
Set up the characteristics and features of the new element.


makeNewType

protected abstract StructuredType makeNewType()
Make a new StructuredType element.

Returns:
the new element.

addOperation

protected Operation addOperation(java.lang.String name,
                                 Type returnType)
Make a new Operation belonging to the new type. The new Operation is returned so further characteristics can be set.

Parameters:
name - the name of this Operation
Returns:
the new Operation

addOperation

protected Operation addOperation(java.lang.String name,
                                 StandardTypeDef returnTypeDef)
Make a new Operation belonging to the new type. The new Operation is returned so further characteristics can be set.

Parameters:
name - the name of this Operation
Returns:
the new Operation

addOperation

protected Operation addOperation(java.lang.String name)
Make a new Operation belonging to the new type, with a void return type. The new Operation is returned so further characteristics can be set.

Parameters:
name - the name of this Operation
Returns:
the new Operation

addProperty

protected UmlTypeCreator.PropertyDetails addProperty(Property property)
Make a new single or pair of Operations belonging to the new type, which are getter and setter (if writable) for a property. The new Operations are returned in a UmlTypeCreator.PropertyDetails so further characteristics can be set if required.

Parameters:
property - the Property from which the features are created
Returns:
the new property details - will only ever have a UmlTypeCreator.PropertyDetails.getter and UmlTypeCreator.PropertyDetails.setter, with a null UmlTypeCreator.PropertyDetails.attribute

getNewName

public java.lang.String getNewName()
Get the name of the class being created. This implementation returns the name of the source element (from getSource()), concatenated with the suffix from getSuffix().

Returns:
the class name

getSuffix

public java.lang.String getSuffix()
Get the suffix for the new class name.

Returns:
the name suffix
See Also:
getNewName()

setSuffix

public void setSuffix(java.lang.String suffix)
Set the suffix for the new class name.


getPackageName

public java.lang.String getPackageName()
Get the name of the package of the class being generated.

Returns:
the package name

setPackageName

public void setPackageName(java.lang.String name)
Set the name of the package to which the class being created belongs.

Parameters:
name - the package name - may not be null

getPackage

public ModelPackage getPackage()
Get the ModelPackage of the class being generated. If this does not exist in the Model passed to transform(com.ashridgetech.jamda.uml.ModelElement), it is added, with any parent packages necessary. Note: this method cannot be called until the Model has been set by transform(com.ashridgetech.jamda.uml.ModelElement).

Returns:
the package

logger

protected org.apache.log4j.Logger logger()

logChange

public void logChange(java.lang.String description)
Log a change made to the Model so that the generation process can be traced.

Parameters:
description - a description of the change

logCreate

public void logCreate(ModelElement newElement)
Log the creation of a new element so that the generation process can be traced.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2003 Ashridge Technologies Ltd. All Rights Reserved.