Package ognl
Class OgnlContext
- java.lang.Object
-
- ognl.OgnlContext
-
- All Implemented Interfaces:
java.util.Map<java.lang.String,java.lang.Object>
public class OgnlContext extends java.lang.Object implements java.util.Map<java.lang.String,java.lang.Object>This class defines the execution context for an OGNL expression
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.Class<?>>accessorStackprivate ClassResolverclassResolverprivate EvaluationcurrentEvaluationprivate NodecurrentNodeprivate java.lang.ObjectcurrentObjectprivate static booleanDEFAULT_IGNORE_READ_METHODSprivate static booleanDEFAULT_KEEP_LAST_EVALUATIONprivate static booleanDEFAULT_TRACE_EVALUATIONSprivate static java.lang.StringIGNORE_READ_METHODS_CONTEXT_KEYprivate booleanignoreReadMethodsprivate java.util.Map<java.lang.String,java.lang.Object>internalContextprivate static java.lang.StringKEEP_LAST_EVALUATION_CONTEXT_KEYprivate booleankeepLastEvaluationprivate static java.lang.StringLAST_EVALUATION_CONTEXT_KEYprivate EvaluationlastEvaluationprivate intlocalReferenceCounterprivate java.util.Map<java.lang.String,LocalReference>localReferenceMapprivate MemberAccessmemberAccessprivate static java.lang.StringPROPERTY_KEY_PREFIXprivate static java.util.Map<java.lang.String,java.lang.Object>RESERVED_KEYSprivate java.lang.Objectrootprivate static java.lang.StringROOT_CONTEXT_KEYprivate EvaluationrootEvaluationprivate static java.lang.StringTHIS_CONTEXT_KEYprivate static java.lang.StringTRACE_EVALUATIONS_CONTEXT_KEYprivate booleantraceEvaluationsprivate TypeConvertertypeConverterprivate java.util.List<java.lang.Class<?>>typeStack
-
Constructor Summary
Constructors Constructor Description OgnlContext(ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess)Constructs a new OgnlContext with the given class resolver, type converter and member access.OgnlContext(MemberAccess memberAccess, ClassResolver classResolver, TypeConverter typeConverter, OgnlContext initialContext)Constructs a new OgnlContext with the given member access, class resolver, type converter and values.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddLocalReference(java.lang.String key, LocalReference reference)voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>>entrySet()booleanequals(java.lang.Object other)java.lang.Objectget(java.lang.Object key)ClassResolvergetClassResolver()java.lang.Class<?>getCurrentAccessor()EvaluationgetCurrentEvaluation()Gets the current Evaluation from the top of the stack.NodegetCurrentNode()java.lang.ObjectgetCurrentObject()java.lang.Class<?>getCurrentType()Gets the current class type being evaluated on the stack, as set bysetCurrentType(Class).EvaluationgetEvaluation(int relativeIndex)Returns the Evaluation at the relative index given.java.lang.Class<?>getFirstAccessor()java.lang.Class<?>getFirstType()booleangetKeepLastEvaluation()Deprecated.since OGNL 3.4.0, useisKeepLastEvaluation()EvaluationgetLastEvaluation()java.util.Map<java.lang.String,LocalReference>getLocalReferences()MemberAccessgetMemberAccess()java.lang.Class<?>getPreviousAccessor()java.lang.Class<?>getPreviousType()Represents the last known object type on the evaluation stack, will be the value of the last knowngetCurrentType().java.lang.ObjectgetRoot()EvaluationgetRootEvaluation()Gets the root of the evaluation stack.booleangetTraceEvaluations()Deprecated.since OGNL 3.4.0, useisTraceEvaluations()TypeConvertergetTypeConverter()java.util.Map<java.lang.String,java.lang.Object>getValues()Get the values Map for this OgnlContext.inthashCode()intincrementLocalReferenceCounter()booleanisEmpty()booleanisIgnoreReadMethods()Returns true if read methods of properties are ignored when accessing properties.booleanisKeepLastEvaluation()Returns true if the last evaluation that was done on this context is retained and available throughgetLastEvaluation().booleanisTraceEvaluations()java.util.Set<java.lang.String>keySet()EvaluationpopEvaluation()Pops the current Evaluation off of the top of the stack.voidpushEvaluation(Evaluation value)Pushes a new Evaluation onto the stack.java.lang.Objectput(java.lang.String key, java.lang.Object value)voidputAll(java.util.Map<? extends java.lang.String,?> t)java.lang.Objectremove(java.lang.Object key)voidsetCurrentAccessor(java.lang.Class<?> type)voidsetCurrentEvaluation(Evaluation value)voidsetCurrentNode(Node value)voidsetCurrentObject(java.lang.Object value)voidsetCurrentType(java.lang.Class<?> type)voidsetIgnoreReadMethods(boolean value)Sets read methods of properties are ignored when accessing properties.voidsetKeepLastEvaluation(boolean value)Sets whether the last evaluation that was done on this context is retained and available throughgetLastEvaluation().voidsetLastEvaluation(Evaluation value)voidsetPreviousType(java.lang.Class<?> type)voidsetRoot(java.lang.Object value)voidsetRootEvaluation(Evaluation value)voidsetTraceEvaluations(boolean value)voidsetValues(java.util.Map<java.lang.String,java.lang.Object> values)Set (put) the provided value map content into the existing values Map for this OgnlContext.intsize()java.util.Collection<java.lang.Object>values()OgnlContextwithValues(java.util.Map<java.lang.String,java.lang.Object> values)Similar tosetValues(Map)but returns the current instance ofOgnlContext
-
-
-
Field Detail
-
ROOT_CONTEXT_KEY
private static final java.lang.String ROOT_CONTEXT_KEY
- See Also:
- Constant Field Values
-
THIS_CONTEXT_KEY
private static final java.lang.String THIS_CONTEXT_KEY
- See Also:
- Constant Field Values
-
TRACE_EVALUATIONS_CONTEXT_KEY
private static final java.lang.String TRACE_EVALUATIONS_CONTEXT_KEY
- See Also:
- Constant Field Values
-
LAST_EVALUATION_CONTEXT_KEY
private static final java.lang.String LAST_EVALUATION_CONTEXT_KEY
- See Also:
- Constant Field Values
-
KEEP_LAST_EVALUATION_CONTEXT_KEY
private static final java.lang.String KEEP_LAST_EVALUATION_CONTEXT_KEY
- See Also:
- Constant Field Values
-
IGNORE_READ_METHODS_CONTEXT_KEY
private static final java.lang.String IGNORE_READ_METHODS_CONTEXT_KEY
- See Also:
- Constant Field Values
-
PROPERTY_KEY_PREFIX
private static final java.lang.String PROPERTY_KEY_PREFIX
- See Also:
- Constant Field Values
-
DEFAULT_IGNORE_READ_METHODS
private static final boolean DEFAULT_IGNORE_READ_METHODS
- See Also:
- Constant Field Values
-
DEFAULT_TRACE_EVALUATIONS
private static boolean DEFAULT_TRACE_EVALUATIONS
-
DEFAULT_KEEP_LAST_EVALUATION
private static boolean DEFAULT_KEEP_LAST_EVALUATION
-
RESERVED_KEYS
private static final java.util.Map<java.lang.String,java.lang.Object> RESERVED_KEYS
-
root
private java.lang.Object root
-
currentObject
private java.lang.Object currentObject
-
currentNode
private Node currentNode
-
traceEvaluations
private boolean traceEvaluations
-
rootEvaluation
private Evaluation rootEvaluation
-
currentEvaluation
private Evaluation currentEvaluation
-
lastEvaluation
private Evaluation lastEvaluation
-
keepLastEvaluation
private boolean keepLastEvaluation
-
ignoreReadMethods
private boolean ignoreReadMethods
-
internalContext
private final java.util.Map<java.lang.String,java.lang.Object> internalContext
-
classResolver
private final ClassResolver classResolver
-
typeConverter
private final TypeConverter typeConverter
-
memberAccess
private final MemberAccess memberAccess
-
typeStack
private final java.util.List<java.lang.Class<?>> typeStack
-
accessorStack
private final java.util.List<java.lang.Class<?>> accessorStack
-
localReferenceCounter
private int localReferenceCounter
-
localReferenceMap
private java.util.Map<java.lang.String,LocalReference> localReferenceMap
-
-
Constructor Detail
-
OgnlContext
public OgnlContext(ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess)
Constructs a new OgnlContext with the given class resolver, type converter and member access. If any of these parameters is null the default will be used, except memberAccess which must be non-null.- Parameters:
classResolver- the ClassResolver for a new OgnlContext.typeConverter- the TypeConverter for a new OgnlContext.memberAccess- the MemberAccess for a new OgnlContext. Must be non-null.
-
OgnlContext
public OgnlContext(MemberAccess memberAccess, ClassResolver classResolver, TypeConverter typeConverter, OgnlContext initialContext)
Constructs a new OgnlContext with the given member access, class resolver, type converter and values. If any of these parameters is null the default will be used, except memberAccess which must be non-null.- Parameters:
memberAccess- the MemberAccess for a new OgnlContext. Must be non-null.classResolver- the ClassResolver for a new OgnlContext.typeConverter- the TypeConverter for a new OgnlContext.initialContext- the initial context of values to provide for a new OgnlContext.
-
-
Method Detail
-
setValues
public void setValues(java.util.Map<java.lang.String,java.lang.Object> values)
Set (put) the provided value map content into the existing values Map for this OgnlContext.- Parameters:
values- a Map of additional values to put into this OgnlContext.
-
withValues
public OgnlContext withValues(java.util.Map<java.lang.String,java.lang.Object> values)
Similar tosetValues(Map)but returns the current instance ofOgnlContext- Parameters:
values- a Map of values- Returns:
- the current instance of
OgnlContext
-
getValues
public java.util.Map<java.lang.String,java.lang.Object> getValues()
Get the values Map for this OgnlContext.- Returns:
- Map of values for this OgnlContext.
-
getClassResolver
public ClassResolver getClassResolver()
-
getTypeConverter
public TypeConverter getTypeConverter()
-
getMemberAccess
public MemberAccess getMemberAccess()
-
setRoot
public void setRoot(java.lang.Object value)
-
getRoot
public java.lang.Object getRoot()
-
getTraceEvaluations
@Deprecated public boolean getTraceEvaluations()
Deprecated.since OGNL 3.4.0, useisTraceEvaluations()
-
isTraceEvaluations
public boolean isTraceEvaluations()
-
setTraceEvaluations
public void setTraceEvaluations(boolean value)
-
getLastEvaluation
public Evaluation getLastEvaluation()
-
setLastEvaluation
public void setLastEvaluation(Evaluation value)
-
getKeepLastEvaluation
@Deprecated public boolean getKeepLastEvaluation()
Deprecated.since OGNL 3.4.0, useisKeepLastEvaluation()
-
isKeepLastEvaluation
public boolean isKeepLastEvaluation()
Returns true if the last evaluation that was done on this context is retained and available throughgetLastEvaluation(). The default is true.- Returns:
- true if the last evaluation for this context is retained and available through
getLastEvaluation(), false otherwise.
-
setKeepLastEvaluation
public void setKeepLastEvaluation(boolean value)
Sets whether the last evaluation that was done on this context is retained and available throughgetLastEvaluation(). The default is true.- Parameters:
value- true if the last evaluation for this context should be retained and available throughgetLastEvaluation(), false otherwise.
-
isIgnoreReadMethods
public boolean isIgnoreReadMethods()
Returns true if read methods of properties are ignored when accessing properties. The default is false.- Returns:
- true if read methods of properties are ignored when accessing properties, false otherwise.
-
setIgnoreReadMethods
public void setIgnoreReadMethods(boolean value)
Sets read methods of properties are ignored when accessing properties. The default is false.- Parameters:
value- true if read methods of properties are ignored when accessing properties, false otherwise.
-
setCurrentObject
public void setCurrentObject(java.lang.Object value)
-
getCurrentObject
public java.lang.Object getCurrentObject()
-
setCurrentAccessor
public void setCurrentAccessor(java.lang.Class<?> type)
-
getCurrentAccessor
public java.lang.Class<?> getCurrentAccessor()
-
getPreviousAccessor
public java.lang.Class<?> getPreviousAccessor()
-
getFirstAccessor
public java.lang.Class<?> getFirstAccessor()
-
getCurrentType
public java.lang.Class<?> getCurrentType()
Gets the current class type being evaluated on the stack, as set bysetCurrentType(Class).- Returns:
- The current object type, may be null.
-
setCurrentType
public void setCurrentType(java.lang.Class<?> type)
-
getPreviousType
public java.lang.Class<?> getPreviousType()
Represents the last known object type on the evaluation stack, will be the value of the last knowngetCurrentType().- Returns:
- The previous type of object on the stack, may be null.
-
setPreviousType
public void setPreviousType(java.lang.Class<?> type)
-
getFirstType
public java.lang.Class<?> getFirstType()
-
setCurrentNode
public void setCurrentNode(Node value)
-
getCurrentNode
public Node getCurrentNode()
-
getCurrentEvaluation
public Evaluation getCurrentEvaluation()
Gets the current Evaluation from the top of the stack. This is the Evaluation that is in process of evaluating.- Returns:
- the current Evaluation from the top of the stack (being evaluated).
-
setCurrentEvaluation
public void setCurrentEvaluation(Evaluation value)
-
getRootEvaluation
public Evaluation getRootEvaluation()
Gets the root of the evaluation stack. This Evaluation contains the node representing the root expression and the source is the root source object.- Returns:
- the root Evaluation from the stack (the root expression node).
-
setRootEvaluation
public void setRootEvaluation(Evaluation value)
-
getEvaluation
public Evaluation getEvaluation(int relativeIndex)
Returns the Evaluation at the relative index given. This should be zero or a negative number as a relative reference back up the evaluation stack. Therefore getEvaluation(0) returns the current Evaluation.- Parameters:
relativeIndex- the relative index for the Evaluation to retrieve from the stack (with 0 being the current Evaluation). relativeIndex should be <= 0.- Returns:
- the Evaluation at relativeIndex, or null if relativeIndex is > 0.
-
pushEvaluation
public void pushEvaluation(Evaluation value)
Pushes a new Evaluation onto the stack. This is done before a node evaluates. When evaluation is complete it should be popped from the stack viapopEvaluation().- Parameters:
value- the Evaluation to push onto the stack.
-
popEvaluation
public Evaluation popEvaluation()
Pops the current Evaluation off of the top of the stack. This is done after a node has completed its evaluation.- Returns:
- the Evaluation popped from the top of the stack.
-
incrementLocalReferenceCounter
public int incrementLocalReferenceCounter()
-
addLocalReference
public void addLocalReference(java.lang.String key, LocalReference reference)
-
getLocalReferences
public java.util.Map<java.lang.String,LocalReference> getLocalReferences()
-
size
public int size()
- Specified by:
sizein interfacejava.util.Map<java.lang.String,java.lang.Object>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Map<java.lang.String,java.lang.Object>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKeyin interfacejava.util.Map<java.lang.String,java.lang.Object>
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValuein interfacejava.util.Map<java.lang.String,java.lang.Object>
-
get
public java.lang.Object get(java.lang.Object key)
- Specified by:
getin interfacejava.util.Map<java.lang.String,java.lang.Object>
-
put
public java.lang.Object put(java.lang.String key, java.lang.Object value)- Specified by:
putin interfacejava.util.Map<java.lang.String,java.lang.Object>
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map<java.lang.String,java.lang.Object>
-
putAll
public void putAll(java.util.Map<? extends java.lang.String,?> t)
- Specified by:
putAllin interfacejava.util.Map<java.lang.String,java.lang.Object>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Map<java.lang.String,java.lang.Object>
-
keySet
public java.util.Set<java.lang.String> keySet()
- Specified by:
keySetin interfacejava.util.Map<java.lang.String,java.lang.Object>
-
values
public java.util.Collection<java.lang.Object> values()
- Specified by:
valuesin interfacejava.util.Map<java.lang.String,java.lang.Object>
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
- Specified by:
entrySetin interfacejava.util.Map<java.lang.String,java.lang.Object>
-
equals
public boolean equals(java.lang.Object other)
- Specified by:
equalsin interfacejava.util.Map<java.lang.String,java.lang.Object>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Map<java.lang.String,java.lang.Object>- Overrides:
hashCodein classjava.lang.Object
-
-