freemarker.ext.beans2
Class ResourceBundleWrapper

java.lang.Object
  extended by freemarker.ext.beans2.ResourceBundleWrapper
All Implemented Interfaces:
ObjectWrapper, TemplateHashModel, TemplateModel, TemplateObjectModel, java.io.Serializable, java.lang.Cloneable

public class ResourceBundleWrapper
extends java.lang.Object
implements ObjectWrapper, TemplateHashModel, TemplateObjectModel, java.io.Serializable

Wrapper for ResourceBundle objects. Provides a simple hash model for accessing objects within a given bundle.

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

Constructor Summary
ResourceBundleWrapper()
          Default constructor where an object is not provided initially.
ResourceBundleWrapper(java.util.ResourceBundle object)
          Constructor that takes a ResourceBundle object to be wrapped.
 
Method Summary
 java.lang.Object clone()
          Creates and returns a copy of this object.
 TemplateModel get(java.lang.String key)
          Gets a value from the resource bundle.
 java.lang.Object getAsObject()
          Return the underlying object to the reflection mechanism in the freemarker.ext.beans package.
 boolean isEmpty()
          Is the resource bundle empty or null?
 void setObject(java.lang.Object object)
          Sets the object to be wrapped by this object wrapper.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceBundleWrapper

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


ResourceBundleWrapper

public ResourceBundleWrapper(java.util.ResourceBundle object)
Constructor that takes a ResourceBundle object to be wrapped.

Parameters:
object - the resource bundle object to be wrapped
Method Detail

setObject

public void setObject(java.lang.Object object)
Description copied from interface: ObjectWrapper
Sets the object to be wrapped by this object wrapper.

Specified by:
setObject in interface ObjectWrapper
Parameters:
object - the object to be wrapped

getAsObject

public java.lang.Object getAsObject()
                             throws TemplateModelException
Return the underlying object to the reflection mechanism in the freemarker.ext.beans package. Any variables, methods or properties can be called directly via reflection.

Specified by:
getAsObject in interface TemplateObjectModel
Returns:
the underlying object for this template model
Throws:
TemplateModelException - the object could not be returned

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the resource bundle empty or null?

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 value from the resource bundle.

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

clone

public java.lang.Object clone()
Creates and returns a copy of this object.

Specified by:
clone in interface ObjectWrapper
Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.
Throws:
java.lang.RuntimeException - the clone operation was not successful
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable