Browse Source

pruned bean references support as it was not used

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@809 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Keith Donald 17 years ago
parent
commit
199f6943d1
  1. 10
      org.springframework.expression/src/main/java/org/springframework/expression/EvaluationContext.java
  2. 4
      org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java
  3. 26
      org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java
  4. 79
      org.springframework.expression/src/test/java/org/springframework/expression/spel/TestScenarioCreator.java

10
org.springframework.expression/src/main/java/org/springframework/expression/EvaluationContext.java

@ -51,16 +51,6 @@ public interface EvaluationContext { @@ -51,16 +51,6 @@ public interface EvaluationContext {
*/
Object lookupVariable(String name);
// TODO lookupReference() - is it too expensive to return all objects within a context?
/**
* Look up an object reference in a particular context. If no contextName is specified (null), assume the default
* context. If no objectName is specified (null), return all objects in the specified context (List).
* @param contextName the context in which to perform the lookup (or <code>null</code> for default context)
* @param objectName the object to lookup in the context (or <code>null</code> to get all objects)
* @return a specific object or List
*/
Object lookupReference(Object contextName, String objectName) throws EvaluationException;
/**
* @return a list of resolvers that will be asked in turn to locate a constructor
*/

4
org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java

@ -91,10 +91,6 @@ public class ExpressionState { @@ -91,10 +91,6 @@ public class ExpressionState {
return this.relatedContext.lookupVariable(name);
}
public Object lookupReference(Object contextName, String objectName) throws EvaluationException {
return this.relatedContext.lookupReference(contextName, objectName);
}
public TypeComparator getTypeComparator() {
return this.relatedContext.getTypeComparator();
}

26
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java

@ -47,8 +47,6 @@ public class StandardEvaluationContext implements EvaluationContext { @@ -47,8 +47,6 @@ public class StandardEvaluationContext implements EvaluationContext {
private final Map<String, Object> variables = new HashMap<String, Object>();
private final Map<String, Map<String, Object>> simpleReferencesMap = new HashMap<String, Map<String, Object>>();
private final List<ConstructorResolver> constructorResolvers = new ArrayList<ConstructorResolver>();
private final List<MethodResolver> methodResolvers = new ArrayList<MethodResolver>();
@ -63,14 +61,12 @@ public class StandardEvaluationContext implements EvaluationContext { @@ -63,14 +61,12 @@ public class StandardEvaluationContext implements EvaluationContext {
private OperatorOverloader operatorOverloader = new StandardOperatorOverloader();
public StandardEvaluationContext() {
this.methodResolvers.add(new ReflectiveMethodResolver());
this.constructorResolvers.add(new ReflectiveConstructorResolver());
this.propertyAccessors.add(new ReflectivePropertyResolver());
}
public void setRootObject(Object rootObject) {
this.rootObject = rootObject;
}
@ -91,28 +87,6 @@ public class StandardEvaluationContext implements EvaluationContext { @@ -91,28 +87,6 @@ public class StandardEvaluationContext implements EvaluationContext {
return this.variables.get(name);
}
public void addReference(String contextName, String objectName, Object value) {
Map<String, Object> contextMap = this.simpleReferencesMap.get(contextName);
if (contextMap == null) {
contextMap = new HashMap<String, Object>();
this.simpleReferencesMap.put(contextName, contextMap);
}
contextMap.put(objectName, value);
}
public Object lookupReference(Object contextName, String objectName) {
String contextToLookup = (contextName == null ? "root" : (String) contextName);
// if (contextName==null) return simpleReferencesMap;
Map<String, Object> contextMap = this.simpleReferencesMap.get(contextToLookup);
if (contextMap == null) {
return null;
}
if (objectName == null) {
return contextMap;
}
return contextMap.get(objectName);
}
public void addConstructorResolver(ConstructorResolver resolver) {
this.constructorResolvers.add(this.constructorResolvers.size() - 1, resolver);
}

79
org.springframework.expression/src/test/java/org/springframework/expression/spel/TestScenarioCreator.java

@ -16,16 +16,10 @@ @@ -16,16 +16,10 @@
package org.springframework.expression.spel;
import java.awt.*;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.expression.spel.testresources.Fruit;
import org.springframework.expression.spel.testresources.Inventor;
import org.springframework.expression.spel.testresources.Person;
import org.springframework.expression.spel.testresources.PlaceOfBirth;
/**
@ -39,7 +33,6 @@ public class TestScenarioCreator { @@ -39,7 +33,6 @@ public class TestScenarioCreator {
public static StandardEvaluationContext getTestEvaluationContext() {
StandardEvaluationContext testContext = new StandardEvaluationContext();
setupRootContextObject(testContext);
populateContextMap(testContext);
populateVariables(testContext);
populateFunctions(testContext);
return testContext;
@ -94,78 +87,6 @@ public class TestScenarioCreator { @@ -94,78 +87,6 @@ public class TestScenarioCreator {
testContext.setRootObject(tesla);
}
/**
* Create a context configuration that tests can reference into using the
* @() language construct. at(context:objectName) will index a particular object within a particular context. The
* 'root' context will be used for references where no context is specified, eg.
* @(orange).
*
* @param testContext the evaluation context in which to register the new references
*/
private static void populateContextMap(StandardEvaluationContext testContext) {
Map<String, Map<String, Object>> contextToReferencesMap = new HashMap<String, Map<String, Object>>();
Person andy, christian, julie, stefanie, rob, rod, adrian;
andy = new Person("Andy");
christian = new Person("Christian");
julie = new Person("Julie");
stefanie = new Person("Stefanie");
rod = new Person("Rod");
rob = new Person("Rob");
adrian = new Person("Adrian");
Map<String, Object> people = new HashMap<String, Object>();
people.put("Andy", andy);
people.put("Christian", christian);
people.put("Julie", julie);
people.put("Stefanie", stefanie);
Map<String, Object> colors = new HashMap<String, Object>();
colors.put("red", Color.red);
colors.put("orange", Color.orange);
colors.put("yellow", Color.yellow);
colors.put("green", Color.red);
colors.put("blue", Color.orange);
contextToReferencesMap.put("colors", colors);
Map<String, Object> fruits = new HashMap<String, Object>();
fruits.put("orange", new Fruit("Orange", Color.orange, "orange"));
fruits.put("apple", new Fruit("Apple", Color.green, "green"));
fruits.put("banana", new Fruit("Banana", Color.yellow, "yellow"));
Map<String, Object> root = new HashMap<String, Object>();
root.put("orange", new Fruit("Orange", Color.orange, "orange"));
root.put("apple", new Fruit("Apple", Color.green, "green"));
root.put("banana", new Fruit("Banana", Color.yellow, "yellow"));
root.put("red", Color.red);
root.put("orange", Color.orange);
root.put("yellow", Color.yellow);
root.put("green", Color.red);
root.put("blue", Color.orange);
root.put("Andy", andy);
root.put("Christian", christian);
root.put("Julie", julie);
root.put("Stefanie", stefanie);
root.put("Adrian", adrian);
root.put("Rob", rob);
root.put("Rod", rod);
contextToReferencesMap.put("people", people);
contextToReferencesMap.put("fruits", fruits);
contextToReferencesMap.put("root", root); // used if no context
// specified
contextToReferencesMap.put("a.b.c", fruits);
java.util.Set<String> contextKeys = contextToReferencesMap.keySet();
for (String contextName : contextKeys) {
Map<String, Object> elements = contextToReferencesMap.get(contextName);
Set<String> objectNames = elements.keySet();
for (String objectName : objectNames) {
testContext.addReference(contextName, objectName, elements.get(objectName));
}
}
}
// These methods are registered in the test context and therefore accessible through function calls
// in test expressions

Loading…
Cancel
Save