freemarker.ext.beans2
Class StaticClassWrapper<T>

java.lang.Object
  extended by freemarker.ext.beans2.StaticClassWrapper<T>
All Implemented Interfaces:
TemplateHashModel, TemplateModel, TemplateScalarModel, TemplateWriteableHashModel, java.io.Serializable
Direct Known Subclasses:
StaticEnumWrapper

public class StaticClassWrapper<T>
extends java.lang.Object
implements TemplateHashModel, TemplateWriteableHashModel, TemplateScalarModel, java.io.Serializable

Wrapper for static or uninstantiated classes. Provides access to static fields and methods of a given class.

Since:
1.9
Version:
$Id: StaticClassWrapper.java 1067 2011-06-06 10:55:28Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

Field Summary
protected  java.lang.Class<T> clazz
          The class being wrapped by this wrapper
 
Constructor Summary
StaticClassWrapper()
          Default constructor where a class is not provided initially.
StaticClassWrapper(java.lang.Class<T> clazz)
          Constructor that takes a class to be wrapped.
 
Method Summary
 TemplateModel get(java.lang.String key)
          Gets a TemplateModel from the hash.
 java.lang.String getAsString()
          Returns the class's name as a String.
 boolean isEmpty()
          Is the object empty?
 void put(java.lang.String key, TemplateModel model)
          Sets a value in the hash model.
 void setClazz(java.lang.Class<T> clazz)
          Sets the class to be wrapped by this class wrapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

clazz

protected java.lang.Class<T> clazz
The class being wrapped by this wrapper

Constructor Detail

StaticClassWrapper

public StaticClassWrapper()
Default constructor where a class is not provided initially. This allows the wrapper to be used as a prototype.


StaticClassWrapper

public StaticClassWrapper(java.lang.Class<T> clazz)
Constructor that takes a class to be wrapped.

Parameters:
clazz - the class to be wrapped
Method Detail

setClazz

public void setClazz(java.lang.Class<T> clazz)
Sets the class to be wrapped by this class wrapper.

Parameters:
clazz - the class to be wrapped

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the object empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
true if this object is empty, otherwise false
Throws:
TemplateModelException

get

public TemplateModel get(java.lang.String key)
                  throws TemplateModelException
Gets a TemplateModel from the hash.

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 - there was a problem getting the value for the given key

put

public void put(java.lang.String key,
                TemplateModel model)
         throws TemplateModelException
Sets a value in the hash model.

Specified by:
put in interface TemplateWriteableHashModel
Parameters:
key - the hash key
model - the value to be added to the hash model
Throws:
TemplateModelException - there was a problem setting the value for the given key

getAsString

public java.lang.String getAsString()
                             throws TemplateModelException
Returns the class's name as a String.

Specified by:
getAsString in interface TemplateScalarModel
Returns:
the String representation of this class.
Throws:
TemplateModelException