Class OgnlContext

java.lang.Object
ognl.OgnlContext
All Implemented Interfaces:
Map<String,Object>

public class OgnlContext extends Object implements Map<String,Object>
This class defines the execution context for an OGNL expression
  • Field Details

    • ROOT_CONTEXT_KEY

      private static final String ROOT_CONTEXT_KEY
      See Also:
    • THIS_CONTEXT_KEY

      private static final String THIS_CONTEXT_KEY
      See Also:
    • TRACE_EVALUATIONS_CONTEXT_KEY

      private static final String TRACE_EVALUATIONS_CONTEXT_KEY
      See Also:
    • LAST_EVALUATION_CONTEXT_KEY

      private static final String LAST_EVALUATION_CONTEXT_KEY
      See Also:
    • KEEP_LAST_EVALUATION_CONTEXT_KEY

      private static final String KEEP_LAST_EVALUATION_CONTEXT_KEY
      See Also:
    • IGNORE_READ_METHODS_CONTEXT_KEY

      private static final String IGNORE_READ_METHODS_CONTEXT_KEY
      See Also:
    • PROPERTY_KEY_PREFIX

      private static final String PROPERTY_KEY_PREFIX
      See Also:
    • DEFAULT_IGNORE_READ_METHODS

      private static final boolean DEFAULT_IGNORE_READ_METHODS
      See Also:
    • 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 Map<String,Object> RESERVED_KEYS
    • root

      private Object root
    • currentObject

      private 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 Map<String,Object> internalContext
    • classResolver

      private final ClassResolver classResolver
    • typeConverter

      private final TypeConverter typeConverter
    • memberAccess

      private final MemberAccess memberAccess
    • typeStack

      private final List<Class<?>> typeStack
    • accessorStack

      private final List<Class<?>> accessorStack
    • localReferenceCounter

      private int localReferenceCounter
    • localReferenceMap

      private Map<String, LocalReference> localReferenceMap
  • Constructor Details

    • 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 Details

    • setValues

      public void setValues(Map<String,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(Map<String,Object> values)
      Similar to setValues(Map) but returns the current instance of OgnlContext
      Parameters:
      values - a Map of values
      Returns:
      the current instance of OgnlContext
    • getValues

      public Map<String,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(Object value)
    • getRoot

      public Object getRoot()
    • getTraceEvaluations

      @Deprecated public boolean getTraceEvaluations()
      Deprecated.
      since OGNL 3.4.0, use isTraceEvaluations()
    • 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, use isKeepLastEvaluation()
    • isKeepLastEvaluation

      public boolean isKeepLastEvaluation()
      Returns true if the last evaluation that was done on this context is retained and available through getLastEvaluation(). 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 through getLastEvaluation(). The default is true.
      Parameters:
      value - true if the last evaluation for this context should be retained and available through getLastEvaluation(), 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(Object value)
    • getCurrentObject

      public Object getCurrentObject()
    • setCurrentAccessor

      public void setCurrentAccessor(Class<?> type)
    • getCurrentAccessor

      public Class<?> getCurrentAccessor()
    • getPreviousAccessor

      public Class<?> getPreviousAccessor()
    • getFirstAccessor

      public Class<?> getFirstAccessor()
    • getCurrentType

      public Class<?> getCurrentType()
      Gets the current class type being evaluated on the stack, as set by setCurrentType(Class).
      Returns:
      The current object type, may be null.
    • setCurrentType

      public void setCurrentType(Class<?> type)
    • getPreviousType

      public Class<?> getPreviousType()
      Represents the last known object type on the evaluation stack, will be the value of the last known getCurrentType().
      Returns:
      The previous type of object on the stack, may be null.
    • setPreviousType

      public void setPreviousType(Class<?> type)
    • getFirstType

      public 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 via popEvaluation().
      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(String key, LocalReference reference)
    • getLocalReferences

      public Map<String, LocalReference> getLocalReferences()
    • size

      public int size()
      Specified by:
      size in interface Map<String,Object>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<String,Object>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<String,Object>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<String,Object>
    • get

      public Object get(Object key)
      Specified by:
      get in interface Map<String,Object>
    • put

      public Object put(String key, Object value)
      Specified by:
      put in interface Map<String,Object>
    • remove

      public Object remove(Object key)
      Specified by:
      remove in interface Map<String,Object>
    • putAll

      public void putAll(Map<? extends String, ?> t)
      Specified by:
      putAll in interface Map<String,Object>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<String,Object>
    • keySet

      public Set<String> keySet()
      Specified by:
      keySet in interface Map<String,Object>
    • values

      public Collection<Object> values()
      Specified by:
      values in interface Map<String,Object>
    • entrySet

      public Set<Map.Entry<String,Object>> entrySet()
      Specified by:
      entrySet in interface Map<String,Object>
    • equals

      public boolean equals(Object other)
      Specified by:
      equals in interface Map<String,Object>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<String,Object>
      Overrides:
      hashCode in class Object