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
FieldsModifier and TypeFieldDescriptionprotected Classprotected OgnlUtilprotected CompoundRootprotected SecurityMemberAccessstatic final StringFields inherited from interface org.apache.struts2.util.ValueStack
REPORT_ERRORS_ON_NO_PROP, VALUE_STACK -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedOgnlValueStack(XWorkConverter xworkConverter, RootAccessor accessor, TextProvider prov, SecurityMemberAccess securityMemberAccess) protectedOgnlValueStack(ValueStack vs, XWorkConverter xworkConverter, RootAccessor accessor, SecurityMemberAccess securityMemberAccess) protectedOgnlValueStack(ValueStack vs, XWorkConverter xworkConverter, RootAccessor accessor, TextProvider prov, SecurityMemberAccess securityMemberAccess) -
Method Summary
Modifier and TypeMethodDescriptionvoidRemove all values from the contextprotected ObjectfindInContext(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 ObjecthandleOgnlException(String expr, boolean throwExceptionOnFailure, ognl.OgnlException e) protected voidhandleOgnlException(String expr, Object value, boolean throwExceptionOnFailure, ognl.OgnlException e) protected ObjecthandleOtherException(String expr, boolean throwExceptionOnFailure, Exception e) protected voidhandleRuntimeException(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.voidPut this object onto the top of the stackvoidSets an object on the stack with the given key so it is retrievable byValueStack.findValue(String),ValueStack.findValue(String, Class)voidsetDefaultType(Class defaultType) Sets the default type to convert to if no type is provided when getting a value.protected voidsetDevMode(String mode) voidsetExprOverrides(Map<Object, Object> overrides) Set a override map containingkey -> valuesthat takes precedent when doing find operations on the ValueStack.protected voidsetLogMissingProperties(String logMissingProperties) protected voidsetOgnlUtil(OgnlUtil ognlUtil) voidsetParameter(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 voidsetRoot(XWorkConverter xworkConverter, RootAccessor accessor, CompoundRoot compoundRoot, SecurityMemberAccess securityMemberAccess) protected voidsetShouldFallbackToContext(String shouldFallbackToContext) protected voidsetupExceptionOnFailure(boolean throwExceptionOnFailure) voidAttempts to set a property on a bean in the stack with the given expression using the default search order.voidAttempts to set a property on a bean in the stack with the given expression using the default search order.protected booleanshouldLogMissingPropertyWarning(ognl.OgnlException e) intsize()Get the number of objects in the stackvoiduseAcceptProperties(Set<Pattern> acceptedProperties) voiduseExcludeProperties(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:ValueStackGets the context for this value stack. The context holds all the information in the value stack and it's surroundings.- Specified by:
getContextin interfaceValueStack- Returns:
- the context.
- See Also:
-
getActionContext
- Specified by:
getActionContextin interfaceValueStack
-
setDefaultType
Description copied from interface:ValueStackSets the default type to convert to if no type is provided when getting a value.- Specified by:
setDefaultTypein interfaceValueStack- Parameters:
defaultType- the new default type- See Also:
-
setExprOverrides
Description copied from interface:ValueStackSet a override map containingkey -> valuesthat takes precedent when doing find operations on the ValueStack.See the unit test for ValueStackTest for examples.
- Specified by:
setExprOverridesin interfaceValueStack- Parameters:
overrides- overrides map.- See Also:
-
getExprOverrides
Description copied from interface:ValueStackGets the override map if anyone exists.- Specified by:
getExprOverridesin interfaceValueStack- Returns:
- the override map, null if not set.
- See Also:
-
getRoot
Description copied from interface:ValueStackGet the CompoundRoot which holds the objects pushed onto the stack- Specified by:
getRootin interfaceValueStack- Returns:
- the root
- See Also:
-
setParameter
Description copied from interface:ValueStackAttempts 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:
setParameterin 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:ValueStackAttempts to set a property on a bean in the stack with the given expression using the default search order.- Specified by:
setValuein 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:ValueStackAttempts to set a property on a bean in the stack with the given expression using the default search order.- Specified by:
setValuein 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:
findStringin interfaceValueStack- See Also:
-
findString
- Specified by:
findStringin interfaceValueStack
-
findValue
- Specified by:
findValuein interfaceValueStack- See Also:
-
setupExceptionOnFailure
protected void setupExceptionOnFailure(boolean throwExceptionOnFailure) -
handleOtherException
-
findValue
Description copied from interface:ValueStackFind a value by evaluating the given expression against the stack in the default search order.- Specified by:
findValuein 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:
findValuein interfaceValueStack- See Also:
-
handleOgnlException
-
shouldLogMissingPropertyWarning
protected boolean shouldLogMissingPropertyWarning(ognl.OgnlException e) -
findInContext
-
findValue
Description copied from interface:ValueStackFind a value by evaluating the given expression against the stack in the default search order.- Specified by:
findValuein 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:ValueStackGet the object on the top of the stack without changing the stack.- Specified by:
peekin interfaceValueStack- Returns:
- the object on the top.
- See Also:
-
pop
Description copied from interface:ValueStackGet the object on the top of the stack and remove it from the stack.- Specified by:
popin interfaceValueStack- Returns:
- the object on the top of the stack
- See Also:
-
push
Description copied from interface:ValueStackPut this object onto the top of the stack- Specified by:
pushin interfaceValueStack- Parameters:
o- the object to be pushed onto the stack- See Also:
-
set
Description copied from interface:ValueStackSets an object on the stack with the given key so it is retrievable byValueStack.findValue(String),ValueStack.findValue(String, Class)- Specified by:
setin interfaceValueStack- Parameters:
key- the keyo- the object- See Also:
-
size
public int size()Description copied from interface:ValueStackGet the number of objects in the stack- Specified by:
sizein interfaceValueStack- Returns:
- the number of objects in the stack
- See Also:
-
clearContextValues
public void clearContextValues()Description copied from interface:ClearableValueStackRemove all values from the context- Specified by:
clearContextValuesin interfaceClearableValueStack
-
useAcceptProperties
- Specified by:
useAcceptPropertiesin interfaceMemberAccessValueStack
-
useExcludeProperties
- Specified by:
useExcludePropertiesin interfaceMemberAccessValueStack
-