com.opensymphony.xwork2.ognl
Class OgnlValueStack

java.lang.Object
  extended by com.opensymphony.xwork2.ognl.OgnlValueStack
All Implemented Interfaces:
ValueStack, Serializable

public class OgnlValueStack
extends Object
implements Serializable, ValueStack

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: 2007-10-15 19:04:43 +0200 (Mon, 15 Oct 2007) $ $Id: OgnlValueStack.java 1647 2007-10-15 17:04:43Z rainerh $
Author:
Patrick Lightbody, tm_jee
See Also:
Serialized Form

Field Summary
(package private)  Map context
           
(package private)  Class defaultType
           
private  boolean devMode
           
private static Logger LOG
           
private static String MAP_IDENTIFIER_KEY
           
(package private)  OgnlUtil ognlUtil
           
(package private)  Map overrides
           
(package private)  CompoundRoot root
           
private static long serialVersionUID
           
 
Fields inherited from interface com.opensymphony.xwork2.util.ValueStack
REPORT_ERRORS_ON_NO_PROP, VALUE_STACK
 
Constructor Summary
protected OgnlValueStack(ValueStack vs, XWorkConverter xworkConverter, CompoundRootAccessor accessor, boolean allowStaticAccess)
           
protected OgnlValueStack(XWorkConverter xworkConverter, CompoundRootAccessor accessor, TextProvider prov, boolean allowStaticAccess)
           
 
Method Summary
private  void checkForInvalidProperties(String expr)
          This method looks for matching methods/properties in an action to warn the user if they specified a property that doesn't exist.
private  void findAvailableProperties(Class c, String expr, Set availableProperties, String parent)
          Look for available properties on an existing class.
private  Object findInContext(String name)
           
 String findString(String expr)
           
 Object findValue(String expr)
          Find a value by evaluating the given expression against the stack in the default search order.
 Object findValue(String expr, Class asType)
          Find a value by evaluating the given expression against the stack in the default search order.
 Map getContext()
          Gets the context for this value stack.
 Map getExprOverrides()
          Gets the override map if anyone exists.
 CompoundRoot getRoot()
          Get the CompoundRoot which holds the objects pushed onto the stack
static void link(Map context, Class clazz, String name)
           
private  void logLookupFailure(String expr, Exception e)
          Log a failed lookup, being more verbose when devMode=true.
 Object peek()
          Get the object on the top of the stack without changing the stack.
 Object pop()
          Get the object on the top of the stack and remove it from the stack.
 void push(Object o)
          Put this object onto the top of the stack
private  Object readResolve()
           
 void set(String key, Object o)
          Sets an object on the stack with the given key so it is retrievable by ValueStack.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.
 void setDevMode(String mode)
           
 void setExprOverrides(Map overrides)
          Set a override map containing key -> values that takes precedent when doing find operations on the ValueStack.
 void setOgnlUtil(OgnlUtil ognlUtil)
           
protected  void setRoot(XWorkConverter xworkConverter, CompoundRootAccessor accessor, CompoundRoot compoundRoot, boolean allowStaticMethodAccess)
           
 void setValue(String expr, Object value)
          Attempts to set a property on a bean in the stack with the given expression using the default search order.
 void setValue(String expr, Object value, boolean throwExceptionOnFailure)
          Attempts to set a property on a bean in the stack with the given expression using the default search order.
 int size()
          Get the number of objects in the stack
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

LOG

private static Logger LOG

devMode

private boolean devMode

root

CompoundRoot root

context

transient Map context

defaultType

Class defaultType

overrides

Map overrides

ognlUtil

transient OgnlUtil ognlUtil

MAP_IDENTIFIER_KEY

private static final String MAP_IDENTIFIER_KEY
See Also:
Constant Field Values
Constructor Detail

OgnlValueStack

protected OgnlValueStack(XWorkConverter xworkConverter,
                         CompoundRootAccessor accessor,
                         TextProvider prov,
                         boolean allowStaticAccess)

OgnlValueStack

protected OgnlValueStack(ValueStack vs,
                         XWorkConverter xworkConverter,
                         CompoundRootAccessor accessor,
                         boolean allowStaticAccess)
