org.sandev.generator
Class FileGeneratorBase

java.lang.Object
  extended byorg.sandev.generator.GeneratorCommon
      extended byorg.sandev.generator.FileGeneratorBase
All Implemented Interfaces:
org.sandev.sandbuild.SandGenerator
Direct Known Subclasses:
InstanceGeneratorBase, PackageHTMLGenerator

public class FileGeneratorBase
extends GeneratorCommon
implements org.sandev.sandbuild.SandGenerator

Optional base class for generators which operate only on files, without side effects or merge requirements. With a file generator, cleanup consists only of deleting the source which was previously generated. If your generator has side-effects (like analyzing/altering a generated database table), or requires merge (like version compatibility testing of an XML schema), then you need to handle your own top level generate/cleanup methods.

However if your generator handles cleanup simply by deleting the files it previously wrote, then it can extend this base to use the simplified interface provided here. Essentially this provides the infrastructure to iterate through the declarations, calling delete for any deleted declarations or on cleanup, and calling generate if either the decl or the generator was changed.

This class is set up for generators which are tied to single struct or node declarations. Use AggregateGeneratorBase for file-based generators that work across many declarations to write a single file.


Field Summary
 
Fields inherited from class org.sandev.generator.GeneratorCommon
CONTEXT_CONFIGURATION, CONTEXT_CONTROL, CONTEXT_FRAMEWORK, CONTEXT_MESSAGING, CONTEXT_PERSISTENCE, CONTEXT_UI, DEFAULT_LINE_LENGTH, MESSAGE_INTERFACES
 
Constructor Summary
FileGeneratorBase()
           
 
Method Summary
 void cleanup(org.sandev.sandbuild.SandDecl[] decls, java.io.File baseDir, boolean changed, java.lang.String extra)
          Nuke the source files we generated.
 void delete(org.sandev.sandbuild.SandDecl decl, java.io.File baseDir, java.lang.String extra)
          Delete what you wrote, calling trackFileDelete for each file deleted.
 void generate(org.sandev.sandbuild.SandDecl[] decls, java.io.File baseDir, boolean changed, java.util.Collection dirtyFiles, java.lang.String extra)
          Write the NodeBase source files if the declaration changed.
 void trackFileWrite(java.lang.String filespec)
          Track the fact that we are writing the specified file.
 void write(org.sandev.sandbuild.SandDecl decl, java.io.File baseDir, java.lang.String extra)
          Write your source code, calling trackFileWrite for each file written.
 
Methods inherited from class org.sandev.generator.GeneratorCommon
capitalize, copyfile, deletefile, filterHTMLLine, getDeclaredFields, getFields, getInheritanceHierarchy, getLastAppProject, getLastUtilDir, getLongInstanceName, getPrintStream, getSandProject, getShortInstanceName, getUtilPackage, getVisibleFields, isBasic, isLongReferenceArray, isMessageInterface, isParentAbstract, isPrimitive, isRootStruct, isVowel, log, nextToken, pluralize, rangeEscape, removePlatformDecls, trackFileDelete, uncapitalize, writeDefaultCtor, writeDescription, writeHTMLContents, writeMessageImports, writeSectionName, writeStandardCommentID, writeXHTMLFooter, writeXHTMLFooter, writeXHTMLHeader, writeXHTMLHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileGeneratorBase

public FileGeneratorBase()
Method Detail

generate

public void generate(org.sandev.sandbuild.SandDecl[] decls,
                     java.io.File baseDir,
                     boolean changed,
                     java.util.Collection dirtyFiles,
                     java.lang.String extra)
              throws org.sandev.sandbuild.SandGeneratorException
Write the NodeBase source files if the declaration changed.

Specified by:
generate in interface org.sandev.sandbuild.SandGenerator
Throws:
org.sandev.sandbuild.SandGeneratorException

cleanup

public void cleanup(org.sandev.sandbuild.SandDecl[] decls,
                    java.io.File baseDir,
                    boolean changed,
                    java.lang.String extra)
             throws org.sandev.sandbuild.SandGeneratorException
Nuke the source files we generated.

Specified by:
cleanup in interface org.sandev.sandbuild.SandGenerator
Throws:
org.sandev.sandbuild.SandGeneratorException

trackFileWrite

public void trackFileWrite(java.lang.String filespec)
Track the fact that we are writing the specified file.

Overrides:
trackFileWrite in class GeneratorCommon

write

public void write(org.sandev.sandbuild.SandDecl decl,
                  java.io.File baseDir,
                  java.lang.String extra)
           throws org.sandev.sandbuild.SandGeneratorException
Write your source code, calling trackFileWrite for each file written.

Throws:
org.sandev.sandbuild.SandGeneratorException

delete

public void delete(org.sandev.sandbuild.SandDecl decl,
                   java.io.File baseDir,
                   java.lang.String extra)
            throws org.sandev.sandbuild.SandGeneratorException
Delete what you wrote, calling trackFileDelete for each file deleted.

Throws:
org.sandev.sandbuild.SandGeneratorException