Package org.apache.struts2.ognl
Class OgnlValueStack
java.lang.Object
org.apache.struts2.ognl.OgnlValueStack
- All Implemented Interfaces:
Serializable
,ClearableValueStack
,MemberAccessValueStack
,ValueStack
public class OgnlValueStack
extends Object
implements Serializable, ValueStack, ClearableValueStack, MemberAccessValueStack
Ognl implementation of a value stack that allows for dynamic Ognl expressions to be evaluated against it. When evaluating an expression,
the stack will be searched down the stack, from the latest objects pushed in to the earliest, looking for a bean with a getter or setter
for the given property or a method of the given name (depending on the expression being evaluated).
- Version:
- $Date$ $Id$
- Author:
- Patrick Lightbody, tm_jee
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected Class
protected OgnlUtil
protected CompoundRoot
protected SecurityMemberAccess
static final String
Fields inherited from interface org.apache.struts2.util.ValueStack
REPORT_ERRORS_ON_NO_PROP, VALUE_STACK
-
Constructor Summary
ModifierConstructorDescriptionprotected
OgnlValueStack
(XWorkConverter xworkConverter, RootAccessor accessor, TextProvider prov, SecurityMemberAccess securityMemberAccess) protected
OgnlValueStack
(ValueStack vs, XWorkConverter xworkConverter, RootAccessor accessor, SecurityMemberAccess securityMemberAccess) protected
OgnlValueStack
(ValueStack vs, XWorkConverter xworkConverter, RootAccessor accessor, TextProvider prov, SecurityMemberAccess securityMemberAccess) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Remove all values from the contextprotected Object
findInContext
(String name) findString
(String expr) findString
(String expr, boolean throwExceptionOnFailure) Find a value by evaluating the given expression against the stack in the default search order.Find a value by evaluating the given expression against the stack in the default search order.Gets the context for this value stack.Gets the override map if anyone exists.getRoot()
Get the CompoundRoot which holds the objects pushed onto the stackprotected Object
handleOgnlException
(String expr, boolean throwExceptionOnFailure, ognl.OgnlException e) protected void
handleOgnlException
(String expr, Object value, boolean throwExceptionOnFailure, ognl.OgnlException e) protected Object
handleOtherException
(String expr, boolean throwExceptionOnFailure, Exception e) protected void
handleRuntimeException
(String expr, Object value, boolean throwExceptionOnFailure, RuntimeException re) peek()
Get the object on the top of the stack without changing the stack.pop()
Get the object on the top of the stack and remove it from the stack.void
Put this object onto the top of the stackvoid
Sets an object on the stack with the given key so it is retrievable byValueStack.findValue(String)
,ValueStack.findValue(String, Class)
void
setDefaultType
(Class defaultType) Sets the default type to convert to if no type is provided when getting a value.protected void
setDevMode
(String mode) void
setExprOverrides
(Map<Object, Object> overrides) Set a override map containingkey -> values
that takes precedent when doing find operations on the ValueStack.protected void
setLogMissingProperties
(String logMissingProperties) protected void
setOgnlUtil
(OgnlUtil ognlUtil) void
setParameter
(String expr, Object value) Attempts to set a property on a bean in the stack with the given expression using the default search order.protected void
setRoot
(XWorkConverter xworkConverter, RootAccessor accessor, CompoundRoot compoundRoot, SecurityMemberAccess securityMemberAccess) protected void
setShouldFallbackToContext
(String shouldFallbackToContext) protected void
setupExceptionOnFailure
(boolean throwExceptionOnFailure) void
Attempts to set a property on a bean in the stack with the given expression using the default search order.void
Attempts to set a property on a bean in the stack with the given expression using the default search order.protected boolean
shouldLogMissingPropertyWarning
(ognl.OgnlException e) int
size()
Get the number of objects in the stackvoid
useAcceptProperties
(Set<Pattern> acceptedProperties) void
useExcludeProperties
(Set<Pattern> excludeProperties)
-
Field Details
-
THROW_EXCEPTION_ON_FAILURE
-
root
-
context
-
defaultType
-
overrides
-
ognlUtil
-
securityMemberAccess
-
-
Constructor Details
-
OgnlValueStack
protected OgnlValueStack(ValueStack vs, XWorkConverter xworkConverter, RootAccessor accessor, TextProvider prov, SecurityMemberAccess securityMemberAccess) - Since:
- 6.4.0
-
OgnlValueStack
protected OgnlValueStack(XWorkConverter xworkConverter, RootAccessor accessor, TextProvider prov, SecurityMemberAccess securityMemberAccess) - Since:
- 6.4.0
-
OgnlValueStack
protected OgnlValueStack(ValueStack vs, XWorkConverter xworkConverter, RootAccessor accessor, SecurityMemberAccess securityMemberAccess) - Since:
- 6.4.0
-
-
Method Details
-
setOgnlUtil
-
setRoot
protected void setRoot(XWorkConverter xworkConverter, RootAccessor accessor, CompoundRoot compoundRoot, SecurityMemberAccess securityMemberAccess) - Since:
- 6.4.0
-
setDevMode
-
setLogMissingProperties
-
setShouldFallbackToContext
-
getContext
Description copied from interface:ValueStack
Gets the context for this value stack. The context holds all the information in the value stack and it's surroundings.- Specified by:
getContext
in interfaceValueStack
- Returns:
- the context.
- See Also:
-
getActionContext
- Specified by:
getActionContext
in interfaceValueStack
-
setDefaultType
Description copied from interface:ValueStack
Sets the default type to convert to if no type is provided when getting a value.- Specified by:
setDefaultType
in interfaceValueStack
- Parameters:
defaultType
- the new default type- See Also:
-
setExprOverrides
Description copied from interface:ValueStack
Set a override map containingkey -> values
that takes precedent when doing find operations on the ValueStack.See the unit test for ValueStackTest for examples.
- Specified by:
setExprOverrides
in interfaceValueStack
- Parameters:
overrides
- overrides map.- See Also:
-
getExprOverrides
Description copied from interface:ValueStack
Gets the override map if anyone exists.- Specified by:
getExprOverrides
in interfaceValueStack
- Returns:
- the override map, null if not set.
- See Also:
-
getRoot
Description copied from interface:ValueStack
Get the CompoundRoot which holds the objects pushed onto the stack- Specified by:
getRoot
in interfaceValueStack
- Returns:
- the root
- See Also:
-
setParameter
Description copied from interface:ValueStack
Attempts to set a property on a bean in the stack with the given expression using the default search order. N.B.: unlike #setValue(String,Object) it doesn't allow eval expression.- Specified by:
setParameter
in interfaceValueStack
- Parameters:
expr
- the expression defining the path to the property to be set.value
- the value to be set into the named property- See Also:
-
setValue
Description copied from interface:ValueStack
Attempts to set a property on a bean in the stack with the given expression using the default search order.- Specified by:
setValue
in interfaceValueStack
- Parameters:
expr
- the expression defining the path to the property to be set.value
- the value to be set into the named property- See Also:
-
setValue
Description copied from interface:ValueStack
Attempts to set a property on a bean in the stack with the given expression using the default search order.- Specified by:
setValue
in interfaceValueStack
- Parameters:
expr
- the expression defining the path to the property to be set.value
- the value to be set into the named propertythrowExceptionOnFailure
- a flag to tell whether an exception should be thrown if there is no property with the given name.- See Also:
-
handleRuntimeException
protected void handleRuntimeException(String expr, Object value, boolean throwExceptionOnFailure, RuntimeException re) -
handleOgnlException
-
findString
- Specified by:
findString
in interfaceValueStack
- See Also:
-
findString
- Specified by:
findString
in interfaceValueStack
-
findValue
- Specified by:
findValue
in interfaceValueStack
- See Also:
-
setupExceptionOnFailure
protected void setupExceptionOnFailure(boolean throwExceptionOnFailure) -
handleOtherException
-
findValue
Description copied from interface:ValueStack
Find a value by evaluating the given expression against the stack in the default search order.- Specified by:
findValue
in interfaceValueStack
- Parameters:
expr
- the expression giving the path of properties to navigate to find the property value to return- Returns:
- the result of evaluating the expression
-
findValue
- Specified by:
findValue
in interfaceValueStack
- See Also:
-
handleOgnlException
-
shouldLogMissingPropertyWarning
protected boolean shouldLogMissingPropertyWarning(ognl.OgnlException e) -
findInContext
-
findValue
Description copied from interface:ValueStack
Find a value by evaluating the given expression against the stack in the default search order.- Specified by:
findValue
in interfaceValueStack
- Parameters:
expr
- the expression giving the path of properties to navigate to find the property value to returnasType
- the type to convert the return value to- Returns:
- the result of evaluating the expression
-
peek
Description copied from interface:ValueStack
Get the object on the top of the stack without changing the stack.- Specified by:
peek
in interfaceValueStack
- Returns:
- the object on the top.
- See Also:
-
pop
Description copied from interface:ValueStack
Get the object on the top of the stack and remove it from the stack.- Specified by:
pop
in interfaceValueStack
- Returns:
- the object on the top of the stack
- See Also:
-
push
Description copied from interface:ValueStack
Put this object onto the top of the stack- Specified by:
push
in interfaceValueStack
- Parameters:
o
- the object to be pushed onto the stack- See Also:
-
set
Description copied from interface:ValueStack
Sets an object on the stack with the given key so it is retrievable byValueStack.findValue(String)
,ValueStack.findValue(String, Class)
- Specified by:
set
in interfaceValueStack
- Parameters:
key
- the keyo
- the object- See Also:
-
size
public int size()Description copied from interface:ValueStack
Get the number of objects in the stack- Specified by:
size
in interfaceValueStack
- Returns:
- the number of objects in the stack
- See Also:
-
clearContextValues
public void clearContextValues()Description copied from interface:ClearableValueStack
Remove all values from the context- Specified by:
clearContextValues
in interfaceClearableValueStack
-
useAcceptProperties
- Specified by:
useAcceptProperties
in interfaceMemberAccessValueStack
-
useExcludeProperties
- Specified by:
useExcludeProperties
in interfaceMemberAccessValueStack
-