关闭

Struts源码之ValueStack

528人阅读 评论(0) 收藏 举报
分类:


/**
 * ValueStack allows multiple beans to be pushed in and dynamic EL 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).
 */
public interface ValueStack {

    public static final String VALUE_STACK = "com.opensymphony.xwork2.util.ValueStack.ValueStack";

    public static final String REPORT_ERRORS_ON_NO_PROP = "com.opensymphony.xwork2.util.ValueStack.ReportErrorsOnNoProp";

    /**
     * Gets the context for this value stack. The context holds all the information in the value stack and it's surroundings.
     *
     * @return  the context.
     */
    public abstract Map<String, Object> getContext();

    /**
     * Sets the default type to convert to if no type is provided when getting a value.
     *
     * @param defaultType the new default type
     */
    public abstract void setDefaultType(Class defaultType);

    /**
     * Set a override map containing <code>key -> values</code> that takes precedent when doing find operations on the ValueStack.
     * <p/>
     * See the unit test for ValueStackTest for examples.
     *
     * @param overrides  overrides map.
     */
    public abstract void setExprOverrides(Map<Object, Object> overrides);

    /**
     * Gets the override map if anyone exists.
     *
     * @return the override map, <tt>null</tt> if not set.
     */
    public abstract Map<Object, Object> getExprOverrides();

    /**
     * Get the CompoundRoot which holds the objects pushed onto the stack
     *
     * @return the root
     */
    public abstract CompoundRoot getRoot();

    /**
     * Attempts to set a property on a bean in the stack with the given expression using the default search order.
     *
     * @param expr  the expression defining the path to the property to be set.
     * @param value the value to be set into the named property
     */
    public abstract 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.
     * N.B.: unlike #setValue(String,Object) it doesn't allow eval expression.
     * @param expr  the expression defining the path to the property to be set.
     * @param value the value to be set into the named property
     */
    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.
     *
     * @param expr                    the expression defining the path to the property to be set.
     * @param value                   the value to be set into the named property
     * @param throwExceptionOnFailure a flag to tell whether an exception should be thrown if there is no property with
     *                                the given name.
     */
    public abstract void setValue(String expr, Object value, boolean throwExceptionOnFailure);

    public abstract String findString(String expr);
    public abstract String findString(String expr, boolean throwExceptionOnFailure);

    /**
     * Find a value by evaluating the given expression against the stack in the default search order.
     *
     * @param expr the expression giving the path of properties to navigate to find the property value to return
     * @return the result of evaluating the expression
     */
    public abstract Object findValue(String expr);

    public abstract Object findValue(String expr, boolean throwExceptionOnFailure);

    /**
     * Find a value by evaluating the given expression against the stack in the default search order.
     *
     * @param expr   the expression giving the path of properties to navigate to find the property value to return
     * @param asType the type to convert the return value to
     * @return the result of evaluating the expression
     */
    public abstract Object findValue(String expr, Class asType);
    public abstract Object findValue(String expr, Class asType,  boolean throwExceptionOnFailure);

    /**
     * Get the object on the top of the stack <b>without</b> changing the stack.
     *
     * @return the object on the top.
     * @see CompoundRoot#peek()
     */
    public abstract Object peek();

    /**
     * Get the object on the top of the stack and <b>remove</b> it from the stack.
     *
     * @return the object on the top of the stack
     * @see CompoundRoot#pop()
     */
    public abstract Object pop();

    /**
     * Put this object onto the top of the stack
     *
     * @param o the object to be pushed onto the stack
     * @see CompoundRoot#push(Object)
     */
    public abstract void push(Object o);

    /**
     * Sets an object on the stack with the given key
     * so it is retrievable by {@link #findValue(String)}, {@link #findValue(String, Class)}
     *
     * @param key  the key
     * @param o    the object
     */
    public abstract void set(String key, Object o);

    /**
     * Get the number of objects in the stack
     *
     * @return the number of objects in the stack
     */
    public abstract int size();

}


