diff --git a/org.springframework.expression/.classpath b/org.springframework.expression/.classpath index 4ccd1929d7a..600f003c05c 100644 --- a/org.springframework.expression/.classpath +++ b/org.springframework.expression/.classpath @@ -9,12 +9,11 @@ - - + diff --git a/org.springframework.expression/.settings/org.eclipse.jdt.core.prefs b/org.springframework.expression/.settings/org.eclipse.jdt.core.prefs index 56da8f0547c..21a360446cb 100644 --- a/org.springframework.expression/.settings/org.eclipse.jdt.core.prefs +++ b/org.springframework.expression/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#Thu Jul 10 09:39:34 BST 2008 +#Tue Jul 15 16:39:56 PDT 2008 eclipse.preferences.version=1 org.eclipse.jdt.core.codeComplete.argumentPrefixes= org.eclipse.jdt.core.codeComplete.argumentSuffixes= @@ -9,22 +9,22 @@ org.eclipse.jdt.core.codeComplete.localSuffixes= org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.doc.comment.support=enabled org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.deprecation=warning org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning @@ -79,7 +79,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 +org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 diff --git a/org.springframework.expression/.settings/org.eclipse.jdt.ui.prefs b/org.springframework.expression/.settings/org.eclipse.jdt.ui.prefs index 193deb8d6d9..9a9ff8d69bd 100644 --- a/org.springframework.expression/.settings/org.eclipse.jdt.ui.prefs +++ b/org.springframework.expression/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,4 @@ -#Wed Jun 25 10:24:03 EDT 2008 +#Tue Aug 05 13:11:35 PDT 2008 eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_Spring Java Conventions @@ -21,7 +21,7 @@ sp_cleanup.always_use_parentheses_in_expressions=false sp_cleanup.always_use_this_for_non_static_field_access=false sp_cleanup.always_use_this_for_non_static_method_access=false sp_cleanup.convert_to_enhanced_for_loop=false -sp_cleanup.format_source_code=true +sp_cleanup.format_source_code=false sp_cleanup.make_local_variable_final=false sp_cleanup.make_parameters_final=false sp_cleanup.make_private_fields_final=true diff --git a/org.springframework.expression/ivy.xml b/org.springframework.expression/ivy.xml index ca334310548..e6c53a29f6d 100644 --- a/org.springframework.expression/ivy.xml +++ b/org.springframework.expression/ivy.xml @@ -22,6 +22,8 @@ + + @@ -29,4 +31,4 @@ - \ No newline at end of file + diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/EvaluationException.java b/org.springframework.expression/src/main/java/org/springframework/expression/EvaluationException.java deleted file mode 100644 index 65ca8613eac..00000000000 --- a/org.springframework.expression/src/main/java/org/springframework/expression/EvaluationException.java +++ /dev/null @@ -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.binding.expression; - -/** - * Indicates an expression evaluation failed. - * - * @author Keith Donald - */ -public class EvaluationException extends RuntimeException { - - private Class contextClass; - - private String expressionString; - - /** - * Creates a new evaluation exception. - * @param contextClass the class of object upon which evaluation was attempted - * @param expressionString the string form of the expression that failed to evaluate - * @param message the exception message - */ - public EvaluationException(Class contextClass, String expressionString, String message) { - this(contextClass, expressionString, message, null); - } - - /** - * Creates a new evaluation exception. - * @param contextClass the class of object upon which evaluation was attempted - * @param expressionString the string form of the expression that failed to evaluate - * @param message the exception message - * @param cause the underlying cause of this evaluation exception - */ - public EvaluationException(Class contextClass, String expressionString, String message, Throwable cause) { - super(message, cause); - } - - /** - * The class of object upon which evaluation was attempted and failed. - * @return the context class - */ - public Class getContextClass() { - return contextClass; - } - - /** - * The string form of the expression that failed to evaluate against an instance of the the context class. - * @return the expression string - */ - public String getExpressionString() { - return expressionString; - } - -} \ No newline at end of file diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/Expression.java b/org.springframework.expression/src/main/java/org/springframework/expression/Expression.java index b044271b23b..049e53954ff 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/Expression.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/Expression.java @@ -13,7 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.binding.expression; +package org.springframework.expression; + +import org.springframework.expression.spel.SpelException; + /** * An expression capable of evaluating itself against context objects. Encapsulates the details of a previously parsed @@ -21,16 +24,47 @@ package org.springframework.binding.expression; * the Unified EL. * * @author Keith Donald + * @author Andy Clement */ public interface Expression { + /** + * Evaluate this expression in the default standard context. + * @return the evaluation result + * @throws EvaluationException an exception occurred during expression evaluation + */ + public Object getValue() throws EvaluationException; + + /** + * Evaluate the expression in the default standard context. If the result of the evaluation + * does not match (and cannot be converted to) the expected result type then an + * exception will be returned. + * + * @param expectedResultType the class the caller would like the result to be + * @return the value of the expression + * @throws EvaluationException if there is a problem with evaluation of the expression. + */ + public Object getValue(Class expectedResultType) throws EvaluationException; + /** * Evaluate this expression in the provided context and return the result of evaluation. * @param context the context to evaluate this expression in * @return the evaluation result * @throws EvaluationException an exception occurred during expression evaluation */ - public Object getValue(Object context) throws EvaluationException; + public Object getValue(EvaluationContext context) throws EvaluationException; + + /** + * Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc - + * the type of the evaluation result is expected to be of a particular class and an exception will be thrown if it + * is not and cannot be converted to that type. + * + * @param context the context in which to evaluate the expression + * @param expectedResultType the class the caller would like the result to be + * @return the value of the expression + * @throws SpelException if there is a problem with evaluation of the expression. + */ + public Object getValue(EvaluationContext context, Class expectedResultType) throws EvaluationException; /** * Set this expression in the provided context to the value provided. @@ -38,16 +72,16 @@ public interface Expression { * @param value the new value to set * @throws EvaluationException an exception occurred during expression evaluation */ - public void setValue(Object context, Object value) throws EvaluationException; + public void setValue(EvaluationContext context, Object value) throws EvaluationException; /** - * Returns the most general type that can be passed to the {@link #setValue(Object, Object)} method for the given + * Returns the most general type that can be passed to the {@link #setValue(EvaluationContext, Object)} method for the given * context. * @param context the context to evaluate * @return the most general type of value that can be set on this context * @throws EvaluationException an exception occurred during expression evaluation */ - public Class getValueType(Object context) throws EvaluationException; + public Class getValueType(EvaluationContext context) throws EvaluationException; /** * Returns the original string used to create this expression, unmodified. @@ -55,4 +89,5 @@ public interface Expression { */ public String getExpressionString(); + } \ No newline at end of file diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/ExpressionParser.java b/org.springframework.expression/src/main/java/org/springframework/expression/ExpressionParser.java index 03831d9c6fa..2b6cfc66954 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/ExpressionParser.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/ExpressionParser.java @@ -13,18 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.binding.expression; +package org.springframework.expression; /** * 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 */ public interface ExpressionParser { /** - * Parse the expression string and return a compiled Expression object you can use for evaluation. Some examples: + * Parse the expression string and return an Expression object you can use for repeated evaluation. Some examples: * *
 	 *     3 + 4
