mapper initial commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.core.convert.support;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.ConverterFactory;
|
||||
|
||||
/**
|
||||
* Adapts a ConverterFactory to the uniform GenericConverter interface.
|
||||
* @author Keith Donald
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class ConverterFactoryGenericConverter implements GenericConverter {
|
||||
|
||||
private final ConverterFactory converterFactory;
|
||||
|
||||
public ConverterFactoryGenericConverter(ConverterFactory converterFactory) {
|
||||
this.converterFactory = converterFactory;
|
||||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return this.converterFactory.getConverter(targetType.getObjectType()).convert(source);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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.core.convert.support;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
||||
/**
|
||||
* Adapts a Converter to the uniform GenericConverter interface.
|
||||
* @author Keith Donald
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class ConverterGenericConverter implements GenericConverter {
|
||||
|
||||
private final Converter converter;
|
||||
|
||||
public ConverterGenericConverter(Converter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return this.converter.convert(source);
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||
}
|
||||
Class sourceType = typeInfo[0];
|
||||
Class targetType = typeInfo[1];
|
||||
getSourceMap(sourceType).put(targetType, new ConverterAdapter(converter));
|
||||
getSourceMap(sourceType).put(targetType, new ConverterGenericConverter(converter));
|
||||
}
|
||||
|
||||
public void addConverterFactory(ConverterFactory<?, ?> converterFactory) {
|
||||
@@ -141,7 +141,7 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||
}
|
||||
Class sourceType = typeInfo[0];
|
||||
Class targetType = typeInfo[1];
|
||||
getSourceMap(sourceType).put(targetType, new ConverterFactoryAdapter(converterFactory));
|
||||
getSourceMap(sourceType).put(targetType, new ConverterFactoryGenericConverter(converterFactory));
|
||||
}
|
||||
|
||||
public void removeConvertible(Class<?> sourceType, Class<?> targetType) {
|
||||
@@ -188,7 +188,7 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||
return invokeConverter(converter, source, sourceType, targetType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// subclassing hooks
|
||||
|
||||
/**
|
||||
@@ -242,10 +242,10 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// internal helpers
|
||||
|
||||
private Class[] getRequiredTypeInfo(Object converter, Class ifc) {
|
||||
private Class[] getRequiredTypeInfo(Object converter, Class genericIfc) {
|
||||
Class[] typeInfo = new Class[2];
|
||||
if (converter instanceof ConverterInfo) {
|
||||
ConverterInfo info = (ConverterInfo) converter;
|
||||
@@ -254,7 +254,7 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||
return typeInfo;
|
||||
}
|
||||
else {
|
||||
return GenericTypeResolver.resolveTypeArguments(converter.getClass(), ifc);
|
||||
return GenericTypeResolver.resolveTypeArguments(converter.getClass(), genericIfc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,34 +370,4 @@ public class GenericConversionService implements ConversionService, ConverterReg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class ConverterAdapter implements GenericConverter {
|
||||
|
||||
private Converter converter;
|
||||
|
||||
public ConverterAdapter(Converter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return this.converter.convert(source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class ConverterFactoryAdapter implements GenericConverter {
|
||||
|
||||
private ConverterFactory converterFactory;
|
||||
|
||||
public ConverterFactoryAdapter(ConverterFactory converterFactory) {
|
||||
this.converterFactory = converterFactory;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return this.converterFactory.getConverter(targetType.getObjectType()).convert(source);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user