ca.krasnay.scaffold
Class Scaffold

java.lang.Object
  extended by ca.krasnay.scaffold.Scaffold

public class Scaffold
extends Object


Constructor Summary
Scaffold(Class<?> entityClass)
           
 
Method Summary
 Class<?> getEntityClass()
          Returns the entity class being scaffolded.
static File getMavenJavaDir(Class<?> clazz)
          Returns the directory of the source file for the given class, assuming this current project is a Maven project.
static File getMavenResourcesDir(Class<?> clazz)
          Returns the resources directory corresponding to the given class, assuming this current project is a Maven project.
 Map<String,Object> getMergeFields()
          Returns map of fields to be merged into the template.
static File getPackageDir(Class<?> clazz)
          Returns the filesystem directory that contains the given class.
 Scaffold render(String templateName, String outFileName)
          Renders the given template to the given output file.
 Scaffold setTargetDir(File targetDir)
          Sets the target directory into which to render templates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scaffold

public Scaffold(Class<?> entityClass)
Method Detail

getPackageDir

public static File getPackageDir(Class<?> clazz)
Returns the filesystem directory that contains the given class. Throws an exception if this cannot be determined (e.g. if the class is in a JAR file).


getMavenJavaDir

public static File getMavenJavaDir(Class<?> clazz)
Returns the directory of the source file for the given class, assuming this current project is a Maven project.


getMavenResourcesDir

public static File getMavenResourcesDir(Class<?> clazz)
Returns the resources directory corresponding to the given class, assuming this current project is a Maven project.


getEntityClass

public Class<?> getEntityClass()
Returns the entity class being scaffolded.


getMergeFields

public Map<String,Object> getMergeFields()
Returns map of fields to be merged into the template. Subclasses may override this to return their own map, but should in general call this base class method and augment and return the default map.


render

public Scaffold render(String templateName,
                       String outFileName)
Renders the given template to the given output file. The template is read from templateDir and the target file is written to targetDir.

Parameters:
templateName - Name of the template, relative to the template directory.
outFileName - Name of the output file, relative to the target directory. This name itself is a template, so you can specify something like "${Entity}Dao.java".

setTargetDir

public Scaffold setTargetDir(File targetDir)
Sets the target directory into which to render templates. By default, templates are rendered into the package directory of the entity class.



Copyright © 2015. All rights reserved.