⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ognlcontext.java

📁 OGNL文档包:----->最新版本!学习Struts2的必须帮助参考文档
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//--------------------------------------------------------------------------
//	Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
//  All rights reserved.
//
//	Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//	Redistributions of source code must retain the above copyright notice,
//  this list of conditions and the following disclaimer.
//	Redistributions in binary form must reproduce the above copyright
//  notice, this list of conditions and the following disclaimer in the
//  documentation and/or other materials provided with the distribution.
//	Neither the name of the Drew Davidson nor the names of its contributors
//  may be used to endorse or promote products derived from this software
//  without specific prior written permission.
//
//	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
//  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
//  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
//  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
//  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
//  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
//  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
//  DAMAGE.
//--------------------------------------------------------------------------
package ognl;

import java.util.*;

/**
 * This class defines the execution context for an OGNL expression
 * @author Luke Blanshard (blanshlu@netscape.net)
 * @author Drew Davidson (drew@ognl.org)
 */
public class OgnlContext extends Object implements Map
{
    public static final String          CONTEXT_CONTEXT_KEY = "context";
    public static final String          ROOT_CONTEXT_KEY = "root";
    public static final String          THIS_CONTEXT_KEY = "this";
    public static final String          TRACE_EVALUATIONS_CONTEXT_KEY = "_traceEvaluations";
    public static final String          LAST_EVALUATION_CONTEXT_KEY = "_lastEvaluation";
    public static final String          KEEP_LAST_EVALUATION_CONTEXT_KEY = "_keepLastEvaluation";
    public static final String          CLASS_RESOLVER_CONTEXT_KEY = "_classResolver";
    public static final String          TYPE_CONVERTER_CONTEXT_KEY = "_typeConverter";
    public static final String          MEMBER_ACCESS_CONTEXT_KEY = "_memberAccess";

    private static final String         PROPERTY_KEY_PREFIX = "ognl";
    private static boolean              DEFAULT_TRACE_EVALUATIONS = false;
    private static boolean              DEFAULT_KEEP_LAST_EVALUATION = false;

    public static final ClassResolver   DEFAULT_CLASS_RESOLVER = new DefaultClassResolver();
    public static final TypeConverter   DEFAULT_TYPE_CONVERTER = new DefaultTypeConverter();
    public static final MemberAccess    DEFAULT_MEMBER_ACCESS = new DefaultMemberAccess(false);

    private static Map                  RESERVED_KEYS = new HashMap(11);

    private Object                      root;
    private Object                      currentObject;
    private Node                        currentNode;
    private boolean                     traceEvaluations = DEFAULT_TRACE_EVALUATIONS;
    private Evaluation                  rootEvaluation;
    private Evaluation                  currentEvaluation;
    private Evaluation                  lastEvaluation;
    private boolean                     keepLastEvaluation = DEFAULT_KEEP_LAST_EVALUATION;
    private Map                         values = new HashMap(23);
    private ClassResolver               classResolver = DEFAULT_CLASS_RESOLVER;
    private TypeConverter               typeConverter = DEFAULT_TYPE_CONVERTER;
    private MemberAccess                memberAccess = DEFAULT_MEMBER_ACCESS;

    static
    {
        String          s;

        RESERVED_KEYS.put(CONTEXT_CONTEXT_KEY, null);
        RESERVED_KEYS.put(ROOT_CONTEXT_KEY, null);
        RESERVED_KEYS.put(THIS_CONTEXT_KEY, null);
        RESERVED_KEYS.put(TRACE_EVALUATIONS_CONTEXT_KEY, null);
        RESERVED_KEYS.put(LAST_EVALUATION_CONTEXT_KEY, null);
        RESERVED_KEYS.put(KEEP_LAST_EVALUATION_CONTEXT_KEY, null);
        RESERVED_KEYS.put(CLASS_RESOLVER_CONTEXT_KEY, null);
        RESERVED_KEYS.put(TYPE_CONVERTER_CONTEXT_KEY, null);
        RESERVED_KEYS.put(MEMBER_ACCESS_CONTEXT_KEY, null);

        try {
            if ((s = System.getProperty(PROPERTY_KEY_PREFIX + ".traceEvaluations")) != null) {
                DEFAULT_TRACE_EVALUATIONS = Boolean.valueOf(s.trim()).booleanValue();
            }
            if ((s = System.getProperty(PROPERTY_KEY_PREFIX + ".keepLastEvaluation")) != null) {
                DEFAULT_KEEP_LAST_EVALUATION = Boolean.valueOf(s.trim()).booleanValue();
            }
        } catch (SecurityException ex) {
            // restricted access environment, just keep defaults
        }
    }

