org.geotools.maven.xmlcodegen
Class AbstractGenerator

java.lang.Object
  extended by org.geotools.maven.xmlcodegen.AbstractGenerator
Direct Known Subclasses:
BindingGenerator, SchemaGenerator, SchemaLocationResolverGenerator

public abstract class AbstractGenerator
extends java.lang.Object

Abstract base class for code generators.

Author:
Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org

Constructor Summary
AbstractGenerator()
           
 
Method Summary
protected  void copy(java.io.File file, java.lang.String baseLocation)
          Copies a file to the output location.
protected  java.lang.String execute(java.lang.String templateName, java.lang.Object input)
          Executes a code generation template.
protected  java.io.File findSchemaFile(java.lang.String path)
          Attempts to locate a schema file by name by iterating through schemaLookupDirectories.
 java.lang.String getPackageBase()
           
protected  boolean included(org.eclipse.xsd.XSDNamedComponent c)
           
protected  java.io.File outputLocation(java.lang.String baseLocation)
          Convenience method for generating the output location of generated files based on #getLocation()
 void setIncluded(java.util.Set included)
           
 void setOverwriting(boolean overwriting)
          Flag controlling the behaviour of the generator when a generated file already exists.
 void setPackageBase(java.lang.String packageBase)
          Sets the base package for generated classes.
 void setResourceLocation(java.lang.String resourceLocation)
          Sets the location to write out generated resource files.
 void setSchemaLookupDirectories(java.io.File[] schemaLookupDirectories)
          Sets the directories to use when attempting to locate a schema via a relative reference.
 void setSchemaSourceDirectory(java.io.File schemaSourceDirectory)
          Sets the single directory to lookup schemas.
 void setSourceLocation(java.lang.String sourceLocation)
          Sets the location to write out generated source files.
 void setTestLocation(java.lang.String testLocation)
          Sets the location to write out generated test files.
protected  void write(java.lang.String result, java.lang.String className, java.lang.String baseLocation)
          Writes out a string to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractGenerator

public AbstractGenerator()
Method Detail

setPackageBase

public void setPackageBase(java.lang.String packageBase)
Sets the base package for generated classes.

Parameters:
packageBase - Dot seperate package name, or null for no package.

getPackageBase

public java.lang.String getPackageBase()

setSourceLocation

public void setSourceLocation(java.lang.String sourceLocation)
Sets the location to write out generated source files.

Parameters:
location - A file path.

setTestLocation

public void setTestLocation(java.lang.String testLocation)
Sets the location to write out generated test files.

Parameters:
testLocation - A file path.

setResourceLocation

public void setResourceLocation(java.lang.String resourceLocation)
Sets the location to write out generated resource files.

Parameters:
resourceLocation - A file path.

setOverwriting

public void setOverwriting(boolean overwriting)
Flag controlling the behaviour of the generator when a generated file already exists.

If set to true, the generator will overwrite existing files. if set to false, the generator will not overwrite the file and issue a warning.

Parameters:
overwriting - overwrite flag.

setSchemaSourceDirectory

public void setSchemaSourceDirectory(java.io.File schemaSourceDirectory)
Sets the single directory to lookup schemas.

Parameters:
schemaSourceDirectory - A directory.

setSchemaLookupDirectories

public void setSchemaLookupDirectories(java.io.File[] schemaLookupDirectories)
Sets the directories to use when attempting to locate a schema via a relative reference.

Parameters:
schemaLookupDirectories - An array of directories.

write

protected void write(java.lang.String result,
                     java.lang.String className,
                     java.lang.String baseLocation)
              throws java.io.IOException
Writes out a string to a file.

THe file written out is located under #location, with the path generated from packageBase appended.

Parameters:
result - Result to write to the files.
className - The name of the file to write out.
Throws:
java.io.IOException

copy

protected void copy(java.io.File file,
                    java.lang.String baseLocation)
             throws java.io.IOException
Copies a file to the output location.

THe file written out is located under #location, with the path generated from packageBase appended.

Parameters:
file - The file to copy.
Throws:
java.io.IOException

findSchemaFile

protected java.io.File findSchemaFile(java.lang.String path)
                               throws java.io.IOException
Attempts to locate a schema file by name by iterating through schemaLookupDirectories.

Parameters:
path - The path of the file.
Throws:
java.io.IOException

outputLocation

protected java.io.File outputLocation(java.lang.String baseLocation)
Convenience method for generating the output location of generated files based on #getLocation()


execute

protected java.lang.String execute(java.lang.String templateName,
                                   java.lang.Object input)
                            throws java.lang.ClassNotFoundException,
                                   java.lang.RuntimeException
Executes a code generation template.

The class of the template is formed by prepending org.geotools.xml.codegen. to name.

Parameters:
templateName - The non-qualified class name of the template.
input - The input to the template.
Returns:
The result of the code generator
Throws:
java.lang.ClassNotFoundException - If the template class could not be found.
java.lang.RuntimeException - If any exceptions ( ex, relection) occur. while attempting to execute the template.

setIncluded

public void setIncluded(java.util.Set included)

included

protected boolean included(org.eclipse.xsd.XSDNamedComponent c)


Copyright © 1996-2010 Geotools. All Rights Reserved.