|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.webmacro.Context
A Context contains state. The idea is to put all of the data you wish to render into the Context and then merge it with a Template via the Template.write() or Template.evaluate() methods. Actually you can render any Macro object by passing a Context to its write() or evaluat() method, not just templates.
A Context is a per-thread data structure. It should not be shared between threads since it is not thread safe. The idea is to put all of the state for a single request into the context and then execute it, with each request having its own separate context. In this thread-per-request worldview there is no reason to synchronzie the Context objects as they are not shared bewteen threads.
Ordinarily you acquire a Context object from the WebMacro interface, use it for awhile, and then recycle() it. But you can implement your own Context objects and pass it to the evaluate() and write() method of any Template or other Macro.
Inner Class Summary | |
static class |
Context.TemplateEvaluationContext
|
Inner classes inherited from class java.util.Map |
java.util.Map.Entry |
Constructor Summary | |
Context(Broker broker)
Create a new Context relative to the supplied broker |
Method Summary | |
void |
clear()
Clear the context so that it can be used for another request. |
java.lang.Object |
clone()
See cloneContext(). |
Context |
cloneContext()
Create a copy of this context. |
boolean |
containsKey(java.lang.Object key)
Method from Map interface, operates on underlying Map |
boolean |
containsValue(java.lang.Object value)
Method from Map interface, operates on underlying Map |
java.util.Set |
entrySet()
Method from Map interface, operates on underlying Map |
java.lang.Object |
get(java.lang.Object name)
Get the named object/property from the Context; returns null if not found. |
Broker |
getBroker()
Get the instance of the Broker for this request |
java.lang.String |
getCurrentLocation()
|
EvaluationExceptionHandler |
getEvaluationExceptionHandler()
Get the EvaluationExceptionHandler |
Log |
getLog(java.lang.String type)
Get a log instance that can be used to write log messages into the log under the supplied log type. |
Log |
getLog(java.lang.String type,
java.lang.String description)
Get a log instance that can be used to write log messages into the log under the supplied log type. |
java.util.Map |
getMap()
Get the underlying Map object. |
Pool |
getPool()
|
java.lang.Object |
getProperty(java.lang.Object name)
Same as get(name) but can be overridden by subclasses to do something different |
java.lang.Object |
getProperty(java.lang.Object[] names)
Same as get(Object names[]) but can be overridden by subclasses to behave differently |
Context.TemplateEvaluationContext |
getTemplateEvaluationContext()
|
java.lang.Object |
internalGet(java.lang.Object name)
Get the named object/property from the Context. |
java.lang.Object |
internalGet(java.lang.Object[] names)
Get the named object from the Context. |
boolean |
isEmpty()
Method from Map interface, operates on underlying Map |
boolean |
isTiming()
Return true if the Context contains an active profiler, and calls to startTiming/stopTiming will be counted. |
java.util.Set |
keySet()
Method from Map interface, operates on underlying Map |
protected void |
loadTools(java.lang.String keyName)
Load the context tools listed in the supplied string. |
void |
put(java.lang.Object o,
boolean b)
|
void |
put(java.lang.Object o,
byte b)
|
void |
put(java.lang.Object o,
char c)
|
java.lang.Object |
put(java.lang.Object name,
java.lang.Class c)
Convenience method for putting static classes into the context, wraps the class instance in a wrapper |
void |
put(java.lang.Object o,
double d)
|
void |
put(java.lang.Object o,
float f)
|
void |
put(java.lang.Object o,
int i)
|
void |
put(java.lang.Object o,
long l)
|
java.lang.Object |
put(java.lang.Object name,
java.lang.Object value)
Add an object to the context returning the object that was there previously under the same name, if any. |
void |
put(java.lang.Object o,
short s)
|
void |
putAll(java.util.Map t)
Method from Map interface, operates on underlying Map |
void |
recycle()
Return the context to the object pool assigned via setPool(), if any. |
java.lang.Object |
remove(java.lang.Object key)
Method from Map interface, operates on underlying Map |
boolean |
set(java.lang.Object[] names,
java.lang.Object value)
Set the named property in the Context. |
void |
setEvaluationExceptionHandler(EvaluationExceptionHandler eeh)
Set a new EvaluationExceptionHandler |
void |
setMap(java.util.Map m)
Set the underlying Map object. |
void |
setPool(Pool contextPool)
Assign the object pool that this context should return to when its recycle() method is called. |
boolean |
setProperty(java.lang.Object[] names,
java.lang.Object value)
Same as set(Object names[], Object value) but can be overridden by subclasses to behave differently |
boolean |
setProperty(java.lang.Object name,
java.lang.Object value)
Same as put(name,value) but can be overridden by subclasses to do something different |
int |
size()
Method from Map interface, operates on underlying Map |
void |
startTiming(java.lang.String name)
Mark the start of an event for profiling. |
void |
startTiming(java.lang.String name,
boolean arg)
Same as startTiming(name1 + "(" + arg + ")") but the concatenation of strings and the call to toString() occurs only if profiling is enabled. |
void |
startTiming(java.lang.String name,
int arg)
Same as startTiming(name1 + "(" + arg + ")") but the concatenation of strings and the call to toString() occurs only if profiling is enabled. |
void |
startTiming(java.lang.String name1,
java.lang.Object arg)
Same as startTiming(name1 + "(" + arg + ")") but the concatenation of strings and the call to arg.toString() occurs only if profiling is enabled. |
void |
startTiming(java.lang.String name1,
java.lang.Object arg1,
java.lang.Object arg2)
Same as startTiming(name1 + "(" + arg1 + "," + arg2 + ")") but the concatenation of strings and the call to arg.toString() occurs only if profiling * is enabled. |
void |
stopTiming()
Mark the end of an event for profiling. |
java.util.Collection |
values()
Method from Map interface, operates on underlying Map |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Map |
equals, hashCode |
Constructor Detail |
public Context(Broker broker)
Method Detail |
protected final void loadTools(java.lang.String keyName)
public final java.lang.Object clone()
clone
in class java.lang.Object
public Context cloneContext()
public void clear()
Subclasses may override the clear method and add functionality but they must call super.clear() if they do so.
clear
in interface java.util.Map
public final Broker getBroker()
public final Context.TemplateEvaluationContext getTemplateEvaluationContext()
public final java.lang.String getCurrentLocation()
public final Log getLog(java.lang.String type, java.lang.String description)
public final Log getLog(java.lang.String type)
public EvaluationExceptionHandler getEvaluationExceptionHandler()
public void setEvaluationExceptionHandler(EvaluationExceptionHandler eeh)
public final java.lang.Object internalGet(java.lang.Object name) throws PropertyException
public final java.lang.Object get(java.lang.Object name)
get
in interface java.util.Map
public final java.lang.Object put(java.lang.Object name, java.lang.Class c)
public final java.lang.Object put(java.lang.Object name, java.lang.Object value)
put
in interface java.util.Map
public final java.lang.Object internalGet(java.lang.Object[] names) throws PropertyException
public final boolean set(java.lang.Object[] names, java.lang.Object value) throws PropertyException
public java.lang.Object getProperty(java.lang.Object name) throws PropertyException
public boolean setProperty(java.lang.Object name, java.lang.Object value) throws PropertyException
public java.lang.Object getProperty(java.lang.Object[] names) throws PropertyException
public boolean setProperty(java.lang.Object[] names, java.lang.Object value) throws PropertyException
public final void setPool(Pool contextPool)
public final Pool getPool()
public final void recycle()
public final void setMap(java.util.Map m)
public final java.util.Map getMap()
public final boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
public final boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
public final java.util.Set entrySet()
entrySet
in interface java.util.Map
public final boolean isEmpty()
isEmpty
in interface java.util.Map
public final java.util.Set keySet()
keySet
in interface java.util.Map
public final void putAll(java.util.Map t)
putAll
in interface java.util.Map
public final java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
public final int size()
size
in interface java.util.Map
public final java.util.Collection values()
values
in interface java.util.Map
public final boolean isTiming()
public final void startTiming(java.lang.String name)
public final void startTiming(java.lang.String name1, java.lang.Object arg)
public final void startTiming(java.lang.String name1, java.lang.Object arg1, java.lang.Object arg2)
public final void startTiming(java.lang.String name, int arg)
public final void startTiming(java.lang.String name, boolean arg)
public final void stopTiming()
public final void put(java.lang.Object o, int i)
public final void put(java.lang.Object o, byte b)
public final void put(java.lang.Object o, short s)
public final void put(java.lang.Object o, long l)
public final void put(java.lang.Object o, char c)
public final void put(java.lang.Object o, float f)
public final void put(java.lang.Object o, double d)
public final void put(java.lang.Object o, boolean b)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |