Home » freemarker-2.3.13 » freemarker.ext.beans » [javadoc | source]
public class: BeanModel [javadoc | source]

All Implemented Interfaces:
    AdapterTemplateModel, WrapperTemplateModel, TemplateHashModelEx

Direct Known Subclasses:
    EnumerationModel, DateModel, ResourceBundleModel, BooleanModel, StringModel, CollectionModel, ArrayModel, MapModel, NumberModel, IteratorModel

A class that will wrap an arbitrary object into freemarker.template.TemplateHashModel interface allowing calls to arbitrary property getters and invocation of accessible methods on the object from a template using the object.foo to access properties and object.bar(arg1, arg2) to invoke methods on it. You can also use the object.foo[index] syntax to access indexed properties. It uses Beans java.beans.Introspector to dynamically discover the properties and methods.
Field Summary
protected final  Object object     
protected final  BeansWrapper wrapper     
static final  ModelFactory FACTORY     
 public BeanModel(Object object,
    BeansWrapper wrapper) 
    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) .
    object - the object to wrap into a model.
    wrapper - the BeansWrapper associated with this model. Every model has to have an associated BeansWrapper instance. The model gains many attributes from its wrapper, including the caching behavior, method exposure level, method-over-item shadowing policy etc.
Method from freemarker.ext.beans.BeanModel Summary:
get,   getAdaptedObject,   getWrappedObject,   hasPlainGetMethod,   invokeGenericGet,   isEmpty,   keySet,   keys,   size,   toString,   unwrap,   values,   wrap
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from freemarker.ext.beans.BeanModel Detail:
 public TemplateModel get(String key) throws TemplateModelException 
    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 freemarker.template.TemplateMethodModelEx (for a method or indexed property), or evaluated on-the-fly and the return value wrapped into appropriate model (for a simple property) 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. (Side-note: 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. The framework does, however detect class reloads (if you happen to be in an environment that does this kind of things--servlet containers do it when they reload a web application) and flushes the cache. If no method or property matching the key is found, the framework will try to invoke methods with signature non-void-return-type get(java.lang.String), then non-void-return-type get(java.lang.Object), or alternatively (if the wrapped object is a resource bundle) Object getObject(java.lang.String).
 public Object getAdaptedObject(Class hint) 
 public Object getWrappedObject() 
 protected boolean hasPlainGetMethod() 
    Whether the model has a plain get(String) or get(Object) method
 protected TemplateModel invokeGenericGet(Map keyMap,
    Class clazz,
    String key) throws InvocationTargetException, TemplateModelException, IllegalAccessException 
 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.
 protected Set keySet() 
    Helper method to support TemplateHashModelEx. Returns the Set of Strings which are available via the TemplateHashModel interface. Subclasses that override invokeGenericGet to provide additional hash keys should also override this method.
 public TemplateCollectionModel keys() 
 public int size() 
 public String toString() 
 protected Object unwrap(TemplateModel model) throws TemplateModelException 
 public TemplateCollectionModel values() throws TemplateModelException 
 protected TemplateModel wrap(Object obj) throws TemplateModelException