| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.seasar.cubby.plugins.spring.spi; |
| 18 | |
|
| 19 | |
import java.util.Collection; |
| 20 | |
import java.util.Collections; |
| 21 | |
import java.util.LinkedHashSet; |
| 22 | |
import java.util.Set; |
| 23 | |
|
| 24 | |
import org.seasar.cubby.converter.Converter; |
| 25 | |
import org.seasar.cubby.spi.impl.AbstractCachedConverterProvider; |
| 26 | |
import org.springframework.beans.factory.BeanFactoryUtils; |
| 27 | |
import org.springframework.context.ApplicationContext; |
| 28 | |
import org.springframework.context.ApplicationContextAware; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | 6 | public class SpringConverterProvider extends AbstractCachedConverterProvider |
| 37 | |
implements ApplicationContextAware { |
| 38 | |
|
| 39 | |
private ApplicationContext applicationContext; |
| 40 | |
|
| 41 | 6 | private boolean initialized = false; |
| 42 | |
|
| 43 | 6 | private final Class<Converter> converterClass = Converter.class; |
| 44 | |
|
| 45 | 6 | private final Set<Converter> converters = new LinkedHashSet<Converter>(); |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
public void setApplicationContext( |
| 54 | |
final ApplicationContext applicationContext) { |
| 55 | 6 | this.applicationContext = applicationContext; |
| 56 | 6 | } |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
public void initialize() { |
| 62 | 6 | if (initialized) { |
| 63 | 0 | return; |
| 64 | |
} |
| 65 | 6 | String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors( |
| 66 | |
applicationContext, converterClass); |
| 67 | 23 | for (String name : names) { |
| 68 | 17 | Converter converter = converterClass.cast(applicationContext |
| 69 | |
.getBean(name, converterClass)); |
| 70 | 17 | converters.add(converter); |
| 71 | |
} |
| 72 | 6 | initialized = true; |
| 73 | 6 | } |
| 74 | |
|
| 75 | |
@Override |
| 76 | |
protected Collection<Converter> getConverters() { |
| 77 | 1 | return Collections.unmodifiableCollection(this.converters); |
| 78 | |
} |
| 79 | |
|
| 80 | |
} |