com.fullspan.propkeyconst
Class ConstantGenerator

java.lang.Object
  extended bycom.fullspan.propkeyconst.ConstantGenerator

public class ConstantGenerator
extends java.lang.Object

Generates a Java source file with inner classes and constants (static final Strings) representing property keys.

Author:
Mitch Stuart

Field Summary
static java.lang.String INDENT
           
static java.lang.String USAGE
           
 
Constructor Summary
ConstantGenerator(java.lang.String destDirPath, java.lang.String packageName, java.lang.String outerClassName, RootClassDesc rootClassDesc)
          Construct an instance of this class to generate a single .java file with all of the constants in the rootClassDesc.
 
Method Summary
protected  void emit(java.lang.String text, int level)
          Break the text into lines, and emit each line separately, prefixed by the proper indentation.
protected  void emitConstants(ClassDesc classDesc)
           
protected  void emitInnerClasses(ClassDesc classDesc)
           
protected  void emitOuter()
           
 void generate()
          Generate the .java file with the directory, package name, and class name specified in this object's constructor.
static java.lang.String getCommentBlock(ICommentHolder commentHolder)
          If the commentHolder has a non-null comment, returns a JavaDoc comment block with the commentHolder's comment text embedded.
static java.lang.String getIndent(int level)
           
static void main(java.lang.String[] args)
           
static java.lang.String merge(java.lang.String template, java.util.Map paramMap)
          Merges the parameters in the map into the template, using <% and %> as delimiters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USAGE

public static final java.lang.String USAGE
See Also:
Constant Field Values

INDENT

public static final java.lang.String INDENT
See Also:
Constant Field Values
Constructor Detail

ConstantGenerator

public ConstantGenerator(java.lang.String destDirPath,
                         java.lang.String packageName,
                         java.lang.String outerClassName,
                         RootClassDesc rootClassDesc)
Construct an instance of this class to generate a single .java file with all of the constants in the rootClassDesc.

Note that the destDirPath and the packageName should be fully specified. They are not computed or checked against each other. For example, you would typically use values like this:

Parameters:
destDirPath - the filesystem path into which the generated .java file will be placed
packageName - the package name that will be emitted with a package statement at the top of the generated file
outerClassName - the class name for the generated file
rootClassDesc - the root class descriptor, typically the caller will get this from PropertyLoader.getRootClassDesc()
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

getIndent

public static java.lang.String getIndent(int level)
Returns:
a String consisting of the INDENT constant concatentated level number of times.

getCommentBlock

public static java.lang.String getCommentBlock(ICommentHolder commentHolder)
If the commentHolder has a non-null comment, returns a JavaDoc comment block with the commentHolder's comment text embedded. Otherwise returns an empty string.

Parameters:
commentHolder -
Returns:
the comment block

merge

public static java.lang.String merge(java.lang.String template,
                                     java.util.Map paramMap)
Merges the parameters in the map into the template, using <% and %> as delimiters. For example if the paramMap contains a key "foo", then the value in the map pointed to by the key "foo" will be inserted into the template wherever the string <%foo%> is found.

Notice that the map drives the replacement, not the template. Neither of these are considered errors:

Parameters:
template -
paramMap -
Returns:
the template with the parameters merged into it

generate

public void generate()
Generate the .java file with the directory, package name, and class name specified in this object's constructor.


emitOuter

protected void emitOuter()
                  throws java.io.IOException
Throws:
java.io.IOException

emitConstants

protected void emitConstants(ClassDesc classDesc)
                      throws java.io.IOException
Throws:
java.io.IOException

emitInnerClasses

protected void emitInnerClasses(ClassDesc classDesc)
                         throws java.io.IOException
Throws:
java.io.IOException

emit

protected void emit(java.lang.String text,
                    int level)
             throws java.io.IOException
Break the text into lines, and emit each line separately, prefixed by the proper indentation.

Throws:
java.io.IOException