Class Generator

java.lang.Object
org.glassfish.rmic.iiop.Generator
All Implemented Interfaces:
Constants, Generator, Constants, Constants, RuntimeConstants
Direct Known Subclasses:
IDLGenerator, StubGenerator

public abstract class Generator extends Object implements Generator, Constants
Generator provides a small framework from which IIOP-specific generators can inherit. Common logic is implemented here which uses both abstract methods as well as concrete methods which subclasses may want to override. The following methods must be present in any subclass:
      Default constructor
              CompoundType getTopType(BatchEnvironment env, ClassDefinition cdef);
      int parseArgs(String argv[], int currentIndex);
      boolean requireNewInstance();
              OutputType[] getOutputTypesFor(CompoundType topType,
                                     HashSet alreadyChecked);
              String getFileNameExtensionFor(OutputType outputType);
              void writeOutputFor (   OutputType outputType,
                              HashSet alreadyChecked,
                                                              IndentingWriter writer) throws IOException;
 
  • Field Details

    • alwaysGenerate

      private boolean alwaysGenerate
    • env

      private BatchEnvironment env
    • trace

      private boolean trace
  • Constructor Details

    • Generator

      Generator()
      Default constructor for subclasses to use.
  • Method Details

    • parseArgs

      public boolean parseArgs(String[] argv, Main main)
      Examine and consume command line arguments.
      Specified by:
      parseArgs in interface Generator
      Parameters:
      argv - The command line arguments. Ignore null and unknown arguments. Set each consumed argument to null.
      main - Report any errors using the main.error() methods.
      Returns:
      true if no errors, false otherwise.
    • parseNonConforming

      protected abstract boolean parseNonConforming(ContextStack stack)
      Return true if non-conforming types should be parsed.
      Parameters:
      stack - The context stack.
    • getTopType

      protected abstract CompoundType getTopType(ClassDefinition cdef, ContextStack stack)
      Create and return a top-level type.
      Parameters:
      cdef - The top-level class definition.
      stack - The context stack.
      Returns:
      The compound type or null if is non-conforming.
    • getOutputTypesFor

      protected abstract Generator.OutputType[] getOutputTypesFor(CompoundType topType, HashSet<Type> alreadyChecked)
      Return an array containing all the file names and types that need to be generated for the given top-level type. The file names must NOT have an extension (e.g. ".java").
      Parameters:
      topType - The type returned by getTopType().
      alreadyChecked - A set of Types which have already been checked. Intended to be passed to Type.collectMatching(filter,alreadyChecked).
    • getFileNameExtensionFor

      protected abstract String getFileNameExtensionFor(Generator.OutputType outputType)
      Return the file name extension for the given file name (e.g. ".java"). All files generated with the ".java" extension will be compiled. To change this behavior for ".java" files, override the compileJavaSourceFile method to return false.
      Parameters:
      outputType - One of the items returned by getOutputTypesFor(...)
    • writeOutputFor

      protected abstract void writeOutputFor(Generator.OutputType outputType, HashSet<Type> alreadyChecked, IndentingWriter writer) throws IOException
      Write the output for the given OutputFileName into the output stream.
      Parameters:
      outputType - One of the items returned by getOutputTypesFor(...)
      alreadyChecked - A set of Types which have already been checked. Intended to be passed to Type.collectMatching(filter,alreadyChecked).
      writer - The output stream.
      Throws:
      IOException
    • requireNewInstance

      protected abstract boolean requireNewInstance()
      Return true if a new instance should be created for each class on the command line. Subclasses which return true should override newInstance() to return an appropriately constructed instance.
    • requiresGeneration

      private boolean requiresGeneration(File target, Type theType)
      Return true if the specified file needs generation.
    • newInstance

      private Generator newInstance()
      Create and return a new instance of self. Subclasses which need to do something other than default construction must override this method.
    • generate

      public void generate(BatchEnvironment env, File destDir, ClassDefinition cdef)
      Generate output. Any source files created which need compilation should be added to the compiler environment using the addGeneratedFile(File) method.
      Specified by:
      generate in interface Generator
      Parameters:
      env - The compiler environment
      destDir - The directory for the root of the package hierarchy
      cdef - The definition for the implementation class or interface from which to generate output
    • generateOutputFiles

      private void generateOutputFiles(CompoundType topType, BatchEnvironment env, File destDir)
      Create and return a new instance of self. Subclasses which need to do something other than default construction must override this method.
    • postProcessFile

      protected void postProcessFile(BatchEnvironment env, File file) throws FileNotFoundException
      Throws:
      FileNotFoundException
    • getFileFor

      private File getFileFor(Generator.OutputType outputType, File destinationDir)
      Return the File object that should be used as the output file for the given OutputType.
      Parameters:
      outputType - The type to create a file for.
      destinationDir - The directory to use as the root of the package heirarchy. May be null, in which case the current classpath is searched to find the directory in which to create the output file. If that search fails (most likely because the package directory lives in a zip or jar file rather than the file system), the current user directory is used.
    • getOutputDirectory

      protected abstract File getOutputDirectory(File destinationDir, Identifier id, BatchEnvironment environment)
    • getOutputId

      protected Identifier getOutputId(Generator.OutputType outputType)
      Return an identifier to use for output.
      Parameters:
      outputType - the type for which output is to be generated.
      Returns:
      the new identifier. This implementation returns the input parameter.