Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ibatis.ognl;
import org.apache.ibatis.ognl.enhance.LocalReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* This class defines the execution context for an OGNL expression
*/
public class OgnlContext implements Map {
private static final String ROOT_CONTEXT_KEY = "root";
private static final String THIS_CONTEXT_KEY = "this";
private static final String TRACE_EVALUATIONS_CONTEXT_KEY = "_traceEvaluations";
private static final String LAST_EVALUATION_CONTEXT_KEY = "_lastEvaluation";
private static final String KEEP_LAST_EVALUATION_CONTEXT_KEY = "_keepLastEvaluation";
private static final String PROPERTY_KEY_PREFIX = "org.apache.ibatis.ognl";
private static boolean DEFAULT_TRACE_EVALUATIONS = false;
private static boolean DEFAULT_KEEP_LAST_EVALUATION = false;
private static final Map RESERVED_KEYS = new HashMap<>(6);
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 final Map internalContext;
private final ClassResolver classResolver;
private final TypeConverter typeConverter;
private final MemberAccess memberAccess;
static {
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);
try {
String property;
if ((property = System.getProperty(PROPERTY_KEY_PREFIX + ".traceEvaluations")) != null) {
DEFAULT_TRACE_EVALUATIONS = Boolean.parseBoolean(property.trim());
}
if ((property = System.getProperty(PROPERTY_KEY_PREFIX + ".keepLastEvaluation")) != null) {
DEFAULT_KEEP_LAST_EVALUATION = Boolean.parseBoolean(property.trim());
}
} catch (SecurityException ex) {
// restricted access environment, just keep defaults
}
}
private final List> typeStack = new ArrayList<>(3); // size 3 should be enough stack for most expressions
private final List> accessorStack = new ArrayList<>(3); // size 3 should be enough stack for most expressions
private int localReferenceCounter = 0;
private Map localReferenceMap = null;
/**
* 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, except memberAccess which must be non-null.
*
* @param classResolver the ClassResolver for a new OgnlContext.
* @param typeConverter the TypeConverter for a new OgnlContext.
* @param memberAccess the MemberAccess for a new OgnlContext. Must be non-null.
*/
public OgnlContext(ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess) {
// No 'values' map has been specified, so we create one of the default size: 23 entries
this(memberAccess, classResolver, typeConverter, null);
}
/**
* Constructs a new OgnlContext with the given member access, class resolver, type converter and values.
* If any of these parameters is null the default will be used, except memberAccess which must be non-null.
*
* @param memberAccess the MemberAccess for a new OgnlContext. Must be non-null.
* @param classResolver the ClassResolver for a new OgnlContext.
* @param typeConverter the TypeConverter for a new OgnlContext.
* @param initialContext the initial context of values to provide for a new OgnlContext.
*/
public OgnlContext(MemberAccess memberAccess, ClassResolver classResolver, TypeConverter typeConverter, OgnlContext initialContext) {
if (classResolver != null) {
this.classResolver = classResolver;
} else {
this.classResolver = new DefaultClassResolver();
}
if (typeConverter != null) {
this.typeConverter = typeConverter;
} else {
this.typeConverter = new DefaultTypeConverter();
}
if (memberAccess != null) {
this.memberAccess = memberAccess;
} else {
throw new IllegalArgumentException("MemberAccess implementation must be provided - null not permitted!");
}
this.internalContext = new HashMap<>(23); // No 'values' map has been specified, so we create one of the default size: 23 entries
if (initialContext != null) {
this.internalContext.putAll(initialContext.internalContext);
}
}
/**
* Set (put) the provided value map content into the existing values Map for this OgnlContext.
*
* @param values a Map of additional values to put into this OgnlContext.
*/
public void setValues(Map