xdoclet

Class TemplateSubTask

Implemented Interfaces:
Serializable
Known Direct Subclasses:
XmlSubTask

public class TemplateSubTask
extends SubTask

Generic subtask for processing a user-supplied template. The template is specified in the templateFile configuration parameter. It operates in two modes: per class and single output.
Version:
$Revision: 1.78 $
Author:
Ara Abrahamian (ara_e@email.com)
ant.element
name = "template" parent = "xdoclet.DocletTask" display-name = "Standard Subtask"
ant.attribute
name = "destinationFile" description = "The destination file name. If a {0} is found it's assumed that a per class output generation is needed, so {0} is substituted with class name; otherwise a single file is generated with the specified name." required = "Yes"
name = "extent" description = "You can control the extent in which the type search occurs. Valid values are: concrete-type , superclass and hierarchy ." required = "No. Default is \"hierarchy\""
created
Sep 25, 2001

Nested Class Summary

static class
TemplateSubTask.ExtentTypes
static class
TemplateSubTask.OfType
Applicable only to per class output generation.

Field Summary

Fields inherited from class xdoclet.DocletSupport

currentClassTag, currentFieldTag, currentMethodTag

Constructor Summary

TemplateSubTask()

Method Summary

protected void
addOfType(String ofType)
void
addOfType(TemplateSubTask.OfType ofType)
void
addPackageSubstitution(PackageTagsHandler.PackageSubstitution ps)
Substitutes the package of the generated files.
void
copyAttributesFrom(TemplateSubTask src)
Describe what the method does
protected void
engineFinished()
Describe what the method does
protected void
engineStarted()
Describe what the method does
void
execute()
Describe what the method does
protected void
generateForClass(XClass clazz)
Processed template for clazz and generates output file for clazz.
boolean
getAcceptAbstractClasses()
boolean
getAcceptInterfaces()
String
getDestinationFile()
Gets the DestinationFile attribute of the TemplateSubTask object
TemplateEngine
getEngine()
Gets the Engine attribute of the TemplateSubTask object
String
getExtent()
Gets the Extent attribute of the TemplateSubTask object
protected String
getGeneratedFileName(XClass clazz)
Returns class name for the generated file.
GenerationManager
getGenerationManager()
String
getHavingClassTag()
Gets the HavingClassTag attribute of the TemplateSubTask object
String[]
getOfType()
Gets the OfType attribute of the TemplateSubTask object
ArrayList
getPackageSubstitutions()
Gets the PackageSubstitutions attribute of the TemplateSubTask object
String
getSubTaskClassName()
Gets the SubTaskClassName attribute of the TemplateSubTask object
URL
getTemplateURL()
Gets the TemplateURL attribute of the TemplateSubTask object
void
init(XJavaDoc xJavaDoc)
Describe what the method does
boolean
isPackageSubstitutionInheritanceSupported()
By default supports, but some subtasks may not support because global packageSubstitution is for public interfaces/classes, not good for impl classes.
boolean
isPrefixWithPackageStructure()
Gets the PrefixWithPackageStructure attribute of the TemplateSubTask object
protected static String
javaFile(String className)
Converts the full qualified class name to a valid path with File.separator characters instead of .
protected boolean
matchesGenerationRules(XClass clazz)
Returns true if output not already generated for clazz, and is of the specified type and has the specified class tag; false otherwise.
protected boolean
processInnerClasses()
Subclasses should override this method and return true if they want startProcessPerClass() to process inner classes too.
void
setAcceptAbstractClasses(boolean acceptAbstractClasses)
Indicates whether or not to generate for abstract classes.
void
setAcceptInterfaces(boolean acceptInterfaces)
Indicates whether or not to generate for interfaces.
void
setDestinationFile(String destinationFile)
The destination file name.
void
setEngine(TemplateEngine engine)
Sets the Engine attribute of the TemplateSubTask object
void
setExtent(TemplateSubTask.ExtentTypes extent)
You can control the extent in which the type search occurs.
protected void
setExtentValue(String extent)
Sets the ExtentValue attribute of the TemplateSubTask object
protected void
setGenerationManager(GenerationManager gM)
Sets the GenerationManager attribute of the TemplateSubTask object
void
setHavingClassTag(String havingClassTag)
Sets the HavingClassTag attribute of the TemplateSubTask object
void
setOfType(String ofType)
void
setPackageSubstitutionInheritanceSupported(boolean packageSubstitutionInheritanceSupported)
Indicates whether or not package substitution should be inherited
void
setPackageSubstitutions(ArrayList packageSubstitutions)
Sets the PackageSubstitutions attribute of the TemplateSubTask object
void
setPrefixWithPackageStructure(boolean prefixWithPackageStructure)
Indicates whether or not to prefix with package structure.
void
setSubTaskClassName(String subTaskClassName)
Sets the SubTaskClassName attribute of the TemplateSubTask object
void
setTemplateFile(File templateFile)
Sets the name of the template file to use for generation
void
setTemplateURL(URL templateURL)
This method should be called to set a template file programmatically.
protected void
startEngine(URL templateURL, File outputFile)
Describe what the method does
protected void
startProcess()
Describe what the method does
protected void
startProcessForAll()
protected void
startProcessPerClass()
void
validateOptions()
Called to validate configuration parameters.

