freemarker.ext.beans
final class: StaticModel [javadoc |
source]
java.lang.Object
freemarker.ext.beans.StaticModel
All Implemented Interfaces:
TemplateHashModelEx
Wraps the static fields and methods of a class in a
freemarker.template.TemplateHashModel .
Fields are wrapped using
BeansWrapper#wrap(Object) , and
methods are wrapped into an appropriate
freemarker.template.TemplateMethodModelEx instance.
Unfortunately, there is currently no support for bean property-style
calls of static methods, similar to that in
BeanModel .
- author:
Attila - Szegedi
- version:
$ - Id: StaticModel.java,v 1.24.2.1 2006/11/12 10:23:02 szegedia Exp $
| Method from freemarker.ext.beans.StaticModel Detail: |
public TemplateModel get(String key) throws TemplateModelException {
Object model = map.get(key);
// Simple method, overloaded method or final field -- these have cached
// template models
if (model instanceof TemplateModel)
return (TemplateModel) model;
// Non-final field; this must be evaluated on each call.
if (model instanceof Field)
{
try
{
return wrapper.getOuterIdentity().wrap(((Field) model).get(null));
}
catch (IllegalAccessException e)
{
throw new TemplateModelException(
"Illegal access for field " + key + " of class " + clazz.getName());
}
}
throw new TemplateModelException(
"No such key: " + key + " in class " + clazz.getName());
}
Returns the field or method named by the key
parameter. |
public boolean isEmpty() {
return map.isEmpty();
}
Returns true if there is at least one public static
field or method in the underlying class. |
public TemplateCollectionModel keys() throws TemplateModelException {
return (TemplateCollectionModel)wrapper.getOuterIdentity().wrap(map.keySet());
}
|
public int size() {
return map.size();
}
|
public TemplateCollectionModel values() throws TemplateModelException {
return (TemplateCollectionModel)wrapper.getOuterIdentity().wrap(map.values());
}
|