12 changed files with 176 additions and 45 deletions
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
/* |
||||
* 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.mapping.support; |
||||
|
||||
/** |
||||
* Default mappable type factory that registers Map and Bean mappable types. |
||||
* @author Keith Donald |
||||
*/ |
||||
final class DefaultMappableTypeFactory extends MappableTypeFactory { |
||||
public DefaultMappableTypeFactory() { |
||||
add(new MapMappableType()); |
||||
add(new BeanMappableType()); |
||||
} |
||||
} |
||||
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
/* |
||||
* 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.mapping.support; |
||||
|
||||
import java.util.LinkedHashSet; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* Generic MappableTypeFactory that has no mappable types registered by default. |
||||
* Call {@link #add(MappableType)} to register. |
||||
* @author Keith Donald |
||||
*/ |
||||
public class MappableTypeFactory { |
||||
|
||||
private Set<MappableType<?>> mappableTypes = new LinkedHashSet<MappableType<?>>(); |
||||
|
||||
/** |
||||
* Add a MappableType to this factory. |
||||
* @param mappableType the mappable type |
||||
*/ |
||||
public void add(MappableType<?> mappableType) { |
||||
this.mappableTypes.add(mappableType); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
public <T> MappableType<T> getMappableType(T object) { |
||||
for (MappableType type : mappableTypes) { |
||||
if (type.isInstance(object)) { |
||||
return type; |
||||
} |
||||
} |
||||
throw new IllegalArgumentException("Object of type [" + object.getClass().getName() |
||||
+ "] not mappable - no suitable MappableType exists"); |
||||
} |
||||
} |
||||
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
/* |
||||
* 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.mapping.support; |
||||
|
||||
import org.springframework.core.convert.TypeDescriptor; |
||||
import org.springframework.core.convert.support.DefaultConversionService; |
||||
import org.springframework.core.convert.support.GenericConverter; |
||||
|
||||
final class MappingConversionService extends DefaultConversionService { |
||||
|
||||
@Override |
||||
protected GenericConverter getDefaultConverter(TypeDescriptor sourceType, TypeDescriptor targetType) { |
||||
return new MapperConverter(new SpelMapper()); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue