org.szegedi.expose.model
Class ReflectionObjectModelBase

java.lang.Object
  |
  +--org.szegedi.expose.model.ReflectionObjectModelBase
All Implemented Interfaces:
freemarker.template.TemplateModel, freemarker.template.TemplateScalarModel
Direct Known Subclasses:
ReflectionArrayModel, ReflectionObjectModel, ResourceBundleHashModel

public class ReflectionObjectModelBase
extends java.lang.Object
implements freemarker.template.TemplateScalarModel

Base class for all classes that wrap objects into template models. Instances of this class and descendant classes can be created directly, or utilizing a model cache through getInstance() calls, or polimorphically through the ReflectionUtilities.wrap(Object) method.

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

Field Summary
static int TYPE_ARRAY
          Returned from getType() if the object is a ReflectionArrayModel
static int TYPE_COLLECTION
          Returned from getType() if the object is a ReflectionCollectionModel
static int TYPE_ENUMERATION
          Returned from getType() if the object is a ReflectionEnumerationModel
static int TYPE_ITERATOR
          Returned from getType() if the object is a ReflectionIteratorModel
static int TYPE_MAP
          Returned from getType() if the object is a ReflectionMapModel
static int TYPE_OBJECT
          Returned from getType() if the object is a ReflectionObjectModel
static int TYPE_OBJECT_BASE
          Returned from getType() if the object is a ReflectionObjectModelBase
static int TYPE_RESOURCE_BUNDLE
          Returned from getType() if the object is a ResourceBundleHashModel
 
Method Summary
 java.lang.String getAsString()
          Returns either the toString() of the wrapped object or the string "null", if the wrapped object is null.
static ReflectionObjectModelBase getInstance(java.lang.String object)
          Returns a model wrapping the specified String object.
 java.lang.Object getObject()
          Returns the wrapped object.
 int getType()
          Returns the type of this object (which is TYPE_OBJECT_BASE)
 boolean isEmpty()
          Tells whether the model is empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_OBJECT_BASE

public static final int TYPE_OBJECT_BASE
Returned from getType() if the object is a ReflectionObjectModelBase

TYPE_OBJECT

public static final int TYPE_OBJECT
Returned from getType() if the object is a ReflectionObjectModel

TYPE_ARRAY

public static final int TYPE_ARRAY
Returned from getType() if the object is a ReflectionArrayModel

TYPE_COLLECTION

public static final int TYPE_COLLECTION
Returned from getType() if the object is a ReflectionCollectionModel

TYPE_MAP

public static final int TYPE_MAP
Returned from getType() if the object is a ReflectionMapModel

TYPE_ITERATOR

public static final int TYPE_ITERATOR
Returned from getType() if the object is a ReflectionIteratorModel

TYPE_ENUMERATION

public static final int TYPE_ENUMERATION
Returned from getType() if the object is a ReflectionEnumerationModel

TYPE_RESOURCE_BUNDLE

public static final int TYPE_RESOURCE_BUNDLE
Returned from getType() if the object is a ResourceBundleHashModel
Method Detail

getInstance

public static final ReflectionObjectModelBase getInstance(java.lang.String object)
Returns a model wrapping the specified String object. If there is already a cached model instance for this String, returns the cached model instance. Models are cached using WeakReference objects. The caching can be turned off by setting the expose.reflection.nocache system property to true. In this case calling this method is equivalent to constructing a new model. Note that since the only Freemarker-specific method in this class is getAsString there is no sense in creating an object of this class directly with anything except a String. If you need to wrap an object of another class, use one of specialized subclasses, or delegate the choice to ReflectionUtilities.wrap(Object).
Parameters:
object - the String to wrap into a model.
Returns:
the model for the String

getObject

public java.lang.Object getObject()
Returns the wrapped object.

getType

public int getType()
Returns the type of this object (which is TYPE_OBJECT_BASE)

getAsString

public java.lang.String getAsString()
Returns either the toString() of the wrapped object or the string "null", if the wrapped object is null.
Specified by:
getAsString in interface freemarker.template.TemplateScalarModel

isEmpty

public boolean isEmpty()
Tells whether the model is empty. It is empty if either the wrapped object is null, or it is a Boolean with false value.
Specified by:
isEmpty in interface freemarker.template.TemplateModel