@@ -34,8 +35,22 @@ public interface ExpressionParser {
 	 * @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 ParserException an exception occurred during parsing
+	 * @throws ParseException an exception occurred during parsing
 	 */
-	public Expression parseExpression(String expressionString, ParserContext context) throws ParserException;
+	public Expression parseExpression(String expressionString, ParserContext context) throws ParseException;
+
+	/**
+	 * Parse the expression string and return an Expression object you can use for repeated evaluation. Some examples:
+	 * 
+	 * 
+	 *     3 + 4
+	 *     name.firstName
+	 * 
+ * + * @param expressionString the raw expression string to parse + * @return an evaluator for the parsed expression + * @throws ParseException an exception occurred during parsing + */ + public Expression parseExpression(String expressionString) throws ParseException; } \ No newline at end of file diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/ExpressionVariable.java b/org.springframework.expression/src/main/java/org/springframework/expression/ExpressionVariable.java deleted file mode 100644 index fc92310bff4..00000000000 --- a/org.springframework.expression/src/main/java/org/springframework/expression/ExpressionVariable.java +++ /dev/null @@ -1,95 +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.binding.expression; - -/** - * An expression variable. - * @author Keith Donald - */ -public class ExpressionVariable { - - private String name; - - private String valueExpression; - - private ParserContext parserContext; - - /** - * Creates a new expression variable. - * @param name the name of the variable, acting as an convenient alias (required) - * @param valueExpression the value expression (required) - */ - public ExpressionVariable(String name, String valueExpression) { - init(name, valueExpression, null); - } - - /** - * Creates a new expression variable with a populated parser context. - * @param name the name of the variable, acting as an convenient alias (required) - * @param valueExpression the value expression (required) - * @param parserContext the parser context to use to parse the value expression (optional) - */ - public ExpressionVariable(String name, String valueExpression, ParserContext parserContext) { - init(name, valueExpression, parserContext); - } - - /** - * Returns the variable name. - * @return the variable name - */ - public String getName() { - return name; - } - - /** - * Returns the expression that will be evaluated when the variable is referenced by its name in another expression. - * @return the expression value. - */ - public String getValueExpression() { - return valueExpression; - } - - /** - * Returns the parser context to use to parse the variable's value expression. - * @return the value expression parser context - */ - public ParserContext getParserContext() { - return parserContext; - } - - public boolean equals(Object o) { - if (!(o instanceof ExpressionVariable)) { - return false; - } - ExpressionVariable var = (ExpressionVariable) o; - return name.equals(var.name); - } - - public int hashCode() { - return name.hashCode(); - } - - public String toString() { - return "[Expression Variable '" + name + "']"; - } - - private void init(String name, String valueExpression, ParserContext parserContext) { - this.name = name; - this.valueExpression = valueExpression; - this.parserContext = parserContext; - } - -} diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/ParserContext.java b/org.springframework.expression/src/main/java/org/springframework/expression/ParserContext.java index 3ea7b556e22..393dffc90c0 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/ParserContext.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/ParserContext.java @@ -13,46 +13,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.binding.expression; +package org.springframework.expression; /** * Input provided to an expression parser that can influence an expression parsing/compilation routine. + * * @author Keith Donald + * @author Andy Clement */ public interface ParserContext { - /** - * Returns the type of context object the parsed expression will evaluate in. An expression parser may use this - * value to install custom variable resolves for that particular type of context. - * @return the evaluation context type - */ - public Class getEvaluationContextType(); - - /** - * Returns the expected type of object returned from evaluating the parsed expression. An expression parser may use - * this value to coerce an raw evaluation result before it is returned. - * @return the expected evaluation result type - */ - public Class getExpectedEvaluationResultType(); - - /** - * Returns additional expression variables or aliases that can be referenced during expression evaluation. An - * expression parser will register these variables for reference during evaluation. - */ - public ExpressionVariable[] getExpressionVariables(); - /** * Whether or not the expression being parsed is a template. A template expression consists of literal text that can * be mixed with evaluatable blocks. Some examples: * *
 	 * 	   Some literal text
-	 *     Hello #{name.firstName}!
-	 *     #{3 + 4}
+	 *     Hello ${name.firstName}!
+	 *     ${3 + 4}
 	 * 
* * @return true if the expression is a template, false otherwise */ public boolean isTemplate(); + /** + * For template expressions, returns the prefix that identifies the start of an expression block within a string. + * For example "${" + * + * @return the prefix that identifies the start of an expression + */ + public String getExpressionPrefix(); + + /** + * For template expressions, return the prefix that identifies the end of an expression block within a string. For + * example "}$" + * + * @return the suffix that identifies the end of an expression + */ + public String getExpressionSuffix(); } \ No newline at end of file diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/ParserException.java b/org.springframework.expression/src/main/java/org/springframework/expression/ParserException.java deleted file mode 100644 index 2dcd85d05d4..00000000000 --- a/org.springframework.expression/src/main/java/org/springframework/expression/ParserException.java +++ /dev/null @@ -1,56 +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.binding.expression; - -/** - * Base class for exceptions thrown during expression parsing. - * - * @author Keith Donald - */ -public class ParserException extends RuntimeException { - - /** - * The expression string that could not be parsed. - */ - private String expressionString; - - /** - * Creates a new expression parsing exception. - * @param expressionString the expression string that could not be parsed - * @param cause the underlying cause of this exception - */ - public ParserException(String expressionString, Throwable cause) { - this(expressionString, "Unable to parse expression string '" + expressionString + "'", cause); - } - - /** - * Creates a new expression parsing exception. - * @param expressionString the expression string that could not be parsed - * @param message a descriptive message - * @param cause the underlying cause of this exception - */ - public ParserException(String expressionString, String message, Throwable cause) { - super(message, cause); - this.expressionString = expressionString; - } - - /** - * Returns the expression string that could not be parsed. - */ - public Object getExpressionString() { - return expressionString; - } -} \ No newline at end of file diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/PropertyNotFoundException.java b/org.springframework.expression/src/main/java/org/springframework/expression/PropertyNotFoundException.java deleted file mode 100644 index 5bc5b6a696a..00000000000 --- a/org.springframework.expression/src/main/java/org/springframework/expression/PropertyNotFoundException.java +++ /dev/null @@ -1,36 +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.binding.expression; - -/** - * An evaluation exception indicating a expression that references a property failed to evaluate because the property - * could not be found. - * @author Keith Donald - */ -public class PropertyNotFoundException extends EvaluationException { - - /** - * Creates a new property not found exception - * @param contextClass the class of object upon which property evaluation was attempted - * @param property the property that could not be found - * @param cause root cause of the failure - */ - public PropertyNotFoundException(Class contextClass, String property, Throwable cause) { - super(contextClass, property, "Property '" + property + "' not found on context of class [" - + contextClass.getName() + "]", cause); - } - -} diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/package.html b/org.springframework.expression/src/main/java/org/springframework/expression/package.html deleted file mode 100644 index 6c863f90171..00000000000 --- a/org.springframework.expression/src/main/java/org/springframework/expression/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - -

-Core expression language abstraction for parsing and evaluating expressions. -

- - \ No newline at end of file diff --git a/org.springframework.expression/src/main/java/overview.html b/org.springframework.expression/src/main/java/overview.html deleted file mode 100644 index 1eb7a2e8c19..00000000000 --- a/org.springframework.expression/src/main/java/overview.html +++ /dev/null @@ -1,7 +0,0 @@ - - -

-The Spring Data Binding framework, an internal library used by Spring Web Flow. -

- - \ No newline at end of file diff --git a/org.springframework.expression/template.mf b/org.springframework.expression/template.mf index e551c63f373..6c00acd95d3 100644 --- a/org.springframework.expression/template.mf +++ b/org.springframework.expression/template.mf @@ -5,3 +5,4 @@ Bundle-ManifestVersion: 2 Import-Template: org.springframework.core;version="[3.0.0, 3.0.1)", org.apache.commons.logging;version="[1.1.1, 2.0.0)", + org.antlr.runtime;version="[3.0.0,3.0.1)", org.antlr.runtime.tree;version="[3.0.0,3.0.1)" \ No newline at end of file