public class ClassGenerator extends Object
getModel(String, ClassLoader),
getDefaultClassloader(),
...to have your own ClassGenerator.
The default implementation of this basic generator expects a java bean (class package) and creates a java file.
Howto start (example): mainClass: de.tsl2.nano.util.codegen.ClassGenerator arguments:
bin/codegen/beanclass.vm| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_DEST_POSTFIX |
static String |
DEFAULT_DEST_PREFIX |
static String |
DEST_FILENAME_PATTERN |
static String |
DEST_POSTFIX |
static String |
DEST_PREFIX |
protected static Log |
LOG |
static String |
POSTFIX_CLS |
static String |
SRC_NAME |
| Modifier | Constructor and Description |
|---|---|
protected |
ClassGenerator() |
| Modifier and Type | Method and Description |
|---|---|
void |
generate(String modelFile,
String templateFile,
Properties properties) |
void |
generate(String modelFile,
String templateFile,
String destFile,
Properties properties,
ClassLoader classLoader)
generates a java class file through the information of the 'modelFile' and the template 'templateFile'.
|
protected ClassLoader |
getDefaultClassloader()
override this method to use your classloader
|
protected String |
getDefaultDestinationFile(String modelFile)
override this method to provide a default destination file
|
protected String |
getDestinationClassName(String sourceFile,
String destinationFileName)
tries to extract the destination class name. precondition is, that package-path starts equal on model and
destination!
|
protected String |
getDestinationPackageName(String sourceFile,
String destinationFileName)
extracts the package name from the result of
getDestinationClassName(String, String). |
protected Object |
getModel(String modelFile,
ClassLoader classLoader)
override this method to provide your class model (the source class)
|
protected GeneratorUtility |
getUtilityInstance()
override this method to use your special utility
|
protected void |
init()
initializes the velocity engine.
|
static ClassGenerator |
instance()
instance
|
protected static ClassGenerator |
instance(ClassGenerator newInstance)
returns a singelton instance of type ClassGenerator. if the singelton is null, the argument will be used as
singelton.
|
protected static ClassGenerator |
instance(String className) |
static void |
main(String[] args) |
protected static final Log LOG
public static final String SRC_NAME
public static final String DEST_PREFIX
public static final String DEST_POSTFIX
public static final String DEST_FILENAME_PATTERN
public static final String DEFAULT_DEST_PREFIX
public static final String DEFAULT_DEST_POSTFIX
public static final String POSTFIX_CLS
public static final ClassGenerator instance()
protected static final ClassGenerator instance(ClassGenerator newInstance)
newInstance - singelton instance, if singelton instance is null.protected static final ClassGenerator instance(String className)
className - generator class nameprotected void init()
public void generate(String modelFile, String templateFile, Properties properties) throws Exception
Exceptiongenerate(String, String, String, Properties, ClassLoader)public void generate(String modelFile, String templateFile, String destFile, Properties properties, ClassLoader classLoader) throws Exception
modelFile - the source file (getModel(String, ClassLoader))templateFile - a velocity template (full path, not classpath!)destFile - the destination fileclassLoader - used in (getModel(String, ClassLoader))Exceptionprotected GeneratorUtility getUtilityInstance()
protected Object getModel(String modelFile, ClassLoader classLoader)
modelFile - source file name (normally a beans java file name)classLoader - classloader to be used to load modelFile class.protected String getDefaultDestinationFile(String modelFile)
modelFile - source filegetModel(String, ClassLoader)protected String getDestinationClassName(String sourceFile, String destinationFileName)
sourceFile - source class namedestinationFileName - dest file nameprotected String getDestinationPackageName(String sourceFile, String destinationFileName)
getDestinationClassName(String, String).sourceFile - source class namedestinationFileName - dest file namegetDestinationClassName(String, String)protected ClassLoader getDefaultClassloader()
Copyright © 2012–2018. All rights reserved.