|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object freemarker.template.RootModelWrapper
public class RootModelWrapper
Wraps a template hash model with a template model root. The hash model
can be accessed transparently from the root of this model. Any local
variables are stored within a HashMap
. Anything that
doesn't exist within the HashMap
is automatically forwarded
to the wrapped hash model. Local variables are counted as being any
variables added using the put()
method.
Use this class when your template model (the hash model) is shared across several template calls, possibly multithreaded, and you want to be sure that the model isn't inadvertently changed between calls.
To do this for multithreaded calls, create a separate
RootModelWrapper
object for each template call, passing in the
data model you want to be left unchanged. Then, call your templates with
each RootModelWrapper
object as your root data model.
To do this for synchronous calls, it is sufficient to create one
RootModelWrapper
object, passing in the data model you want
to be left unchanged. Then, call your templates with the
RootModelWrapper
object as your root data model, and call the
reset()
method between each template call.
This class was previously in the freemarker.ext.misc
package.
LocalModelWrapper
,
Serialized FormField Summary | |
---|---|
protected TemplateHashModel |
hashModel
The underlying template hash being wrapped. |
protected java.util.Map<java.lang.String,TemplateModel> |
rootModel
The map containing temporary values for the root model. |
Constructor Summary | |
---|---|
RootModelWrapper(TemplateHashModel innerModel)
Create a new RootModelWrapper with the given
hash model as the model to be wrapped. |
|
RootModelWrapper(TemplateHashModel innerModel,
java.util.Map<java.lang.String,TemplateModel> modelMap)
Create a new RootModelWrapper with the given
hash model as the model to be wrapped. |
Method Summary | |
---|---|
TemplateModel |
get(java.lang.String key)
Retrieve a template model for the given key, if one exists. |
boolean |
isEmpty()
Returns whether we have a completely empty model. |
void |
put(java.lang.String key,
TemplateModel model)
Put the given template model into local storage with the given key. |
void |
remove(java.lang.String key)
Remove the named model from local storage. |
void |
reset()
Clear all the local variables from the local storage, and just provide pass-through access to the wrapped hash model. |
java.lang.String |
toString()
Returns a string representation of the object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.Map<java.lang.String,TemplateModel> rootModel
protected TemplateHashModel hashModel
Constructor Detail |
---|
public RootModelWrapper(TemplateHashModel innerModel)
RootModelWrapper
with the given
hash model as the model to be wrapped.
innerModel
- the hash model to be wrappedpublic RootModelWrapper(TemplateHashModel innerModel, java.util.Map<java.lang.String,TemplateModel> modelMap)
RootModelWrapper
with the given
hash model as the model to be wrapped.
innerModel
- the hash model to be wrappedmodelMap
- the map containing the outer modelMethod Detail |
---|
public TemplateModel get(java.lang.String key) throws TemplateModelException
get
in interface TemplateHashModel
key
- the name of the value to be returned
null
TemplateModelException
- there was a problem with the underlying
hash modelpublic boolean isEmpty() throws TemplateModelException
false
. Otherwise, forward
the call to the wrapped hash model.
isEmpty
in interface TemplateModel
true
if the model is empty, otherwise false
TemplateModelException
- there was a problem with underlying
hash modelpublic void put(java.lang.String key, TemplateModel model)
put
in interface TemplateModelRoot
put
in interface TemplateWriteableHashModel
key
- the name of the model to be storedmodel
- the model being stored locallypublic void remove(java.lang.String key)
Remove the named model from local storage.
Note that we don't attempt to block access to the hash model when we remove a key. This is because the only time a "remove" call is performed is when the template engine is sure that there was no underlying data for that key to begin with.
remove
in interface TemplateModelRoot
key
- the name of the model to be removedpublic void reset()
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |