bind target initial commit

sample polishing
This commit is contained in:
Keith Donald
2008-03-15 07:04:45 +00:00
parent c5340f7f2b
commit ee37861149
15 changed files with 142 additions and 114 deletions

View File

@@ -135,11 +135,11 @@ public class GenericConversionService implements ConversionService {
if (this.sourceClassConverters == null || this.sourceClassConverters.isEmpty()) {
throw new IllegalStateException("No converters have been added to this service's registry");
}
sourceClass = convertToWrapperClassIfNecessary(sourceClass);
targetClass = convertToWrapperClassIfNecessary(targetClass);
if (targetClass.isAssignableFrom(sourceClass)) {
return new ConversionExecutorImpl(sourceClass, targetClass, new NoOpConverter(sourceClass, targetClass));
}
sourceClass = convertToWrapperClassIfNecessary(sourceClass);
targetClass = convertToWrapperClassIfNecessary(targetClass);
Map sourceTargetConverters = findConvertersForSource(sourceClass);
Converter converter = findTargetConverter(sourceTargetConverters, targetClass);
if (converter != null) {

View File

@@ -56,16 +56,6 @@ public class Mapping {
*/
private boolean required;
/**
* Creates a new mapping.
* @param sourceExpression the source expression
* @param targetExpression the target expression
* @param typeConverter a type converter
*/
public Mapping(Expression sourceExpression, Expression targetExpression, ConversionExecutor typeConverter) {
this(sourceExpression, targetExpression, typeConverter, false);
}
/**
* Creates a new mapping.
* @param sourceExpression the source expression
@@ -94,7 +84,7 @@ public class Mapping {
Assert.notNull(target, "The target to map to is required");
Assert.notNull(context, "The mapping context is required");
Object sourceValue = sourceExpression.getValue(source);
if (required && sourceValue == null || isEmptyString(sourceValue)) {
if (required && (sourceValue == null || isEmptyString(sourceValue))) {
String defaultText = "'" + targetExpression.getExpressionString() + "' is required";
MessageResolver message = new MessageBuilder().error().source(targetExpression.getExpressionString())
.codes(createMessageCodes("required", target, targetExpression)).defaultText(defaultText).build();
@@ -106,6 +96,7 @@ public class Mapping {
try {
targetValue = typeConverter.execute(sourceValue);
} catch (ConversionException e) {
e.printStackTrace();
String defaultText = "The '" + targetExpression.getExpressionString() + "' value is the wrong type";
MessageResolver message = new MessageBuilder().error().source(targetExpression.getExpressionString())
.codes(createMessageCodes("typeMismatch", target, targetExpression)).defaultText(defaultText)