0
0
查看评论

Struts中<s:debug/>标签中ValueStack与ContextStack的区别

在用户发送HTTP请求给Struts2框架后,Struts2框架会穿件ActionContext、ValueStack和相应的action对象: 而该action对象会放入ValueStack对象中,ValueStack对象则会放入ActionContext对象中。在JSP页面访问contex...
  • zhoucheng05_13
  • zhoucheng05_13
  • 2016-10-08 15:18
  • 665

Struts-ValueStack和OGNL总结

(1)ValueStack是一个借口,在Struts2中使用OGNL表达式实际上是使用实现了ValueStack接口类的OgnlValueStack,它是ValueStack的默认实现类。 (2)ValueStack贯穿整个action的生命周期,每一个action实例都拥有一个ValueStac...
  • qq924862077
  • qq924862077
  • 2015-11-18 22:23
  • 1284

Struts2的ValueStack(值栈)的原理

1.     数据传输背后机制:ValueStack(值栈)   在这一切的背后,是因为有了ValueStack(值栈)!   ValueStack基础:OGNL 要了解ValueStack,必须先理解OGNL(Obj...
  • u012312373
  • u012312373
  • 2015-06-17 21:57
  • 1554

深度解析Struts2中ValueStack

对于每一个action的调用,Struts在执行相应的动作方法之前会先创建一个名为ValueStack的对象
  • canot
  • canot
  • 2016-04-09 22:01
  • 6880

Strus2中关于ValueStack详解

什么是ValueStack它是一个接口com.opensymphony.xwork2.util.ValueStack。我们使用它是将其做为一个容器,用于携带action数据到页面。在页面上通过ognl表达式获取数据。 valueStack主要是将action数据携带到页面上,通过ognl获取数据1...
  • qq32933432
  • qq32933432
  • 2016-06-02 17:49
  • 1284

Struts2中的ValueStack-OgnlValueStack中的Context和Root存数据和取数据

将数据obj放入值栈ValueStack中的RootActionContext.getContext().getValueStack().push(obj);通过键值对key和value将数据放入值栈ValueStack中的ContextActionContext.getContext().put(...
  • YoungStar70
  • YoungStar70
  • 2017-10-26 10:26
  • 446

action获取ValueStack中的值

HttpServletRequest request = ServletActionContext.getRequest();ValueStack vs = (ValueStack)request.getAttribute("struts.valueStack");String ...
  • mingjian_zheng
  • mingjian_zheng
  • 2009-05-08 15:15
  • 3159

struts ValueStack 详解

一、ValueStack     1.ValueStack是一个接口,在struts2中使用OGNL(Object-Graph Navigation Language)表达式实际上是使用       ...
  • xiaomu709421487
  • xiaomu709421487
  • 2016-02-27 21:17
  • 5727

Struts2中JSP获取值栈(ValueStack)中的数据

什么是值栈 值栈就是OGNL表达式存取数据的地方,Struts2是在有请求到达的时候为每个请求创建一个新的值栈,这也就是说值栈和请求是一一对应的,值栈封装了一次请求所需要的所有数据,这种一一对应的关系使值栈能够线程安全地为每个请求提供公共的数据存取服务。 值栈的生命周期 值栈可以作为一个数据的...
  • situliang
  • situliang
  • 2017-06-16 23:33
  • 1496

struts.valueStack (Action 中属性存放的原理)

Java代码   //获取封装输出信息的 ValueStack 对象   ValueStack vs = (ValueStack)request.getAttribute("strut...
  • q1054261752
  • q1054261752
  • 2015-10-24 13:21
  • 204
    个人资料
    • 访问:595435次
    • 积分:8870
    • 等级:
    • 排名:第2573名
    • 原创:307篇
    • 转载:16篇
    • 译文:0篇
    • 评论:125条
    Github
    访问:https://github.com/IAMTJW
    博客专栏
    最新评论