Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@619 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
147 changed files with 2985 additions and 4334 deletions
@ -1,115 +0,0 @@
@@ -1,115 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2008 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.context.expression; |
||||
|
||||
import org.springframework.beans.factory.config.BeanExpressionContext; |
||||
import org.springframework.beans.factory.config.BeanExpressionResolver; |
||||
import org.springframework.util.Assert; |
||||
|
||||
/** |
||||
* Abstract implementation of the {@link BeanExpressionResolver} interface. |
||||
* Handles the common mixing of expression parts with literal parts. |
||||
* |
||||
* <p>Subclasses need to implement the {@link #evaluateExpression} template |
||||
* method for actual expression evaluation. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
* @see #setExpressionPrefix |
||||
* @see #setExpressionSuffix |
||||
*/ |
||||
public abstract class AbstractBeanExpressionResolver implements BeanExpressionResolver { |
||||
|
||||
/** Default expression prefix: "#{" */ |
||||
public static final String DEFAULT_EXPRESSION_PREFIX = "#{"; |
||||
|
||||
/** Default expression suffix: "}" */ |
||||
public static final String DEFAULT_EXPRESSION_SUFFIX = "}"; |
||||
|
||||
|
||||
private String expressionPrefix = DEFAULT_EXPRESSION_PREFIX; |
||||
|
||||
private String expressionSuffix = DEFAULT_EXPRESSION_SUFFIX; |
||||
|
||||
|
||||
/** |
||||
* Set the prefix that an expression string starts with. |
||||
* The default is "#{". |
||||
* @see #DEFAULT_EXPRESSION_PREFIX |
||||
*/ |
||||
public void setExpressionPrefix(String expressionPrefix) { |
||||
Assert.hasText(expressionPrefix, "Expression prefix must not be empty"); |
||||
this.expressionPrefix = expressionPrefix; |
||||
} |
||||
|
||||
/** |
||||
* Set the suffix that an expression string ends with. |
||||
* The default is "}". |
||||
* @see #DEFAULT_EXPRESSION_SUFFIX |
||||
*/ |
||||
public void setExpressionSuffix(String expressionSuffix) { |
||||
Assert.hasText(expressionSuffix, "Expression suffix must not be empty"); |
||||
this.expressionSuffix = expressionSuffix; |
||||
} |
||||
|
||||
|
||||
public Object evaluate(String value, BeanExpressionContext evalContext) { |
||||
if (value == null) { |
||||
return null; |
||||
} |
||||
Object result = ""; |
||||
int prefixIndex = value.indexOf(this.expressionPrefix); |
||||
int endIndex = 0; |
||||
while (prefixIndex != -1) { |
||||
int exprStart = prefixIndex + this.expressionPrefix.length(); |
||||
int suffixIndex = value.indexOf(this.expressionSuffix, exprStart); |
||||
if (suffixIndex != -1) { |
||||
if (prefixIndex > 0) { |
||||
result = result + value.substring(endIndex, prefixIndex); |
||||
} |
||||
endIndex = suffixIndex + this.expressionSuffix.length(); |
||||
String expr = value.substring(exprStart, suffixIndex); |
||||
Object exprResult = evaluateExpression(expr, evalContext); |
||||
if (result != null && !"".equals(result)) { |
||||
result = result.toString() + exprResult.toString(); |
||||
} |
||||
else { |
||||
result = exprResult; |
||||
} |
||||
prefixIndex = value.indexOf(this.expressionPrefix, suffixIndex); |
||||
} |
||||
else { |
||||
prefixIndex = -1; |
||||
} |
||||
} |
||||
if (endIndex < value.length()) { |
||||
return result + value.substring(endIndex); |
||||
} |
||||
else { |
||||
return result; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Evaluate the given expression. |
||||
* @param exprString the expression String to evaluate |
||||
* @param evalContext the context to evaluate the expression within |
||||
* @return the evaluation result |
||||
*/ |
||||
protected abstract Object evaluateExpression(String exprString, BeanExpressionContext evalContext); |
||||
|
||||
} |
||||
@ -1,57 +0,0 @@
@@ -1,57 +0,0 @@
|
||||
package org.springframework.expression; |
||||
|
||||
/** |
||||
* A CacheablePropertyAccessor is an optimized PropertyAccessor where the two parts of accessing the property are |
||||
* separated: (1) resolving the property and (2) retrieving its value. In some cases there is a large cost to |
||||
* discovering which property an expression refers to and once discovered it will always resolve to the same property. |
||||
* In these situations a CacheablePropertyAccessor enables the resolution to be done once and a reusable object (an |
||||
* executor) returned that can be called over and over to retrieve the property value without going through resolution |
||||
* again. |
||||
* <p> |
||||
* |
||||
* @author Andy Clement |
||||
*/ |
||||
public abstract class CacheablePropertyAccessor implements PropertyAccessor { |
||||
|
||||
/** |
||||
* Attempt to resolve the named property and return an executor that can be called to get the value of that |
||||
* property. Return null if the property cannot be resolved. |
||||
* |
||||
* @param context the evaluation context |
||||
* @param target the target upon which the property is being accessed |
||||
* @param name the name of the property being accessed |
||||
* @return a reusable executor that can retrieve the property value |
||||
*/ |
||||
public abstract PropertyReaderExecutor getReaderAccessor(EvaluationContext context, Object target, Object name); |
||||
|
||||
/** |
||||
* Attempt to resolve the named property and return an executor that can be called to set the value of that |
||||
* property. Return null if the property cannot be resolved. |
||||
* |
||||
* @param context the evaluation context |
||||
* @param target the target upon which the property is being accessed |
||||
* @param name the name of the property to be set |
||||
* @return a reusable executor that can set the property value |
||||
*/ |
||||
public abstract PropertyWriterExecutor getWriterAccessor(EvaluationContext context, Object target, Object name); |
||||
|
||||
// Implementation of PropertyAccessor follows, based on the resolver/executor model
|
||||
|
||||
public final boolean canRead(EvaluationContext context, Object target, Object name) throws AccessException { |
||||
return getReaderAccessor(context, target, name) != null; |
||||
} |
||||
|
||||
public final boolean canWrite(EvaluationContext context, Object target, Object name) throws AccessException { |
||||
return getWriterAccessor(context, target, name) != null; |
||||
} |
||||
|
||||
public final Object read(EvaluationContext context, Object target, Object name) throws AccessException { |
||||
return getReaderAccessor(context, target, name).execute(context, target); |
||||
} |
||||
|
||||
public final void write(EvaluationContext context, Object target, Object name, Object newValue) |
||||
throws AccessException { |
||||
getWriterAccessor(context, target, name).execute(context, target, newValue); |
||||
} |
||||
|
||||
} |
||||
@ -1,56 +1,56 @@
@@ -1,56 +1,56 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Copyright 2002-2009 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression; |
||||
|
||||
/** |
||||
* Parses expression strings into compiled expressions that can be evaluated. Supports parsing templates as well as |
||||
* standard expression strings. |
||||
* |
||||
* Parses expression strings into compiled expressions that can be evaluated. |
||||
* Supports parsing templates as well as standard expression strings. |
||||
* |
||||
* @author Keith Donald |
||||
* @author Andy Clement |
||||
* @since 3.0 |
||||
*/ |
||||
public interface ExpressionParser { |
||||
|
||||
/** |
||||
* Parse the expression string and return an Expression object you can use for repeated evaluation. Some examples: |
||||
* |
||||
* Parse the expression string and return an Expression object you can use for repeated evaluation. |
||||
* <p>Some examples: |
||||
* <pre> |
||||
* 3 + 4 |
||||
* name.firstName |
||||
* </pre> |
||||
* |
||||
* @param expressionString the raw expression string to parse |
||||
* @param context a context for influencing this expression parsing routine (optional) |
||||
* @return an evaluator for the parsed expression |
||||
* @throws ParseException an exception occurred during parsing |
||||
*/ |
||||
public Expression parseExpression(String expressionString, ParserContext context) throws ParseException; |
||||
Expression parseExpression(String expressionString) throws ParseException; |
||||
|
||||
/** |
||||
* Parse the expression string and return an Expression object you can use for repeated evaluation. Some examples: |
||||
* |
||||
* Parse the expression string and return an Expression object you can use for repeated evaluation. |
||||
* <p>Some examples: |
||||
* <pre> |
||||
* 3 + 4 |
||||
* name.firstName |
||||
* </pre> |
||||
* |
||||
* @param expressionString the raw expression string to parse |
||||
* @param context a context for influencing this expression parsing routine (optional) |
||||
* @return an evaluator for the parsed expression |
||||
* @throws ParseException an exception occurred during parsing |
||||
*/ |
||||
public Expression parseExpression(String expressionString) throws ParseException; |
||||
Expression parseExpression(String expressionString, ParserContext context) throws ParseException; |
||||
|
||||
} |
||||
} |
||||
|
||||
@ -1,40 +0,0 @@
@@ -1,40 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression; |
||||
|
||||
/** |
||||
* If a property accessor is built upon the CacheablePropertyAccessor class then once the property |
||||
* has been resolved the accessor will return an instance of this PropertyReaderExecutor interface
|
||||
* that can be cached and repeatedly called to access the value of the property. |
||||
* <p> |
||||
* They can become stale, and in that case should throw an AccessException - this will cause the |
||||
* infrastructure to go back to the resolvers to ask for a new one. |
||||
* |
||||
* @author Andy Clement |
||||
*/ |
||||
public interface PropertyReaderExecutor { |
||||
|
||||
/** |
||||
* Return the value of a property for the specified target. |
||||
* |
||||
* @param context the evaluation context in which the command is being executed |
||||
* @param targetObject the target object on which property access is being attempted |
||||
* @return the property value |
||||
* @throws AccessException if there is a problem accessing the property or this executor has become stale |
||||
*/ |
||||
Object execute(EvaluationContext context, Object targetObject) throws AccessException; |
||||
|
||||
} |
||||
@ -1,40 +0,0 @@
@@ -1,40 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression; |
||||
|
||||
/** |
||||
* If a property accessor is built upon the CacheablePropertyAccessor class then once the property |
||||
* has been resolved the accessor will return an instance of this PropertyWriterExecutor interface
|
||||
* that can be cached and repeatedly called to set the value of the property. |
||||
* |
||||
* <p>They can become stale, and in that case should throw an AccessException - this will cause the |
||||
* infrastructure to go back to the resolvers to ask for a new one. |
||||
* |
||||
* @author Andy Clement |
||||
*/ |
||||
public interface PropertyWriterExecutor { |
||||
|
||||
/** |
||||
* Set the value of a property to the supplied new value. |
||||
* @param context the evaluation context in which the command is being executed |
||||
* @param targetObject the target object on which property write is being attempted |
||||
* @param newValue the new value for the property |
||||
* @throws AccessException if there is a problem setting the property or this executor has become stale |
||||
*/ |
||||
void execute(EvaluationContext context, Object targetObject, Object newValue) throws AccessException; |
||||
|
||||
} |
||||
@ -1,54 +0,0 @@
@@ -1,54 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression; |
||||
|
||||
/** |
||||
* TypeUtilities brings together the various kinds of type related function that may occur |
||||
* whilst working with expressions. An implementor is providing support for four type related |
||||
* facilities: |
||||
* <ul> |
||||
* <li>a mechanism for finding types |
||||
* <li>a mechanism for comparing types |
||||
* <li>a mechanism for type conversion/coercion |
||||
* <li>a mechanism for overloading mathematical operations (add/subtract/etc) |
||||
* </ul> |
||||
* |
||||
* @author Andy Clement |
||||
*/ |
||||
public interface TypeUtils { |
||||
|
||||
/** |
||||
* @return a type locator that can be used to find types, either by short or fully qualified name. |
||||
*/ |
||||
TypeLocator getTypeLocator(); |
||||
|
||||
/** |
||||
* @return a type comparator for comparing pairs of objects for equality. |
||||
*/ |
||||
TypeComparator getTypeComparator(); |
||||
|
||||
/** |
||||
* @return a type converter that can convert (or coerce) a value from one type to another. |
||||
*/ |
||||
TypeConverter getTypeConverter(); |
||||
|
||||
/** |
||||
* @return an operator overloader that may support mathematical operations between more than the standard set of |
||||
* types |
||||
*/ |
||||
OperatorOverloader getOperatorOverloader(); |
||||
|
||||
} |
||||
@ -1,78 +1,99 @@
@@ -1,78 +1,99 @@
|
||||
/* |
||||
* Copyright 2002-2009 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression.common; |
||||
|
||||
import org.springframework.expression.EvaluationContext; |
||||
import org.springframework.expression.EvaluationException; |
||||
import org.springframework.expression.Expression; |
||||
import org.springframework.util.ObjectUtils; |
||||
|
||||
/** |
||||
* Represents a template expression broken into pieces. Each piece will be an Expression but pure text parts to the |
||||
* template will be represented as LiteralExpression objects. An example of a template expression might be: <code><pre> |
||||
* "Hello ${getName()}" |
||||
* </pre></code> which will be represented as a CompositeStringExpression of two parts. The first part being a |
||||
* LiteralExpression representing 'Hello ' and the second part being a real expression that will call getName() when |
||||
* invoked. |
||||
* template will be represented as LiteralExpression objects. An example of a template expression might be: |
||||
* |
||||
* <pre class="code"> |
||||
* "Hello ${getName()}"</pre> |
||||
* |
||||
* which will be represented as a CompositeStringExpression of two parts. The first part being a |
||||
* LiteralExpression representing 'Hello ' and the second part being a real expression that will |
||||
* call <code>getName()</code> when invoked. |
||||
* |
||||
* @author Andy Clement |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public class CompositeStringExpression implements Expression { |
||||
|
||||
private final String expressionString; |
||||
|
||||
/** |
||||
* The array of expressions that make up the composite expression |
||||
*/ |
||||
/** The array of expressions that make up the composite expression */ |
||||
private final Expression[] expressions; |
||||
|
||||
|
||||
public CompositeStringExpression(String expressionString, Expression[] expressions) { |
||||
this.expressionString = expressionString; |
||||
this.expressions = expressions; |
||||
} |
||||
|
||||
public String getExpressionString() { |
||||
return expressionString; |
||||
|
||||
public final String getExpressionString() { |
||||
return this.expressionString; |
||||
} |
||||
|
||||
public String getValue() throws EvaluationException { |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0; i < expressions.length; i++) { |
||||
// TODO is stringify ok for the non literal components? or should the converters be used? see another
|
||||
// case below
|
||||
sb.append(expressions[i].getValue()); |
||||
for (Expression expression : this.expressions) { |
||||
sb.append(ObjectUtils.getDisplayString(expression.getValue())); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
public String getValue(EvaluationContext context) throws EvaluationException { |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0; i < expressions.length; i++) { |
||||
sb.append(expressions[i].getValue(context)); |
||||
for (Expression expression : this.expressions) { |
||||
sb.append(ObjectUtils.getDisplayString(expression.getValue(context))); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
public Class getValueType(EvaluationContext context) throws EvaluationException { |
||||
public Class getValueType(EvaluationContext context) { |
||||
return String.class; |
||||
} |
||||
|
||||
public Class getValueType() throws EvaluationException { |
||||
public Class getValueType() { |
||||
return String.class; |
||||
} |
||||
|
||||
public void setValue(EvaluationContext context, Object value) throws EvaluationException { |
||||
throw new EvaluationException(expressionString, "Cannot call setValue() on a composite expression"); |
||||
throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression"); |
||||
} |
||||
|
||||
public <T> T getValue(EvaluationContext context, Class<T> expectedResultType) throws EvaluationException { |
||||
Object value = getValue(context); |
||||
return (T)ExpressionUtils.convert(context, value, expectedResultType); |
||||
return ExpressionUtils.convert(context, value, expectedResultType); |
||||
} |
||||
|
||||
public <T> T getValue(Class<T> expectedResultType) throws EvaluationException { |
||||
Object value = getValue(); |
||||
return (T)ExpressionUtils.convert(null, value, expectedResultType); |
||||
return ExpressionUtils.convert(null, value, expectedResultType); |
||||
} |
||||
|
||||
public boolean isWritable(EvaluationContext context) throws EvaluationException { |
||||
public boolean isWritable(EvaluationContext context) { |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
|
||||
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
package org.springframework.expression.common; |
||||
|
||||
import org.springframework.expression.ParserContext; |
||||
|
||||
public class DefaultNonTemplateParserContext implements ParserContext { |
||||
|
||||
public static final DefaultNonTemplateParserContext INSTANCE = new DefaultNonTemplateParserContext(); |
||||
|
||||
private DefaultNonTemplateParserContext() { |
||||
} |
||||
|
||||
public String getExpressionPrefix() { |
||||
return null; |
||||
} |
||||
|
||||
public String getExpressionSuffix() { |
||||
return null; |
||||
} |
||||
|
||||
public boolean isTemplate() { |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
package org.springframework.expression.common; |
||||
|
||||
import org.springframework.expression.ParserContext; |
||||
|
||||
public class DefaultTemplateParserContext implements ParserContext { |
||||
|
||||
public static final DefaultTemplateParserContext INSTANCE = new DefaultTemplateParserContext(); |
||||
|
||||
private DefaultTemplateParserContext() { |
||||
} |
||||
|
||||
public String getExpressionPrefix() { |
||||
return "${"; |
||||
} |
||||
|
||||
public String getExpressionSuffix() { |
||||
return "}"; |
||||
} |
||||
|
||||
public boolean isTemplate() { |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
/* |
||||
* Copyright 2002-2009 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression.common; |
||||
|
||||
import org.springframework.expression.ParserContext; |
||||
|
||||
/** |
||||
* Configurable {@link ParserContext} implementation for template parsing. |
||||
* Expects the expression prefix and suffix as constructor arguments. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public class TemplateParserContext implements ParserContext { |
||||
|
||||
private final String expressionPrefix; |
||||
|
||||
private final String expressionSuffix; |
||||
|
||||
|
||||
/** |
||||
* Create a new TemplateParserContext for the given prefix and suffix. |
||||
* @param expressionPrefix the expression prefix to use |
||||
* @param expressionSuffix the expression suffix to use |
||||
*/ |
||||
public TemplateParserContext(String expressionPrefix, String expressionSuffix) { |
||||
this.expressionPrefix = expressionPrefix; |
||||
this.expressionSuffix = expressionSuffix; |
||||
} |
||||
|
||||
|
||||
public final boolean isTemplate() { |
||||
return true; |
||||
} |
||||
|
||||
public final String getExpressionPrefix() { |
||||
return this.expressionPrefix; |
||||
} |
||||
|
||||
public final String getExpressionSuffix() { |
||||
return this.expressionSuffix; |
||||
} |
||||
|
||||
} |
||||
@ -1,65 +0,0 @@
@@ -1,65 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression.spel; |
||||
|
||||
import org.springframework.expression.Expression; |
||||
import org.springframework.expression.ParseException; |
||||
import org.springframework.expression.ParserContext; |
||||
import org.springframework.expression.common.DefaultNonTemplateParserContext; |
||||
import org.springframework.expression.common.TemplateAwareExpressionParser; |
||||
import org.springframework.expression.spel.antlr.SpelAntlrExpressionParser; |
||||
|
||||
/** |
||||
* Instances of this parser class can process Spring Expression Language format expressions. The result of parsing an |
||||
* expression is a SpelExpression instance that can be repeatedly evaluated (possibly against different evaluation |
||||
* contexts) or serialized for later evaluation. |
||||
* |
||||
* @author Andy Clement |
||||
*/ |
||||
public class SpelExpressionParser extends TemplateAwareExpressionParser { |
||||
|
||||
private final SpelInternalParser expressionParser; |
||||
|
||||
public SpelExpressionParser() { |
||||
// Use an Antlr based expression parser
|
||||
expressionParser = new SpelAntlrExpressionParser(); |
||||
} |
||||
|
||||
/** |
||||
* Parse an expression string. |
||||
* |
||||
* @param expressionString the expression to parse |
||||
* @param context the parser context in which to perform the parse |
||||
* @return a parsed expression object |
||||
* @throws ParseException if the expression is invalid |
||||
*/ |
||||
@Override |
||||
protected Expression doParseExpression(String expressionString, ParserContext context) throws ParseException { |
||||
return expressionParser.doParseExpression(expressionString,context); |
||||
} |
||||
|
||||
/** |
||||
* Simple override with covariance to return a nicer type |
||||
*/ |
||||
@Override |
||||
public SpelExpression parseExpression(String expressionString) throws ParseException { |
||||
return (SpelExpression) super.parseExpression(expressionString, DefaultNonTemplateParserContext.INSTANCE); |
||||
} |
||||
|
||||
public interface SpelInternalParser { |
||||
Expression doParseExpression(String expressionString, ParserContext context) throws ParseException; |
||||
} |
||||
} |
||||
@ -1,35 +0,0 @@
@@ -1,35 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression.spel.internal; |
||||
|
||||
import org.springframework.expression.spel.SpelException; |
||||
|
||||
/** |
||||
* Wraps an ELException and can pass up through Antlr since it is unchecked, where it can then be unwrapped. |
||||
* |
||||
* @author Andy Clement |
||||
*/ |
||||
public class WrappedExpressionException extends RuntimeException { |
||||
|
||||
WrappedExpressionException(SpelException e) { |
||||
super(e); |
||||
} |
||||
|
||||
@Override |
||||
public SpelException getCause() { |
||||
return (SpelException) super.getCause(); |
||||
} |
||||
} |
||||
@ -1,74 +0,0 @@
@@ -1,74 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression.spel.reflection; |
||||
|
||||
import java.lang.reflect.Constructor; |
||||
import java.lang.reflect.InvocationTargetException; |
||||
|
||||
import org.springframework.expression.AccessException; |
||||
import org.springframework.expression.ConstructorExecutor; |
||||
import org.springframework.expression.EvaluationContext; |
||||
import org.springframework.expression.EvaluationException; |
||||
|
||||
/** |
||||
* A simple CommandExecutor implementation that runs a constructor using reflective invocation. |
||||
* |
||||
* @author Andy Clement |
||||
*/ |
||||
public class ReflectionConstructorExecutor implements ConstructorExecutor { |
||||
|
||||
private final Constructor<?> c; |
||||
|
||||
// When the constructor was found, we will have determined if arguments need to be converted for it
|
||||
// to be invoked. Conversion won't be cheap so let's only do it if necessary.
|
||||
private final Integer[] argsRequiringConversion; |
||||
|
||||
public ReflectionConstructorExecutor(Constructor<?> constructor, Integer[] argsRequiringConversion) { |
||||
c = constructor; |
||||
this.argsRequiringConversion = argsRequiringConversion; |
||||
} |
||||
|
||||
/** |
||||
* Invoke a constructor via reflection. |
||||
*/ |
||||
public Object execute(EvaluationContext context, Object... arguments) throws AccessException { |
||||
if (argsRequiringConversion != null && arguments != null) { |
||||
try { |
||||
ReflectionUtils.convertArguments(c.getParameterTypes(), c.isVarArgs(), context.getTypeUtils() |
||||
.getTypeConverter(), argsRequiringConversion, arguments); |
||||
} catch (EvaluationException ex) { |
||||
throw new AccessException("Problem invoking constructor on '" + c + "': " + ex.getMessage(), ex); |
||||
} |
||||
} |
||||
if (c.isVarArgs()) { |
||||
arguments = ReflectionUtils.setupArgumentsForVarargsInvocation(c.getParameterTypes(), arguments); |
||||
} |
||||
try { |
||||
if (!c.isAccessible()) { |
||||
c.setAccessible(true); |
||||
} |
||||
return c.newInstance(arguments); |
||||
} catch (IllegalArgumentException e) { |
||||
throw new AccessException("Problem invoking constructor on '" + c + "' : " + e.getMessage(), e); |
||||
} catch (InstantiationException e) { |
||||
throw new AccessException("Problem invoking constructor on '" + c + "' : " + e.getMessage(), e); |
||||
} catch (IllegalAccessException e) { |
||||
throw new AccessException("Problem invoking constructor on '" + c + "' : " + e.getMessage(), e); |
||||
} catch (InvocationTargetException e) { |
||||
throw new AccessException("Problem invoking constructor on '" + c + "' : " + e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
||||
@ -1,66 +0,0 @@
@@ -1,66 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression.spel.reflection; |
||||
|
||||
import org.springframework.expression.AccessException; |
||||
import org.springframework.expression.ConstructorExecutor; |
||||
import org.springframework.expression.ConstructorResolver; |
||||
import org.springframework.expression.EvaluationContext; |
||||
import org.springframework.expression.EvaluationException; |
||||
import org.springframework.expression.spel.reflection.ReflectionUtils.DiscoveredConstructor; |
||||
|
||||
/** |
||||
* A constructor resolver that uses reflection to locate the constructor that should be invoked |
||||
* |
||||
* @author Andy Clement |
||||
*/ |
||||
public class ReflectionConstructorResolver implements ConstructorResolver { |
||||
|
||||
/* |
||||
* Indicates if this resolve will allow matches to be found that require some of the input arguments to be |
||||
* transformed by the conversion service. |
||||
*/ |
||||
private boolean allowMatchesRequiringArgumentConversion = true; |
||||
|
||||
public ReflectionConstructorResolver() { |
||||
} |
||||
|
||||
public ReflectionConstructorResolver(boolean allowMatchesRequiringArgumentConversion) { |
||||
this.allowMatchesRequiringArgumentConversion = allowMatchesRequiringArgumentConversion; |
||||
} |
||||
|
||||
public void setAllowMatchRequiringArgumentConversion(boolean allow) { |
||||
this.allowMatchesRequiringArgumentConversion = allow; |
||||
} |
||||
|
||||
/** |
||||
* Locate a matching constructor or return null if non can be found. |
||||
*/ |
||||
public ConstructorExecutor resolve(EvaluationContext context, String typename, Class<?>[] argumentTypes) |
||||
throws AccessException { |
||||
try { |
||||
Class<?> c = context.getTypeUtils().getTypeLocator().findType(typename); |
||||
DiscoveredConstructor dCtor = ReflectionUtils.findConstructor(context.getTypeUtils().getTypeConverter(), c, |
||||
argumentTypes, allowMatchesRequiringArgumentConversion); |
||||
if (dCtor == null) { |
||||
return null; |
||||
} |
||||
return new ReflectionConstructorExecutor(dCtor.theConstructor, dCtor.argumentsRequiringConversion); |
||||
} catch (EvaluationException e) { |
||||
throw new AccessException(null,e); |
||||
} |
||||
} |
||||
} |
||||
@ -1,70 +0,0 @@
@@ -1,70 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression.spel.reflection; |
||||
|
||||
import java.lang.reflect.InvocationTargetException; |
||||
import java.lang.reflect.Method; |
||||
|
||||
import org.springframework.expression.AccessException; |
||||
import org.springframework.expression.EvaluationContext; |
||||
import org.springframework.expression.EvaluationException; |
||||
import org.springframework.expression.MethodExecutor; |
||||
|
||||
public class ReflectionMethodExecutor implements MethodExecutor { |
||||
|
||||
private final Method m; |
||||
|
||||
// When the method was found, we will have determined if arguments need to be converted for it
|
||||
// to be invoked. Conversion won't be cheap so let's only do it if necessary.
|
||||
private final Integer[] argsRequiringConversion; |
||||
|
||||
public ReflectionMethodExecutor(Method theMethod, Integer[] argumentsRequiringConversion) { |
||||
m = theMethod; |
||||
argsRequiringConversion = argumentsRequiringConversion; |
||||
} |
||||
|
||||
public Object execute(EvaluationContext context, Object target, Object... arguments) throws AccessException { |
||||
if (argsRequiringConversion != null && arguments != null) { |
||||
try { |
||||
ReflectionUtils.convertArguments(m.getParameterTypes(), m.isVarArgs(), context.getTypeUtils() |
||||
.getTypeConverter(), argsRequiringConversion, arguments); |
||||
} catch (EvaluationException ex) { |
||||
throw new AccessException("Problem invoking method '" + m.getName() + "' on '" + target.getClass() |
||||
+ "': " + ex.getMessage(), ex); |
||||
} |
||||
} |
||||
if (m.isVarArgs()) { |
||||
arguments = ReflectionUtils.setupArgumentsForVarargsInvocation(m.getParameterTypes(), arguments); |
||||
} |
||||
try { |
||||
if (!m.isAccessible()) { |
||||
m.setAccessible(true); |
||||
} |
||||
return m.invoke(target, arguments); |
||||
} catch (IllegalArgumentException e) { |
||||
throw new AccessException("Problem invoking method '" + m.getName() + "' on '" + target.getClass() + "': " |
||||
+ e.getMessage(), e); |
||||
} catch (IllegalAccessException e) { |
||||
throw new AccessException("Problem invoking method '" + m.getName() + "' on '" + target.getClass() + "': " |
||||
+ e.getMessage(), e); |
||||
} catch (InvocationTargetException e) { |
||||
e.getCause().printStackTrace(); |
||||
throw new AccessException("Problem invoking method '" + m.getName() + "' on '" + target.getClass() + "': " |
||||
+ e.getMessage(), e); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -1,63 +0,0 @@
@@ -1,63 +0,0 @@
|
||||
/* |
||||
* Copyright 2004-2008 the original author or authors. |
||||
* |
||||
* Licensed 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.springframework.expression.spel.reflection; |
||||
|
||||
import org.springframework.expression.AccessException; |
||||
import org.springframework.expression.EvaluationContext; |
||||
import org.springframework.expression.EvaluationException; |
||||
import org.springframework.expression.MethodExecutor; |
||||
import org.springframework.expression.MethodResolver; |
||||
import org.springframework.expression.spel.reflection.ReflectionUtils.DiscoveredMethod; |
||||
|
||||
/** |
||||
* A method resolver that uses reflection to locate the method that should be invoked |
||||
* |
||||
* @author Andy Clement |
||||
*/ |
||||
public class ReflectionMethodResolver implements MethodResolver { |
||||
|
||||
/* |
||||
* Indicates if this resolve will allow matches to be found that require some of the input arguments to be |
||||
* transformed by the conversion service. |
||||
*/ |
||||
private boolean allowMatchesRequiringArgumentConversion = true; |
||||
|
||||
public ReflectionMethodResolver() { |
||||
} |
||||
|
||||
public ReflectionMethodResolver(boolean allowMatchesRequiringArgumentConversion) { |
||||
this.allowMatchesRequiringArgumentConversion = allowMatchesRequiringArgumentConversion; |
||||
} |
||||
|
||||
public void setAllowMatchRequiringArgumentConversion(boolean allow) { |
||||
this.allowMatchesRequiringArgumentConversion = allow; |
||||
} |
||||
|
||||
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, Class<?>[] argumentTypes) throws AccessException { |
||||
try { |
||||
Class<?> relevantClass = (targetObject instanceof Class ? (Class<?>) targetObject : targetObject.getClass()); |
||||
DiscoveredMethod dMethod = ReflectionUtils.findMethod(context.getTypeUtils().getTypeConverter(), name, |
||||
argumentTypes, relevantClass, allowMatchesRequiringArgumentConversion); |
||||
if (dMethod == null) { |
||||
return null; |
||||
} |
||||
return new ReflectionMethodExecutor(dMethod.theMethod, dMethod.argumentsRequiringConversion); |
||||
} catch (EvaluationException e) { |
||||
throw new AccessException(null,e); |
||||
} |
||||
} |
||||
|
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue