implementations
Class JavaImplementationGenerator

java.lang.Object
  |
  +--implementations.JavaImplementationGenerator
All Implemented Interfaces:
ImplementationGeneratorI
Direct Known Subclasses:
ConcernJImplementationGenerator, JavaInheritance, JavaOverrides, JavaReturns, JavaSingleInstance, JavaSingleRelation

public abstract class JavaImplementationGenerator
extends java.lang.Object
implements ImplementationGeneratorI

Introduces basic funtionality for Java implementation generators.

Version:
0.1.18, 22 November 2003
Author:
Dennis Wagelaar

Constructor Summary
JavaImplementationGenerator()
          Constructs a JavaImplementationGenerator.
 
Method Summary
 void apply(ImplementationGenerator implementation, GenerateImplementationVisitor generateImpl)
          Applies the implementation generator.
protected  java.lang.String createClause(java.lang.String name, java.util.Collection elements)
          Creates a comma-separated clause and returns it.
PRE: elements ::= Collection<Concept>
protected  java.lang.String createMethod(java.lang.String name, java.util.Hashtable parms, java.lang.String returnType, java.lang.String body)
          Creates a Java method body from the given data.
protected  java.util.Collection getClasses(java.util.Collection concepts)
          Retrieves all concepts that can be interpreted as classes from the given list of concepts.
PRE: concepts ::= Collection<Concept>
POST: result ::= Collection<Concept>
protected  Composite getComposite()
          Returns the composite to generate implementation for.
protected  java.util.Collection getConceptsFor(CompositeRole role)
          Retrieves the concepts filling the given role.
POST: result ::= Collection<Concept>
protected  java.lang.String getCurrentImplementation(Concept concept)
          Retrieves current implementation for a concept.
protected  java.lang.String getCurrentImplementation(UniqueRealm realm)
          Retrieves current implementation for a unique realm.
protected  ImplementationGenerator getImplGen()
          Returns the corresponding ImplementationGenerator.
protected  java.lang.String getInstanceName(AbstractConcept concept)
          Returns the name of a concept adapted as instance name.
protected  java.util.Collection getInterfaces(java.util.Collection concepts)
          Retrieves all concepts that can be interpreted as interfaces from the given list of concepts.
PRE: concepts ::= Collection<Concept>
POST: result ::= Collection<Concept>
protected  Model getModel()
          Returns the model.
protected  java.util.Collection getPrimitives(java.util.Collection concepts)
          Retrieves all concepts that can be interpreted as primitives from the given list of concepts.
PRE: concepts ::= Collection<Concept>
POST: result ::= Collection<Concept>
protected  GenerateImplementationVisitor getVisitor()
          Returns the corresponding GenerateImplementationVisitor.
protected  java.lang.String insertImports(java.lang.String impl, java.util.Collection libraries)
          Inserts an import clause into the implementation and returns the updated implementation.
protected  java.lang.String insertInheritance(java.lang.String impl, java.lang.String inheritance)
          Inserts an inheritance clause into the given implementation and returns it.
protected  java.lang.String insertMethod(java.lang.String impl, java.lang.String method)
          Inserts a method into a java implementation and returns it.
protected  java.lang.String insertMethodOverrideID(java.lang.String impl, int id)
          Inserts a method override id into the implementation and returns the updated implementation.
protected  java.lang.String insertParameters(java.lang.String impl, java.util.Hashtable parms)
          Inserts parameters into the method declaration and returns the updated implementation.
protected  java.lang.String insertPrimitiveImplementation(java.lang.String impl, Concept primitive)
          Inserts a primitive's implementation into a java implementation and returns it.
protected  java.lang.String insertPrimitiveImplementations(java.lang.String impl, java.util.Collection primitives)
          Inserts the implementations of the given Primitive concepts in the given implementation.
protected  java.lang.String insertReturnType(java.lang.String impl, java.lang.String type)
          Inserts a return type clause into the implementation and returns the updated implementation.
protected  java.lang.String insertVariables(java.lang.String impl, java.util.Collection variables)
          Inserts variables into the given implementation and returns it.
protected  boolean isClass(java.lang.String form)
          Checks whether the given form can be interpreted as a class.
protected  boolean isInterface(java.lang.String form)
          Checks whether the given form can be interpreted as an interface.
protected  boolean isMethod(java.lang.String form)
          Checks whether the given form can be interpreted as a method.
protected  boolean isPrimitive(java.lang.String form)
          Checks whether the given form can be interpreted as a primitive.
