Initial code checkin
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 capable of evaluating itself against context objects. Encapsulates the details of a previously parsed
|
||||
* expression string. Provides a common abstraction for expression evaluation independent of any language like OGNL or
|
||||
* the Unified EL.
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public interface Expression {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Set this expression in the provided context to the value provided.
|
||||
* @param context the context on which the new value should be set
|
||||
* @param value the new value to set
|
||||
* @throws EvaluationException an exception occurred during expression evaluation
|
||||
*/
|
||||
public void setValue(Object context, Object value) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Returns the most general type that can be passed to the {@link #setValue(Object, 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;
|
||||
|
||||
/**
|
||||
* Returns the original string used to create this expression, unmodified.
|
||||
* @return the original expression string
|
||||
*/
|
||||
public String getExpressionString();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Parses expression strings into compiled expressions that can be evaluated. Supports parsing templates as well as
|
||||
* standard expression strings.
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public interface ExpressionParser {
|
||||
|
||||
/**
|
||||
* Parse the expression string and return a compiled Expression object you can use for evaluation. 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 ParserException an exception occurred during parsing
|
||||
*/
|
||||
public Expression parseExpression(String expressionString, ParserContext context) throws ParserException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Input provided to an expression parser that can influence an expression parsing/compilation routine.
|
||||
* @author Keith Donald
|
||||
*/
|
||||
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:
|
||||
*
|
||||
* <pre>
|
||||
* Some literal text
|
||||
* Hello #{name.firstName}!
|
||||
* #{3 + 4}
|
||||
* </pre>
|
||||
*
|
||||
* @return true if the expression is a template, false otherwise
|
||||
*/
|
||||
public boolean isTemplate();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
<p>
|
||||
Core expression language abstraction for parsing and evaluating expressions.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
<p>
|
||||
The Spring Data Binding framework, an internal library used by Spring Web Flow.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
28
org.springframework.expression/src/test/resources/log4j.xml
Normal file
28
org.springframework.expression/src/test/resources/log4j.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<!-- Appenders -->
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework.beans">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.binding">
|
||||
<level value="debug" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
Reference in New Issue
Block a user