EvaluationContext.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 2004-2008 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.expression;
  17. import java.util.List;
  18. import org.springframework.expression.spel.standard.StandardEvaluationContext;
  19. import org.springframework.expression.spel.standard.StandardTypeUtilities;
  20. /**
  21. * Expressions are executed in an evaluation context. It is in this context that references are resolved when
  22. * encountered during expression evaluation.
  23. *
  24. * There is a default implementation of the EvaluationContext, {@link StandardEvaluationContext} that can be extended,
  25. * rather than having to implement everything.
  26. *
  27. * @author Andy Clement
  28. */
  29. public interface EvaluationContext {
  30. /**
  31. * @return the root context object against which unqualified properties/methods/etc should be resolved
  32. */
  33. Object getRootContextObject();
  34. /**
  35. * @return a TypeUtilities implementation that can be used for looking up types, converting types, comparing types,
  36. * and overloading basic operators for types. A standard implementation is provided in {@link StandardTypeUtilities}
  37. */
  38. TypeUtils getTypeUtils();
  39. /**
  40. * Look up a named variable within this execution context.
  41. *
  42. * @param name variable to lookup
  43. * @return the value of the variable
  44. */
  45. Object lookupVariable(String name);
  46. /**
  47. * Set a named variable within this execution context to a specified value.
  48. *
  49. * @param name variable to set
  50. * @param value value to be placed in the variable
  51. */
  52. void setVariable(String name, Object value);
  53. // TODO lookupReference() - is it too expensive to return all objects within a context?
  54. /**
  55. * Look up an object reference in a particular context. If no contextName is specified (null), assume the default
  56. * context. If no objectName is specified (null), return all objects in the specified context (List<Object>).
  57. *
  58. * @param contextName the context in which to perform the lookup (or null for default context)
  59. * @param objectName the object to lookup in the context (or null to get all objects)
  60. * @return a specific object or List<Object>
  61. */
  62. Object lookupReference(Object contextName, Object objectName) throws EvaluationException;
  63. /**
  64. * @return a list of resolvers that will be asked in turn to locate a constructor
  65. */
  66. List<ConstructorResolver> getConstructorResolvers();
  67. /**
  68. * @return a list of resolvers that will be asked in turn to locate a method
  69. */
  70. List<MethodResolver> getMethodResolvers();
  71. /**
  72. * @return a list of accessors that will be asked in turn to read/write a property
  73. */
  74. List<PropertyAccessor> getPropertyAccessors();
  75. }