protected  boolean isStatic(java.lang.String form)
          Checks whether the given form is static.
protected  java.lang.String lcfirst(java.lang.String str)
          Changes the first character of the string to lowercase.
protected  void setCurrentImplementation(Concept concept, java.lang.String impl)
          Stores current implementation for a concept.
protected  void setCurrentImplementation(UniqueRealm realm, java.lang.String impl)
          Stores current implementation for a unique realm.
protected  java.lang.String ucfirst(java.lang.String str)
          Changes the first character of the string to uppercase.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaImplementationGenerator

public JavaImplementationGenerator()
Constructs a JavaImplementationGenerator.
Method Detail

getImplGen

protected ImplementationGenerator getImplGen()
Returns the corresponding ImplementationGenerator.
Returns:
The ImplementationGenerator.

getVisitor

protected GenerateImplementationVisitor getVisitor()
Returns the corresponding GenerateImplementationVisitor.
Returns:
The GenerateImplementationVisitor.

getCurrentImplementation

protected java.lang.String getCurrentImplementation(Concept concept)
Retrieves current implementation for a concept.
Parameters:
concept - The concept to get the implementation for.
Returns:
The implementation.

getCurrentImplementation

protected java.lang.String getCurrentImplementation(UniqueRealm realm)
Retrieves current implementation for a unique realm.
Parameters:
realm - The unique realm to get the implementation for.
Returns:
The implementation.

setCurrentImplementation

protected void setCurrentImplementation(Concept concept,
                                        java.lang.String impl)
Stores current implementation for a concept.
Parameters:
concept - The concept to get the implementation for.
impl - The implementation.

setCurrentImplementation

protected void setCurrentImplementation(UniqueRealm realm,
                                        java.lang.String impl)
Stores current implementation for a unique realm.
Parameters:
realm - The unique realm to get the implementation for.
impl - The implementation.

getComposite

protected Composite getComposite()
Returns the composite to generate implementation for.
Returns:
The composite.

getModel

protected Model getModel()
Returns the model.
Returns:
The Model.

getConceptsFor

protected java.util.Collection getConceptsFor(CompositeRole role)
Retrieves the concepts filling the given role.
POST: result ::= Collection<Concept>
Parameters:
role - The composite role that the requested concepts fill.
Returns:
The collection of parent concepts.

lcfirst

protected java.lang.String lcfirst(java.lang.String str)
Changes the first character of the string to lowercase.
Parameters:
str - The string to manipulate.

ucfirst

protected java.lang.String ucfirst(java.lang.String str)
Changes the first character of the string to uppercase.
Parameters:
str - The string to manipulate.

getInstanceName

protected java.lang.String getInstanceName(AbstractConcept concept)
Returns the name of a concept adapted as instance name.
Parameters:
concept - The concept to name.
Returns:
The instance name.

isClass

protected boolean isClass(java.lang.String form)
Checks whether the given form can be interpreted as a class.
Parameters:
form - The concept form.
Returns:
True if form can be interpreted as a class.

isInterface

protected boolean isInterface(java.lang.String form)
Checks whether the given form can be interpreted as an interface.
Parameters:
form - The concept form.
Returns:
True if form can be interpreted as an interface.

isPrimitive

protected boolean isPrimitive(java.lang.String form)
Checks whether the given form can be interpreted as a primitive.
Parameters:
form - The concept form.
Returns:
True if form can be interpreted as a primitive.

isMethod

protected boolean isMethod(java.lang.String form)
Checks whether the given form can be interpreted as a method.
Parameters:
form - The concept form.
Returns:
True if form can be interpreted as a method.

isStatic

protected boolean isStatic(java.lang.String form)
Checks whether the given form is static.
Parameters:
form - The concept form.
Returns:
True if form is static.

getClasses

protected java.util.Collection getClasses(java.util.Collection concepts)
                                   throws CoComposeException
Retrieves all concepts that can be interpreted as classes from the given list of concepts.
PRE: concepts ::= Collection<Concept>
POST: result ::= Collection<Concept>
Parameters:
concepts - The collection of concepts to retrieve from.
Returns:
The collection of class concepts.
Throws:
CoComposeException -  

getInterfaces

protected java.util.Collection getInterfaces(java.util.Collection concepts)
                                      throws CoComposeException
Retrieves all concepts that can be interpreted as interfaces from the given list of concepts.
PRE: concepts ::= Collection<Concept>
POST: result ::= Collection<Concept>
Parameters:
concepts - The collection of concepts to retrieve from.
Returns:
The collection of class concepts.
Throws:
CoComposeException -  

