freemarker.ext.beans
Class ScalarModel

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

Deprecated. this class is deprecated in favour of the classes in the freemarker.ext.beans2 package

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 1101 2013-04-01 04:17:32Z run2000 $
Author:
Attila Szegedi, attila@szegedi.org

Constructor Summary
ScalarModel(java.lang.Object object, java.lang.reflect.Method getter)
          Deprecated. Creates a new model.
 
Method Summary
 java.lang.Object getAsObject()
          Deprecated. Invokes the wrapped method, returns its return value.
 java.lang.String getAsString()
          Deprecated. Calls the wrapped method, and calls toString() on its return value.
 boolean isEmpty()
          Deprecated. 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)
Deprecated. 
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
Deprecated. 
Calls the wrapped method, and calls toString() on its return value.

Specified by:
getAsString in interface TemplateScalarModel
Returns:
the String value of this scalar.
Throws:
TemplateModelException

getAsObject

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

Specified by:
getAsObject in interface TemplateObjectModel
Returns:
the underlying object for this template model
Throws:
TemplateModelException - the object could not be returned

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Deprecated. 
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
Returns:
true if this object is empty, otherwise false
Throws:
TemplateModelException