Methods inherited from class xdoclet.SubTask

addConfigParam, copyAttributesFrom, execute, getConfigParams, getConfigParamsAsMap, getContext, getDestDir, getMergeDir, getSubTaskName, getXJavaDoc, init, setDestDir, setMergeDir, setSubTaskName, validateOptions

Methods inherited from class xdoclet.DocletSupport

getCurrentClass, getCurrentClassTag, getCurrentConstructor, getCurrentField, getCurrentFieldTag, getCurrentMethod, getCurrentMethodTag, getCurrentPackage, getCurrentTag, isDocletGenerated, popCurrentClass, pushCurrentClass, setCurrentClass, setCurrentClassTag, setCurrentConstructor, setCurrentField, setCurrentFieldTag, setCurrentMethod, setCurrentMethodTag, setCurrentPackage

Constructor Details

TemplateSubTask

public TemplateSubTask()

Method Details

addOfType

protected void addOfType(String ofType)

addOfType

public void addOfType(TemplateSubTask.OfType ofType)

addPackageSubstitution

public void addPackageSubstitution(PackageTagsHandler.PackageSubstitution ps)
Substitutes the package of the generated files.
Parameters:
ps - The feature to be added to the Fileset attribute

copyAttributesFrom

public void copyAttributesFrom(TemplateSubTask src)
Describe what the method does
Overrides:
copyAttributesFrom in interface SubTask
Parameters:
src - Describe what the parameter does

engineFinished

protected void engineFinished()
            throws TemplateException
Describe what the method does
Throws:
TemplateException - Describe the exception

engineStarted

protected void engineStarted()
            throws XDocletException
Describe what the method does
Throws:
XDocletException - Describe the exception

execute

public void execute()
            throws XDocletException
Describe what the method does
Overrides:
execute in interface SubTask
Throws:
XDocletException - Describe the exception

generateForClass

protected void generateForClass(XClass clazz)
            throws XDocletException
Processed template for clazz and generates output file for clazz.
Parameters:
clazz - Description of Parameter
Throws:
XDocletException - Description of Exception

getAcceptAbstractClasses

public boolean getAcceptAbstractClasses()

getAcceptInterfaces

public boolean getAcceptInterfaces()

getDestinationFile

public String getDestinationFile()
Gets the DestinationFile attribute of the TemplateSubTask object
Returns:
The DestinationFile value

getEngine

public TemplateEngine getEngine()
Gets the Engine attribute of the TemplateSubTask object
Returns:
The Engine value

getExtent

public String getExtent()
Gets the Extent attribute of the TemplateSubTask object
Returns:
The Extent value

getGeneratedFileName

protected String getGeneratedFileName(XClass clazz)
            throws XDocletException
Returns class name for the generated file. {0} substituted by class name.
Parameters:
clazz - Description of Parameter
Returns:
The GeneratedClassName value
Throws:
XDocletException - Description of Exception

getGenerationManager

public GenerationManager getGenerationManager()

getHavingClassTag

public String getHavingClassTag()
Gets the HavingClassTag attribute of the TemplateSubTask object
Returns:
The HavingClassTag value

getOfType

public String[] getOfType()
Gets the OfType attribute of the TemplateSubTask object
Returns:
The OfType value

getPackageSubstitutions

public ArrayList getPackageSubstitutions()
Gets the PackageSubstitutions attribute of the TemplateSubTask object
Returns:
The PackageSubstitutions value

getSubTaskClassName

public String getSubTaskClassName()
Gets the SubTaskClassName attribute of the TemplateSubTask object
Returns:
The SubTaskClassName value

getTemplateURL

public URL getTemplateURL()
Gets the TemplateURL attribute of the TemplateSubTask object
Returns:
The TemplateURL value

init

public void init(XJavaDoc xJavaDoc)
            throws XDocletException
Describe what the method does
Overrides:
init in interface SubTask
Parameters:
xJavaDoc -
Throws:
XDocletException - Describe the exception

isPackageSubstitutionInheritanceSupported

public boolean isPackageSubstitutionInheritanceSupported()
By default supports, but some subtasks may not support because global packageSubstitution is for public interfaces/classes, not good for impl classes.
Returns:
true

isPrefixWithPackageStructure

public boolean isPrefixWithPackageStructure()
Gets the PrefixWithPackageStructure attribute of the TemplateSubTask object
Returns:
The PrefixWithPackageStructure value

javaFile

protected static String javaFile(String className)
Converts the full qualified class name to a valid path with File.separator characters instead of . characters and class name postfixed by a ".java".
Parameters:
className - Description of Parameter
Returns:
Description of the Returned Value

