forked from spring-projects/spring-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
found hotspot; added ConverisonServiceFactoryBean
- Loading branch information
Keith Donald
committed
Nov 20, 2009
1 parent
4024b67
commit 692b1ef
Showing
8 changed files
with
149 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...ntext/src/main/java/org/springframework/context/support/ConversionServiceFactoryBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* 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.context.support; | ||
|
||
import java.util.Set; | ||
|
||
import org.springframework.beans.factory.FactoryBean; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.core.convert.ConversionService; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.core.convert.converter.ConverterFactory; | ||
import org.springframework.core.convert.converter.ConverterRegistry; | ||
import org.springframework.core.convert.converter.GenericConverter; | ||
import org.springframework.core.convert.support.ConversionServiceFactory; | ||
|
||
/** | ||
* A factory for a ConversionService that installs default converters appropriate for most environments. | ||
* Set the <code>converters</code> property to supplement or override the default converters. | ||
* @author Keith Donald | ||
* @since 3.0 | ||
* @see ConversionServiceFactory#createDefaultConversionService() | ||
*/ | ||
public class ConversionServiceFactoryBean implements FactoryBean<ConversionService>, InitializingBean { | ||
|
||
private Set<Object> converters; | ||
|
||
private ConversionService conversionService; | ||
|
||
/** | ||
* Configure the set of custom Converters that should be added. | ||
*/ | ||
public void setConverters(Set<Object> converters) { | ||
this.converters = converters; | ||
} | ||
|
||
// implementing InitializingBean | ||
|
||
public void afterPropertiesSet() { | ||
this.conversionService = createConversionService(); | ||
registerConverters(this.converters, (ConverterRegistry) this.conversionService); | ||
} | ||
|
||
// implementing FactoryBean | ||
|
||
public ConversionService getObject() { | ||
return this.conversionService; | ||
} | ||
|
||
public Class<? extends ConversionService> getObjectType() { | ||
return ConversionService.class; | ||
} | ||
|
||
public boolean isSingleton() { | ||
return true; | ||
} | ||
|
||
// subclassing hooks | ||
|
||
/** | ||
* Creates the ConversionService instance returned by this factory bean. | ||
*/ | ||
protected ConversionService createConversionService() { | ||
return ConversionServiceFactory.createDefaultConversionService(); | ||
} | ||
|
||
// internal helpers | ||
|
||
private void registerConverters(Set<Object> converters, ConverterRegistry registry) { | ||
if (converters != null) { | ||
for (Object converter : converters) { | ||
if (converter instanceof Converter<?, ?>) { | ||
registry.addConverter((Converter<?, ?>) converter); | ||
} else if (converter instanceof ConverterFactory<?, ?>) { | ||
registry.addConverterFactory((ConverterFactory<?, ?>) converter); | ||
} else if (converter instanceof GenericConverter) { | ||
registry.addGenericConverter((GenericConverter) converter); | ||
} else { | ||
throw new IllegalArgumentException("Each converter must implement one of the Converter, ConverterFactory, or GenericConverter interfaces"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters