com.moesol.generator
Class ClassGenerator

java.lang.Object
  extended by com.moesol.generator.ClassGenerator
Direct Known Subclasses:
JavaClassGenerator, JniClassGenerator, JniHeaderClassGenerator, TestClassGenerator

public abstract class ClassGenerator
extends Object

Abstract base class for code generators


Constructor Summary
ClassGenerator(Class clazz, boolean quiet, TranslationContext map)
           
 
Method Summary
static Class ClassForName(String className)
          Helper
 void cni_forward(Writer out)
          Called from class templates
protected  Writer createClassOutput(String output_directory)
          Create an output file suitable for return from createClassOutput.
protected  Template createClassTemplate()
          Create an instance of Template that is configured to callback onto this.
protected abstract  ClassGeneratorVisitor createClassVisitor(Writer out)
          Template method
protected  void extendClassProperties(Properties p)
          Template method
protected  String findClassTemplate(String prefix, String type)
          Finds the translation template using a standard search.
 void generate(String output_directory)
           
protected  String getClassDirectory()
           
protected  String getClassDirectory(Class a_class)
           
protected abstract  String getFileSuffix()
          Template method
protected abstract  String getTemplateName()
          Template method
 TranslationContext getTranslationContext()
           
protected static String getTransProperty(String key)
          Helper
 void merge_import(Writer out)
          Called from class templats
 void merge(Writer out)
          Called from class templats
protected  boolean shouldGenerate()
          Template method, default implementation returns true for public classes and interfaces.
 void visit(Writer out)
          Called from class templates
 void visit(Writer out, String arg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassGenerator

public ClassGenerator(Class clazz,
                      boolean quiet,
                      TranslationContext map)
Method Detail

shouldGenerate

protected boolean shouldGenerate()
Template method, default implementation returns true for public classes and interfaces.

Returns:
true if the generation should happen for this class.

extendClassProperties

protected void extendClassProperties(Properties p)
                              throws ApplyException
Template method

Throws:
ApplyException

getTemplateName

protected abstract String getTemplateName()
                                   throws ApplyException
Template method

Throws:
ApplyException

createClassVisitor

protected abstract ClassGeneratorVisitor createClassVisitor(Writer out)
                                                     throws ApplyException
Template method

Throws:
ApplyException

getFileSuffix

protected abstract String getFileSuffix()
Template method


ClassForName

public static Class ClassForName(String className)
                          throws ApplyException
Helper

Throws:
ApplyException

generate

public void generate(String output_directory)
              throws ApplyException
Throws:
ApplyException

createClassOutput

protected Writer createClassOutput(String output_directory)
                            throws IOException
Create an output file suitable for return from createClassOutput. The output file created will be based on the fully qualified class name replacing each '.' with '/'. For example java.lang.System will create /java.lang.System.

If the output_directory does not exist then this method will throw a java.io.IOException.

Parameters:
output_directory - a string defining which directory to create the output file in.
Throws:
IOException

getClassDirectory

protected String getClassDirectory()
Returns:
the filesystem path for m_class.

getClassDirectory

protected String getClassDirectory(Class a_class)
Returns:
the filesystem path for the a_class parameter.

findClassTemplate

protected String findClassTemplate(String prefix,
                                   String type)
                            throws ApplyException
Finds the translation template using a standard search. The search starts with the prefix plus the full class name, then prefix plus the string "super" plus the full super class name. If neither of the above find a translation, then if the class is an interface search for prefix plus "interface", otherwise just search for prefix by itself.

For example, if the prefix is "java.class" and the class being generated is "com.moebiussolutions.test.Test" that extends from "com.moebiussolutions.test.TestSuper", then the search is:
"java.class.com.moebiussolutions.test.Test",
"java.class.super.com.moebiussolutions.test.TestSuper",
"java.class"

Throws:
ApplyException

createClassTemplate

protected Template createClassTemplate()
                                throws ApplyException
Create an instance of Template that is configured to callback onto this.

Throws:
ApplyException

getTransProperty

protected static String getTransProperty(String key)
                                  throws ApplyException
Helper

Throws:
ApplyException

getTranslationContext

public TranslationContext getTranslationContext()

cni_forward

public void cni_forward(Writer out)
                 throws ApplyException
Called from class templates

Throws:
ApplyException

visit

public void visit(Writer out)
           throws ApplyException
Called from class templates

Throws:
ApplyException

visit

public void visit(Writer out,
                  String arg)
           throws ApplyException
Throws:
ApplyException

merge

public void merge(Writer out)
           throws ApplyException
Called from class templats

Throws:
ApplyException

merge_import

public void merge_import(Writer out)
                  throws ApplyException
Called from class templats

Throws:
ApplyException


Copyright © 2004 Moebius Solutions, Inc. All Rights Reserved.