freemarker.ext.beans
Class ScalarModel

java.lang.Object
  |
  +--freemarker.ext.beans.ScalarModel
All Implemented Interfaces:
TemplateModel, TemplateObjectModel, TemplateScalarModel
Direct Known Subclasses:
NumberModel

public class ScalarModel
extends java.lang.Object
implements TemplateScalarModel, TemplateObjectModel

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

Version:
$Id: ScalarModel.java,v 1.4 2003/10/20 13:49:02 run2000 Exp $
Author:
Attila Szegedi, attila@szegedi.org

Constructor Summary
ScalarModel(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

ScalarModel

public ScalarModel(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 TemplateModelException
Calls the wrapped method, and calls toString() on its return value.
Specified by:
getAsString in interface TemplateScalarModel
Following copied from interface: freemarker.template.TemplateScalarModel
Returns:
the String value of this scalar.

getAsObject

public java.lang.Object getAsObject()
                             throws TemplateModelException
Invokes the wrapped method, returns its return value.
Specified by:
getAsObject in interface TemplateObjectModel
Following copied from interface: freemarker.template.TemplateObjectModel
Returns:
the underlying object for this template model
Throws:
TemplateModelException - the object could not be returned

isEmpty

public boolean isEmpty()
                throws 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 statements without testing for obj == "true" in the template.
Specified by:
isEmpty in interface TemplateModel
Following copied from interface: freemarker.template.TemplateModel
Returns:
true if this object is empty, otherwise false