diff --git a/spring-binding/src/main/java/org/springframework/binding/mapping/impl/DefaultMapping.java b/spring-binding/src/main/java/org/springframework/binding/mapping/impl/DefaultMapping.java index d9596641..db657cf2 100644 --- a/spring-binding/src/main/java/org/springframework/binding/mapping/impl/DefaultMapping.java +++ b/spring-binding/src/main/java/org/springframework/binding/mapping/impl/DefaultMapping.java @@ -106,7 +106,7 @@ public class DefaultMapping implements Mapping { * Execute this mapping. * @param context the mapping context */ - void map(MappingContext context) { + void map(DefaultMappingContext context) { context.setCurrentMapping(this); Object sourceValue; try { diff --git a/spring-binding/src/main/java/org/springframework/binding/mapping/impl/DefaultMappingContext.java b/spring-binding/src/main/java/org/springframework/binding/mapping/impl/DefaultMappingContext.java index a5be98c4..67a70965 100644 --- a/spring-binding/src/main/java/org/springframework/binding/mapping/impl/DefaultMappingContext.java +++ b/spring-binding/src/main/java/org/springframework/binding/mapping/impl/DefaultMappingContext.java @@ -20,7 +20,7 @@ import org.springframework.binding.mapping.results.TypeConversionError; * Default mapping context implementation. * @author Keith Donald */ -class DefaultMappingContext implements MappingContext { +public class DefaultMappingContext { private static final Log logger = LogFactory.getLog(DefaultMapping.class); @@ -41,22 +41,41 @@ class DefaultMappingContext implements MappingContext { this.mappingResults = new ArrayList(); } + /** + * The object being mapped from. + */ public Object getSource() { return source; } + /** + * The object being mapped to. + */ public Object getTarget() { return target; } + /** + * Returns the conversion service that can be used to perform type conversions during the mapping process. May be + * null if no externally managed conversion service is provided. + */ public ConversionService getConversionService() { return conversionService; } + /** + * Returns the current mapping. + * @return the current mapping + */ public Mapping getCurrentMapping() { return currentMapping; } + /** + * Sets the current mapping. Called when a single mapping operation is about to begin. This updates progress of the + * overall mapping transaction. + * @param mapping the mapping to make the current mapping + */ public void setCurrentMapping(Mapping mapping) { if (this.currentMapping != null) { throw new IllegalStateException("The current mapping has not finished yet"); @@ -64,26 +83,57 @@ class DefaultMappingContext implements MappingContext { this.currentMapping = mapping; } + /** + * Indicates the current mapping completed successfully. + * @param originalValue the original value from the source of the mapping + * @param mappedValue the successfully mapped value, which may be different from the original if a type conversion + * was performed + */ public void setSuccessResult(Object originalValue, Object mappedValue) { add(new MappingResult(currentMapping, new Success(mappedValue, originalValue))); } + /** + * Indicates the current mapping ended with a 'required' error. This means the value obtained from the source was + * empty, and the mapping could not be completed as a result. + * @param originalValue the original source value that is empty (null or an empty string, typically) + */ public void setRequiredErrorResult(Object originalValue) { add(new MappingResult(currentMapping, new RequiredError(originalValue))); } + /** + * Indicates the current mapping ended with a 'type conversion' error. This means the value obtained from the source + * could not be converted to a type that could be assigned to the target expression. + * @param originalValue the original source value that could not be converted during the mapping attempt + * @param targetType the desired target type to which conversion could not be performed + */ public void setTypeConversionErrorResult(Object originalValue, Class targetType) { add(new MappingResult(currentMapping, new TypeConversionError(originalValue, targetType))); } + /** + * Indicates a error occurred accessing the source mapping expression. + * @param error the error that occurred + */ public void setSourceAccessError(EvaluationException error) { add(new MappingResult(currentMapping, new SourceAccessError(error))); } + /** + * Indicates a error occurred accessing the target mapping expression. + * @param error the error that occurred + */ public void setTargetAccessError(Object originalValue, EvaluationException error) { add(new MappingResult(currentMapping, new TargetAccessError(originalValue, error))); } + public MappingResults toResult() { + return new DefaultMappingResults(source, target, mappingResults); + } + + // internal helpers + private void add(MappingResult result) { if (logger.isDebugEnabled()) { logger.debug("Adding " + result); @@ -92,7 +142,4 @@ class DefaultMappingContext implements MappingContext { this.currentMapping = null; } - public MappingResults toResult() { - return new DefaultMappingResults(source, target, mappingResults); - } } diff --git a/spring-binding/src/main/java/org/springframework/binding/mapping/impl/MappingContext.java b/spring-binding/src/main/java/org/springframework/binding/mapping/impl/MappingContext.java deleted file mode 100644 index 0b6614a5..00000000 --- a/spring-binding/src/main/java/org/springframework/binding/mapping/impl/MappingContext.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2004-2007 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.mapping.impl; - -import org.springframework.binding.convert.ConversionService; -import org.springframework.binding.expression.EvaluationException; -import org.springframework.binding.mapping.Mapping; - -/** - * A context for a mapping transaction. - * - * @author Keith Donald - */ -public interface MappingContext { - - /** - * The object being mapped from. - */ - public Object getSource(); - - /** - * The object being mapped to. - */ - public Object getTarget(); - - /** - * Returns the conversion service that can be used to perform type conversions during the mapping process. May be - * null if no externally managed conversion service is provided. - */ - public ConversionService getConversionService(); - - /** - * Returns the current mapping. - * @return the current mapping - */ - public Mapping getCurrentMapping(); - - /** - * Sets the current mapping. Called when a single mapping operation is about to begin. This updates progress of the - * overall mapping transaction. - * @param mapping the mapping to make the current mapping - */ - public void setCurrentMapping(Mapping mapping); - - /** - * Indicates the current mapping completed successfully. - * @param originalValue the original value from the source of the mapping - * @param mappedValue the successfully mapped value, which may be different from the original if a type conversion - * was performed - */ - public void setSuccessResult(Object originalValue, Object mappedValue); - - /** - * Indicates the current mapping ended with a 'required' error. This means the value obtained from the source was - * empty, and the mapping could not be completed as a result. - * @param originalValue the original source value that is empty (null or an empty string, typically) - */ - public void setRequiredErrorResult(Object originalValue); - - /** - * Indicates the current mapping ended with a 'type conversion' error. This means the value obtained from the source - * could not be converted to a type that could be assigned to the target expression. - * @param originalValue the original source value that could not be converted during the mapping attempt - * @param targetType the desired target type to which conversion could not be performed - */ - public void setTypeConversionErrorResult(Object originalValue, Class targetType); - - /** - * Indicates a error occurred accessing the source mapping expression. - * @param error the error that occurred - */ - public void setSourceAccessError(EvaluationException error); - - /** - * Indicates a error occurred accessing the target mapping expression. - * @param error the error that occurred - */ - public void setTargetAccessError(Object originalValue, EvaluationException error); - -} diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/MvcView.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/MvcView.java index c05c74fa..7cdbb604 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/MvcView.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/MvcView.java @@ -38,7 +38,7 @@ import org.springframework.binding.mapping.MappingResults; import org.springframework.binding.mapping.MappingResultsCriteria; import org.springframework.binding.mapping.impl.DefaultMapper; import org.springframework.binding.mapping.impl.DefaultMapping; -import org.springframework.binding.mapping.impl.MappingContext; +import org.springframework.binding.mapping.impl.DefaultMappingContext; import org.springframework.binding.mapping.results.TargetAccessError; import org.springframework.validation.BindingResult; import org.springframework.webflow.core.collection.ParameterMap; @@ -258,7 +258,7 @@ class MvcView implements View { public Object execute(Object source, Object context) throws ConversionException { String formattedValue = (String) source; - MappingContext mappingContext = (MappingContext) context; + DefaultMappingContext mappingContext = (DefaultMappingContext) context; Expression target = mappingContext.getCurrentMapping().getTargetExpression(); Class targetClass = getTargetClass(); if (targetClass == null) {