Method Detail

link

public static void link(Map context,
                        Class clazz,
                        String name)

setOgnlUtil

public void setOgnlUtil(OgnlUtil ognlUtil)

setRoot

protected void setRoot(XWorkConverter xworkConverter,
                       CompoundRootAccessor accessor,
                       CompoundRoot compoundRoot,
                       boolean allowStaticMethodAccess)

setDevMode

public void setDevMode(String mode)

getContext

public Map 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 interface ValueStack
Returns:
the context.

setDefaultType

public void setDefaultType(Class defaultType)
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 interface ValueStack
Parameters:
defaultType - the new default type

setExprOverrides

public void setExprOverrides(Map overrides)
Description copied from interface: ValueStack
Set a override map containing key -> values that takes precedent when doing find operations on the ValueStack.

See the unit test for ValueStackTest for examples.

Specified by:
setExprOverrides in interface ValueStack
Parameters:
overrides - overrides map.

getExprOverrides

public Map getExprOverrides()
Description copied from interface: ValueStack
Gets the override map if anyone exists.

Specified by:
getExprOverrides in interface ValueStack
Returns:
the override map, null if not set.

getRoot

public CompoundRoot getRoot()
Description copied from interface: ValueStack
Get the CompoundRoot which holds the objects pushed onto the stack

Specified by:
getRoot in interface ValueStack
Returns:
the root

setValue

public void setValue(String expr,
                     Object value)
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 interface ValueStack
Parameters:
expr - the expression defining the path to the property to be set.
value - the value to be set into the named property

setValue

public void setValue(String expr,
                     Object value,
                     boolean throwExceptionOnFailure)
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 interface ValueStack
Parameters:
expr - the expression defining the path to the property to be set.
value - the value to be set into the named property
throwExceptionOnFailure - a flag to tell whether an exception should be thrown if there is no property with the given name.

findString

public String findString(String expr)
Specified by:
findString in interface ValueStack

findValue

public Object findValue(String expr)
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 interface ValueStack
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

public Object findValue(String expr,
                        Class asType)
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 interface ValueStack
Parameters:
expr - the expression giving the path of properties to navigate to find the property value to return
asType - the type to convert the return value to
Returns:
the result of evaluating the expression

findInContext

private Object findInContext(String name)

checkForInvalidProperties

private void checkForInvalidProperties(String expr)
This method looks for matching methods/properties in an action to warn the user if they specified a property that doesn't exist.

Parameters:
expr - the property expression

findAvailableProperties

private void findAvailableProperties(Class c,
                                     String expr,
                                     Set availableProperties,
                                     String parent)
                              throws IntrospectionException
Look for available properties on an existing class.

Parameters:
c - the class to search on
expr - the property expression
availableProperties - a set of properties found
parent - a parent property
Throws:
IntrospectionException - when Ognl can't get property descriptors

logLookupFailure

private void logLookupFailure(String expr,
                              Exception e)
Log a failed lookup, being more verbose when devMode=true.

Parameters:
expr - The failed expression
e - The thrown exception.

peek

public Object peek()
Description copied from interface: ValueStack
Get the object on the top of the stack without changing the stack.

Specified by:
peek in interface ValueStack
Returns:
the object on the top.
See Also:
CompoundRoot.peek()

pop

public Object 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 interface ValueStack
Returns:
the object on the top of the stack
See Also:
CompoundRoot.pop()

push

public void push(Object o)
Description copied from interface: ValueStack
Put this object onto the top of the stack

Specified by:
push in interface ValueStack
Parameters:
o - the object to be pushed onto the stack
See Also:
CompoundRoot.push(Object)

set

public void set(String key,
                Object o)
Description copied from interface: ValueStack
Sets an object on the stack with the given key so it is retrievable by ValueStack.findValue(String), ValueStack.findValue(String, Class)

Specified by:
set in interface ValueStack
Parameters:
key - the key
o - the object

size

public int size()
Description copied from interface: ValueStack
Get the number of objects in the stack

Specified by:
size in interface ValueStack
Returns:
the number of objects in the stack

readResolve

private Object readResolve()


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.