    /**
        Constructs a new OgnlContext with the default class resolver, type converter and
        member access.
     */
    public OgnlContext()
    {
        super();
    }

    /**
        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.
     */
    public OgnlContext(ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess)
    {
        this();
        if (classResolver != null) {
            this.classResolver = classResolver;
        }
        if (typeConverter != null) {
            this.typeConverter = typeConverter;
        }
        if (memberAccess != null) {
            this.memberAccess = memberAccess;
        }
    }

    public OgnlContext(Map values)
    {
        super();
        this.values = values;
    }

    public OgnlContext(ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess, Map values)
    {
        this(classResolver, typeConverter, memberAccess);
        this.values = values;
    }

    public void setValues(Map value)
    {
        for (Iterator it = value.keySet().iterator(); it.hasNext();) {
            Object      k = it.next();

            values.put(k, value.get(k));
        }
    }

    public Map getValues()
    {
        return values;
    }

    public void setClassResolver(ClassResolver value)
    {
        if (value == null) {
            throw new IllegalArgumentException("cannot set ClassResolver to null");
        }
        classResolver = value;
    }

    public ClassResolver getClassResolver()
    {
        return classResolver;
    }

    public void setTypeConverter(TypeConverter value)
    {
        if (value == null) {
            throw new IllegalArgumentException("cannot set TypeConverter to null");
        }
        typeConverter = value;
    }

    public TypeConverter getTypeConverter()
    {
        return typeConverter;
    }

    public void setMemberAccess(MemberAccess value)
    {
        if (value == null) {
            throw new IllegalArgumentException("cannot set MemberAccess to null");
        }
        memberAccess = value;
    }

    public MemberAccess getMemberAccess()
    {
        return memberAccess;
    }

    public void setRoot(Object value)
    {
        root = value;
    }

    public Object getRoot()
    {
        return root;
    }

    public boolean getTraceEvaluations()
    {
        return traceEvaluations;
    }

    public void setTraceEvaluations(boolean value)
    {
        traceEvaluations = value;
    }

    public Evaluation getLastEvaluation()
    {
        return lastEvaluation;
    }

    public void setLastEvaluation(Evaluation value)
    {
        lastEvaluation = value;
    }

    /**
        This method can be called when the last evaluation has been used
        and can be returned for reuse in the free pool maintained by the
        runtime.  This is not a necessary step, but is useful for keeping
        memory usage down.  This will recycle the last evaluation and then
        set the last evaluation to null.
     */
    public void recycleLastEvaluation()
    {
        OgnlRuntime.getEvaluationPool().recycleAll(lastEvaluation);
        lastEvaluation = null;
    }

    /**
        Returns true if the last evaluation that was done on this
        context is retained and available through <code>getLastEvaluation()</code>.
        The default is true.
     */
    public boolean getKeepLastEvaluation()
    {
        return keepLastEvaluation;
    }

    /**
        Sets whether the last evaluation that was done on this
        context is retained and available through <code>getLastEvaluation()</code>.
        The default is true.
     */
    public void setKeepLastEvaluation(boolean value)
    {
        keepLastEvaluation = value;
    }

    public void setCurrentObject(Object value)
    {
        currentObject = value;
    }

    public Object getCurrentObject()
    {
        return currentObject;
    }

    public void setCurrentNode(Node value)
    {
        currentNode = value;
    }

    public Node getCurrentNode()
    {
        return currentNode;
    }

    /**
        Gets the current Evaluation from the top of the stack.
        This is the Evaluation that is in process of evaluating.
     */
    public Evaluation getCurrentEvaluation()
    {
        return currentEvaluation;
    }

    public void setCurrentEvaluation(Evaluation value)
    {
        currentEvaluation = value;
    }

    /**
        Gets the root of the evaluation stack.
        This Evaluation contains the node representing
        the root expression and the source is the root
        source object.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -