org.exolab.castor.builder
Class SingleClassGenerator

java.lang.Object
  extended by org.exolab.castor.builder.SingleClassGenerator

public final class SingleClassGenerator
extends java.lang.Object

Writes a single class (and any associated inner classes) to a file.

Version:
$Revision: 0000 $ $Date: $
Author:
Keith Visco - Main author., Arnaud Blandin - Contributions., Nathan Green - Contributions., Edward Kuns - Separated from SourceGenerator

Constructor Summary
SingleClassGenerator(ConsoleDialog dialog, SourceGenerator sourceGenerator, java.lang.String conflictStrategyType)
          Creates an instance of this class.
 
Method Summary
 SourceGenerator getSourceGenerator()
          Returns the SourceGenerator instance that created this class.
(package private)  boolean process(JClass[] classes, SGStateInfo state)
          Processes the given JClasses, one by one, stopping if the SourceGenerator state indicates STOP after processing one class.
(package private)  boolean process(JClass jClass, SGStateInfo state)
          Processes the given JClass by checking for class name conflicts, and if there are none, making the class as processed and then printing the class and, if appropriate, its class descriptors.
(package private)  boolean processIfNotAlreadyProcessed(java.util.Enumeration classKeys, SGStateInfo state)
          Processes the JClass mapped by the provided key unless the JClass has already been processed.
 void setDescriptorCreation(boolean createDescriptors)
          Sets whether or not to create ClassDescriptors for the generated classes.
 void setDestDir(java.lang.String destDir)
          Sets the destination directory.
 void setLineSeparator(java.lang.String lineSeparator)
          Sets the line separator to use when printing the source code.
 void setNameConflictStrategy(java.lang.String nameConflictStrategy)
          Sets the desired ClassNameCRStrategy instance type to be used for name conflict resolution.
 void setPromptForOverwrite(boolean promptForOverwrite)
          Sets whether or not to prompt when we would otherwise overwrite an existing JClass.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleClassGenerator

public SingleClassGenerator(ConsoleDialog dialog,
                            SourceGenerator sourceGenerator,
                            java.lang.String conflictStrategyType)
Creates an instance of this class.

Parameters:
dialog - A ConsoleDialog instance
sourceGenerator - A SourceGenerator instance
conflictStrategyType - Type of the ClassNameCRStrategy instance to be used.
Method Detail

setDestDir

public void setDestDir(java.lang.String destDir)
Sets the destination directory.

Parameters:
destDir - the destination directory.

setLineSeparator

public void setLineSeparator(java.lang.String lineSeparator)
Sets the line separator to use when printing the source code.

Parameters:
lineSeparator - the line separator to use when printing the source code. This method is useful if you are generating source on one platform, but will be compiling the source on a different platform. Note:This can be any string, so be careful. I recommend either using the default or using one of the following:
 windows systems use: "\r\n"
 unix systems use: "\n"
 mac systems use: "\r"
 

setDescriptorCreation

public void setDescriptorCreation(boolean createDescriptors)
Sets whether or not to create ClassDescriptors for the generated classes. By default, descriptors are generated.

Parameters:
createDescriptors - a boolean, when true indicates to generated ClassDescriptors

setPromptForOverwrite

public void setPromptForOverwrite(boolean promptForOverwrite)
Sets whether or not to prompt when we would otherwise overwrite an existing JClass. If set to false, then it is always OK to overwrite an existing class. If set to true, the user will be prompted.

Parameters:
promptForOverwrite - the new value

processIfNotAlreadyProcessed

boolean processIfNotAlreadyProcessed(java.util.Enumeration classKeys,
                                     SGStateInfo state)
                               throws java.io.IOException
Processes the JClass mapped by the provided key unless the JClass has already been processed.

Parameters:
state - SourceGenerator state
classKeys - Enumeration over a collection of keys to ClassInfos
Returns:
true if processing is allowed to continue, false if the SourceGenerator state is STOP_STATUS,
Throws:
java.io.IOException - If an already existing '.castor.cdr' file can not be loaded or found

process

boolean process(JClass[] classes,
                SGStateInfo state)
          throws java.io.IOException
Processes the given JClasses, one by one, stopping if the SourceGenerator state indicates STOP after processing one class.

Parameters:
classes - Array of classes to process
state - SourceGenerator state
Returns:
true if processing is allowed to continue, false if the SourceGenerator state is STOP_STATUS,
Throws:
java.io.IOException - If an already existing '.castor.cdr' file can not be loaded or found

process

boolean process(JClass jClass,
                SGStateInfo state)
          throws java.io.IOException
Processes the given JClass by checking for class name conflicts, and if there are none, making the class as processed and then printing the class and, if appropriate, its class descriptors.

If there is a class name conflict, at best the user stops the source generation and at worst the user continues, skipping this class.

Parameters:
jClass - the class to process
state - SourceGenerator state
Returns:
true if processing is allowed to continue, false if the SourceGenerator state is STOP_STATUS,
Throws:
java.io.IOException - If an already existing '.castor.cdr' file can not be loaded or found

setNameConflictStrategy

public void setNameConflictStrategy(java.lang.String nameConflictStrategy)
Sets the desired ClassNameCRStrategy instance type to be used for name conflict resolution.

Parameters:
nameConflictStrategy - the desired ClassNameCRStrategy instance type

getSourceGenerator

public SourceGenerator getSourceGenerator()
Returns the SourceGenerator instance that created this class.

Returns:
the SourceGenerator instance that created this class.


Intalio Inc. (C) 1999-2007. All rights reserved http://www.intalio.com