net.sf.jelly.apt.freemarker
Class FreemarkerTransform<S extends TemplateStrategyControl>

java.lang.Object
  extended by net.sf.jelly.apt.freemarker.FreemarkerTransform<S>
All Implemented Interfaces:
freemarker.template.TemplateModel, freemarker.template.TemplateTransformModel
Direct Known Subclasses:
AnnotationValueTransform, FileTransform, ForAllConstructorsTransform, ForAllFieldsTransform, ForAllImportedTypesTransform, ForAllMethodsTransform, ForAllNestedTypesTransform, ForAllPackagesTransform, ForAllParametersTransform, ForAllPropertiesTransform, ForAllThrownTypesTransform, ForAllTypesTransform, IfHasAnnotationTransform, IfHasDeclarationTransform, JavaSourceTransform, PrimitiveWrapperTransform, UnwrapIfPrimitiveTransform, WrapIfPrimitiveTransform

public abstract class FreemarkerTransform<S extends TemplateStrategyControl>
extends java.lang.Object
implements freemarker.template.TemplateTransformModel

Base class for freemarker transforms.

Author:
Ryan Heaton

Field Summary
 
Fields inherited from interface freemarker.template.TemplateModel
NOTHING
 
Constructor Summary
protected FreemarkerTransform(java.lang.String namespace)
          Construct a new transform under the specified namespace.
 
Method Summary
protected  java.lang.Object convertString(java.lang.String value, java.lang.Class toClass)
          Attempts to convert a string value to a given class using the "valueOf" method or "fromString" method.
protected  java.lang.reflect.Method findSetter(java.lang.String property, S strategy)
          Finds the setter for the given property on the specified strategy.
 java.lang.String getTransformName()
          The name of the transform.
 java.lang.String getTransformNamespace()
          The namespace of the transform.
 java.io.Writer getWriter(java.io.Writer out, java.util.Map args)
           
abstract  S newStrategy()
          Instantiate a new strategy instance.
protected  void setupStrategy(S strategy, java.util.Map args)
          Setup the strategy given the specified arguments to the template transform.
protected  java.lang.Object unwrap(freemarker.template.TemplateModel value, java.lang.String property)
          Unwrap the specified value of the given property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FreemarkerTransform

protected FreemarkerTransform(java.lang.String namespace)
Construct a new transform under the specified namespace. null or "" means the root namespace.

Parameters:
namespace - The namespace.
Method Detail

getWriter

public java.io.Writer getWriter(java.io.Writer out,
                                java.util.Map args)
                         throws freemarker.template.TemplateModelException,
                                java.io.IOException
Specified by:
getWriter in interface freemarker.template.TemplateTransformModel
Throws:
freemarker.template.TemplateModelException
java.io.IOException

setupStrategy

protected void setupStrategy(S strategy,
                             java.util.Map args)
                      throws freemarker.template.TemplateModelException
Setup the strategy given the specified arguments to the template transform.

Parameters:
strategy - The strategy to set up.
args - The arguments to the transform.
Throws:
freemarker.template.TemplateModelException

convertString

protected java.lang.Object convertString(java.lang.String value,
                                         java.lang.Class toClass)
Attempts to convert a string value to a given class using the "valueOf" method or "fromString" method.

Parameters:
value - The value to convert.
toClass - The class to convert to.

unwrap

protected java.lang.Object unwrap(freemarker.template.TemplateModel value,
                                  java.lang.String property)
                           throws freemarker.template.TemplateModelException
Unwrap the specified value of the given property.

Parameters:
value - The value to unwrap.
property - The property.
Returns:
The unwrapped object.
Throws:
freemarker.template.TemplateModelException

findSetter

protected java.lang.reflect.Method findSetter(java.lang.String property,
                                              S strategy)
                                       throws freemarker.template.TemplateModelException
Finds the setter for the given property on the specified strategy.

Parameters:
property - The property.
strategy - The strategy.
Returns:
The setter, or null if not found.
Throws:
freemarker.template.TemplateModelException

newStrategy

public abstract S newStrategy()
Instantiate a new strategy instance.

Returns:
The strategy.

getTransformName

public java.lang.String getTransformName()
The name of the transform. Default implementation uses the name of the class.

Returns:
The name of the transform.

getTransformNamespace

public java.lang.String getTransformNamespace()
The namespace of the transform. null or "" means the root namespace.

Returns:
The namespace of the transform.