freemarker.ext.beans
Class ObjectModel

java.lang.Object
  extended by freemarker.ext.beans.ObjectModelBase
      extended by freemarker.ext.beans.ObjectModel
All Implemented Interfaces:
TemplateHashModel, TemplateModel, TemplateObjectModel, TemplateScalarModel, java.io.Serializable
Direct Known Subclasses:
CollectionModel, EnumerationModel, IteratorModel, MapModel

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

public class ObjectModel
extends ObjectModelBase
implements TemplateHashModel

A class that will wrap an arbitrary object into TemplateHashModel interface. It uses Beans Introspector to dynamically discover the properties and methods. Properties will be wrapped into MethodModel and ScalarModel class instances. The models are cached (meaning requesting a model for same object twice will return the same model instance) unless the system property expose.reflection.nocache is set to true.

Version:
$Id: ObjectModel.java 1101 2013-04-01 04:17:32Z run2000 $
Author:
Attila Szegedi, attila@szegedi.org
See Also:
Serialized Form

Field Summary
 
Fields inherited from class freemarker.ext.beans.ObjectModelBase
object
 
Constructor Summary
ObjectModel(java.lang.Object object)
          Deprecated. Creates a new model that wraps the specified object.
 
Method Summary
 TemplateModel get(java.lang.String key)
          Deprecated. Uses Beans introspection to locate a property or method with name matching the key name.
static ObjectModel getInstance(java.lang.Object object)
          Deprecated. Returns a model wrapping the specified object.
 freemarker.ext.beans.ObjectModelBase.ModelType getType()
          Deprecated. Returns the type of this object (which is TYPE_OBJECT)
 
Methods inherited from class freemarker.ext.beans.ObjectModelBase
getAsObject, getAsString, getInstance, isEmpty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface freemarker.template.TemplateModel
isEmpty
 

Constructor Detail

ObjectModel

public ObjectModel(java.lang.Object object)
Deprecated. 
Creates a new model that wraps the specified object. Note that there are specialized subclasses of this class for wrapping arrays, collections, enumeration, iterators, and maps. Note also that the superclass can be used to wrap String objects if only scalar functionality is needed. You can also choose to delegate the choice over which model class is used for wrapping to BeansWrapper.wrap(Object).

Parameters:
object - the object to wrap into a model.
Method Detail

getInstance

public static final ObjectModel getInstance(java.lang.Object object)
Deprecated. 
Returns a model wrapping the specified object. If there is already a cached model instance for this object, 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 there are specialized subclasses of this class for wrapping arrays, collections, enumeration, iterators, and maps. Note also that the superclass can be used to wrap String objects if only scalar functionality is needed. You can also choose to delegate the choice over which model class is used for wrapping to BeansWrapper.wrap(Object).

Parameters:
object - the object to wrap into a model.
Returns:
the model for the object.

getType

public freemarker.ext.beans.ObjectModelBase.ModelType getType()
Deprecated. 
Returns the type of this object (which is TYPE_OBJECT)

Overrides:
getType in class ObjectModelBase

get

public TemplateModel get(java.lang.String key)
                  throws TemplateModelException
Deprecated. 
Uses Beans introspection to locate a property or method with name matching the key name. If a method or property is found, it is wrapped into MethodModel or ScalarModel instance and returned. Models for various properties and methods are cached on a per-class basis, so the costly introspection is performed only once per property or method of a class. (Sidenote: this also implies that any class whose method has been called will be strongly referred to by the framework and will not become unloadable until this class has been unloaded first. Normally this is not an issue, but can be in a rare scenario where you create many classes on the fly. Also, as the cache grows with new classes and methods introduced to the framework, it may appear as if it were leaking memory.) If no method or propery matching the key is found, the framework will try to invoke methods with signature get(java.lang.String), then get(java.lang.Object).

Specified by:
get in interface TemplateHashModel
Parameters:
key - the name by which the TemplateModel is identified in the template.
Returns:
the TemplateModel referred to by the key, or null if not found.
Throws:
TemplateModelException - if there was no property nor method nor a generic get method to invoke.