org.szegedi.expose.model
Class ReflectionScalarModel

java.lang.Object
  |
  +--org.szegedi.expose.model.ReflectionScalarModel
All Implemented Interfaces:
freemarker.template.TemplateModel, freemarker.template.TemplateScalarModel

public final class ReflectionScalarModel
extends java.lang.Object
implements freemarker.template.TemplateScalarModel

A class that will wrap a reflected parameterless method call into a TemplateScalarModel interface. It can be used directly, and is heavily used by ReflectionObjectModel to wrap properties of primitive types.

Version:
1.0
Author:
Attila Szegedi, attila@szegedi.org

Constructor Summary
ReflectionScalarModel(java.lang.Object object, java.lang.reflect.Method getter)
          Creates a new model.
 
Method Summary
 java.lang.Object getAsObject()
          Invokes the wrapped method, returns its return value.
 java.lang.String getAsString()
          Calls the wrapped method, and calls toString() on its return value.
 boolean isEmpty()
          Returns true only if the property value is a null, or a Boolean with false value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionScalarModel

public ReflectionScalarModel(java.lang.Object object,
                             java.lang.reflect.Method getter)
Creates a new model.
Parameters:
object - the object on which the method will be called. Can be null for static methods.
getter - the method that will be called to obtain the value of the model.
Method Detail

getAsString

public java.lang.String getAsString()
                             throws freemarker.template.TemplateModelException
Calls the wrapped method, and calls toString() on its return value.
Specified by:
getAsString in interface freemarker.template.TemplateScalarModel

getAsObject

public java.lang.Object getAsObject()
                             throws freemarker.template.TemplateModelException
Invokes the wrapped method, returns its return value.

isEmpty

public boolean isEmpty()
                throws freemarker.template.TemplateModelException
Returns true only if the property value is a null, or a Boolean with false value. This allows boolean values to be used in if statement without testing for obj == "true".
Specified by:
isEmpty in interface freemarker.template.TemplateModel