matchesGenerationRules

protected boolean matchesGenerationRules(XClass clazz)
            throws XDocletException
Returns true if output not already generated for clazz, and is of the specified type and has the specified class tag; false otherwise. If returned false, no output file is generated for clazz.
Parameters:
clazz - Description of Parameter
Returns:
Description of the Returned Value
Throws:
XDocletException - Description of Exception

processInnerClasses

protected boolean processInnerClasses()
Subclasses should override this method and return true if they want startProcessPerClass() to process inner classes too.
Returns:

setAcceptAbstractClasses

public void setAcceptAbstractClasses(boolean acceptAbstractClasses)
Indicates whether or not to generate for abstract classes.
Parameters:
acceptAbstractClasses -
ant.not-required
"No, default is 'true'"

setAcceptInterfaces

public void setAcceptInterfaces(boolean acceptInterfaces)
Indicates whether or not to generate for interfaces.
Parameters:
acceptInterfaces -
ant.not-required
"No, default is 'true'"

setDestinationFile

public void setDestinationFile(String destinationFile)
The destination file name. If a {0} is found it's assumed that a per class output generation is needed, so {0} is substituted with class name; otherwise a single file is generated with the specified name.
Parameters:
destinationFile - The new DestinationFile value
ant.not-required
No,defaultis determinedbythis task.

setEngine

public void setEngine(TemplateEngine engine)
Sets the Engine attribute of the TemplateSubTask object
Parameters:
engine - The new Engine value
ant.element

setExtent

public void setExtent(TemplateSubTask.ExtentTypes extent)
You can control the extent in which the type search occurs. Valid values are:
  • "concrete-type": the class is itself one of the classes listed in ofType attribute.
  • "superclass": the class is itself one of the classes listed in ofType attribute or its superclass is one of the listed ones
  • "hierarchy" which is the default: anywhere in its hierarchy it derives from one of the listed classes.
There's no distinction between a class and an interface.
Parameters:
extent - The new Extent value
ant.element

setExtentValue

protected void setExtentValue(String extent)
Sets the ExtentValue attribute of the TemplateSubTask object
Parameters:
extent - The new ExtentValue value

setGenerationManager

protected void setGenerationManager(GenerationManager gM)
Sets the GenerationManager attribute of the TemplateSubTask object
Parameters:
gM - The new GenerationManager value

setHavingClassTag

public void setHavingClassTag(String havingClassTag)
Sets the HavingClassTag attribute of the TemplateSubTask object
Parameters:
havingClassTag - The new HavingClassTag value

setOfType

public void setOfType(String ofType)

setPackageSubstitutionInheritanceSupported

public void setPackageSubstitutionInheritanceSupported(boolean packageSubstitutionInheritanceSupported)
Indicates whether or not package substitution should be inherited
Parameters:
packageSubstitutionInheritanceSupported - The new PackageSubstitutionInheritanceSupported value
ant.not-required
"No, default is 'true'"

setPackageSubstitutions

public void setPackageSubstitutions(ArrayList packageSubstitutions)
Sets the PackageSubstitutions attribute of the TemplateSubTask object
Parameters:
packageSubstitutions - The new PackageSubstitutions value

setPrefixWithPackageStructure

public void setPrefixWithPackageStructure(boolean prefixWithPackageStructure)
Indicates whether or not to prefix with package structure.
Parameters:
prefixWithPackageStructure - The new PrefixWithPackageStructure value
ant.not-required
"No, default is 'true'"

setSubTaskClassName

public void setSubTaskClassName(String subTaskClassName)
Sets the SubTaskClassName attribute of the TemplateSubTask object
Parameters:
subTaskClassName - The new SubTaskClassName value
ant.element

setTemplateFile

public void setTemplateFile(File templateFile)
            throws XDocletException
Sets the name of the template file to use for generation
Parameters:
templateFile - the file name (real file!) of the template
ant.not-required
No,defaultis determinedbythis task.

setTemplateURL

public void setTemplateURL(URL templateURL)
This method should be called to set a template file programmatically. The URL is typically obtained with a getClass().getResource( templateName )
Parameters:
templateURL -
ant.element

startEngine

protected final void startEngine(URL templateURL,
                                 File outputFile)
            throws TemplateException
Describe what the method does
Parameters:
templateURL - Describe what the parameter does
outputFile - Describe what the parameter does
Throws:
TemplateException - Describe the exception

startProcess

protected void startProcess()
            throws XDocletException
Describe what the method does
Throws:
XDocletException - Describe the exception

startProcessForAll

protected void startProcessForAll()
            throws XDocletException

startProcessPerClass

protected void startProcessPerClass()
            throws XDocletException

validateOptions

public void validateOptions()
            throws XDocletException
Called to validate configuration parameters.
Overrides:
validateOptions in interface SubTask
Throws:
XDocletException - Description of Exception