getPrimitives

protected java.util.Collection getPrimitives(java.util.Collection concepts)
                                      throws CoComposeException
Retrieves all concepts that can be interpreted as primitives from the given list of concepts.
PRE: concepts ::= Collection<Concept>
POST: result ::= Collection<Concept>
Parameters:
concepts - The collection of concepts to retrieve from.
Returns:
The collection of class concepts.
Throws:
CoComposeException -  

insertPrimitiveImplementation

protected java.lang.String insertPrimitiveImplementation(java.lang.String impl,
                                                         Concept primitive)
Inserts a primitive's implementation into a java implementation and returns it.
Parameters:
impl - The current implementation.
primitive - The primitive concept.
Returns:
The updated implementation.

insertPrimitiveImplementations

protected java.lang.String insertPrimitiveImplementations(java.lang.String impl,
                                                          java.util.Collection primitives)
                                                   throws CoComposeException
Inserts the implementations of the given Primitive concepts in the given implementation.
Parameters:
impl - The implementation to adapt.
primitives - The Primitive concepts for which to insert the implementation.
Returns:
The adapted implementation.
Throws:
CoComposeException - if precondition not met. PRE: primitives ::= Collection

createClause

protected java.lang.String createClause(java.lang.String name,
                                        java.util.Collection elements)
                                 throws CoComposeException
Creates a comma-separated clause and returns it.
PRE: elements ::= Collection<Concept>
Parameters:
name - The name of the clause, e.g. 'extends'.
elements - The clause elements.
Returns:
The clause string.
Throws:
CoComposeException -  

createMethod

protected java.lang.String createMethod(java.lang.String name,
                                        java.util.Hashtable parms,
                                        java.lang.String returnType,
                                        java.lang.String body)
Creates a Java method body from the given data.
Parameters:
name - The method name.
parms - The method parameters (null = none).
returnType - The method return type (null = void).
body - The method body.
Returns:
The created method implementation.

insertMethod

protected java.lang.String insertMethod(java.lang.String impl,
                                        java.lang.String method)
Inserts a method into a java implementation and returns it.
Parameters:
impl - The current implementation.
method - The method implementation.
Returns:
The updated implementation.

insertInheritance

protected java.lang.String insertInheritance(java.lang.String impl,
                                             java.lang.String inheritance)
                                      throws CoComposeException
Inserts an inheritance clause into the given implementation and returns it.
Parameters:
impl - The current implementation.
inheritance - The inheritance clause.
Returns:
The updated implementation.
Throws:
CoComposeException - if illegal inheritance clause is attempted.

insertVariables

protected java.lang.String insertVariables(java.lang.String impl,
                                           java.util.Collection variables)
Inserts variables into the given implementation and returns it.
Parameters:
impl - The current implementation.
variables - The inheritance clause.
Returns:
The updated implementation.

insertParameters

protected java.lang.String insertParameters(java.lang.String impl,
                                            java.util.Hashtable parms)
Inserts parameters into the method declaration and returns the updated implementation.
Parameters:
impl - The current implementation.
parms - The parameter declarations. Structure: |-> .
Returns:
The updated implementation.

insertImports

protected java.lang.String insertImports(java.lang.String impl,
                                         java.util.Collection libraries)
Inserts an import clause into the implementation and returns the updated implementation.
Parameters:
impl - The current implementation.
libraries - The set of libraries to be imported.
Returns:
The updated implementation.

insertReturnType

protected java.lang.String insertReturnType(java.lang.String impl,
                                            java.lang.String type)
Inserts a return type clause into the implementation and returns the updated implementation.
Parameters:
impl - The current implementation.
type - The return type.
Returns:
The updated implementation.

insertMethodOverrideID

protected java.lang.String insertMethodOverrideID(java.lang.String impl,
                                                  int id)
Inserts a method override id into the implementation and returns the updated implementation.
Parameters:
impl - The current implementation.
id - The overridden method id.
Returns:
The updated implementation.

apply

public void apply(ImplementationGenerator implementation,
                  GenerateImplementationVisitor generateImpl)
           throws CoComposeException
Applies the implementation generator.
Specified by:
apply in interface ImplementationGeneratorI
Parameters:
implementation - The implementation generator to apply.
generateImpl - The language specific code generation operation visitor.
Throws:
CoComposeException - if generating implementation failed.