revised core conversion package for BeanWrapper/BeanFactory integration

This commit is contained in:
Juergen Hoeller
2009-08-09 00:52:41 +00:00
parent 45a0cadf8e
commit dd67900109
15 changed files with 92 additions and 129 deletions

View File

@@ -24,15 +24,14 @@ import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.DefaultTypeConverter;
import org.springframework.core.convert.support.GenericTypeConverter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Expression;
import org.springframework.expression.TypeConverter;
import org.springframework.expression.spel.support.StandardEvaluationContext;
/**
* Expression evaluation where the TypeConverter plugged in is the {@link GenericTypeConverter}
* Expression evaluation where the TypeConverter plugged in is the {@link org.springframework.core.convert.support.GenericConversionService}
*
* @author Andy Clement
*/
@@ -99,7 +98,7 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
*/
private static class TypeConvertorUsingConversionService implements TypeConverter {
private final DefaultTypeConverter service = new DefaultTypeConverter();
private final DefaultConversionService service = new DefaultConversionService();
public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
return this.service.canConvert(sourceType, TypeDescriptor.valueOf(targetType));

View File

@@ -27,9 +27,9 @@ import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.PropertyAccessor;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ast.CommonTypeDescriptors;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.core.convert.TypeDescriptor;
/**
* Testing variations on map access.
@@ -78,7 +78,7 @@ public class MapAccessTests extends ExpressionTestCase {
}
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
return new TypedValue(((Map) target).get(name),CommonTypeDescriptors.OBJECT_TYPE_DESCRIPTOR);
return new TypedValue(((Map) target).get(name), TypeDescriptor.valueOf(Object.class));
}
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {

View File

@@ -17,15 +17,15 @@
package org.springframework.expression.spel;
import junit.framework.Assert;
import org.junit.Test;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Expression;
import org.springframework.expression.PropertyAccessor;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ast.CommonTypeDescriptors;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
@@ -154,7 +154,7 @@ public class PropertyAccessTests extends ExpressionTestCase {
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
if (!name.equals("flibbles"))
throw new RuntimeException("Assertion Failed! name should be flibbles");
return new TypedValue(flibbles,CommonTypeDescriptors.STRING_TYPE_DESCRIPTOR);
return new TypedValue(flibbles, TypeDescriptor.valueOf(String.class));
}
public void write(EvaluationContext context, Object target, String name, Object newValue)
@@ -162,8 +162,8 @@ public class PropertyAccessTests extends ExpressionTestCase {
if (!name.equals("flibbles"))
throw new RuntimeException("Assertion Failed! name should be flibbles");
try {
flibbles = context.getTypeConverter().convertValue(newValue, Integer.class);
} catch (EvaluationException e) {
flibbles = (Integer) context.getTypeConverter().convertValue(newValue, TypeDescriptor.valueOf(Integer.class));
}catch (EvaluationException e) {
throw new AccessException("Cannot set flibbles to an object of type '" + newValue.getClass() + "'");
}
}

View File

@@ -21,8 +21,9 @@ import java.util.Map;
import java.util.Properties;
import junit.framework.Assert;
import org.junit.Test;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException;
@@ -30,7 +31,6 @@ import org.springframework.expression.Expression;
import org.springframework.expression.ParserContext;
import org.springframework.expression.PropertyAccessor;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ast.CommonTypeDescriptors;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.ReflectivePropertyResolver;
import org.springframework.expression.spel.support.StandardEvaluationContext;
@@ -219,7 +219,7 @@ public class SpringEL300Tests extends ExpressionTestCase {
}
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
return new TypedValue(((Map) target).get(name),CommonTypeDescriptors.OBJECT_TYPE_DESCRIPTOR);
return new TypedValue(((Map) target).get(name), TypeDescriptor.valueOf(Object.class));
}
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {

View File

@@ -13,13 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.expression.spel.support;
package org.springframework.expression.spel.support;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.core.convert.support.DefaultTypeConverter;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation;
import org.springframework.expression.OperatorOverloader;
@@ -70,10 +73,9 @@ public class StandardComponentsTests {
@Test
public void testStandardTypeConverter() throws EvaluationException {
TypeConverter tc = new StandardTypeConverter(new DefaultTypeConverter());
tc.convertValue(3,Double.class);
TypeConverter tc = new StandardTypeConverter(new DefaultConversionService());
tc.convertValue(3, TypeDescriptor.valueOf(Double.class));
}
}