removed mapping context iface

This commit is contained in:
Keith Donald
2008-03-26 04:00:07 +00:00
parent e4145e0c97
commit ced7258332
4 changed files with 54 additions and 100 deletions

View File

@@ -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 {

View File

@@ -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);
}
}

View File

@@ -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);
}