1 16 package net.sf.dozer.util.mapping.spring; 17 18 import java.util.ArrayList ; 19 import java.util.List ; 20 import java.util.Map ; 21 22 import net.sf.dozer.util.mapping.DozerBeanMapper; 23 import net.sf.dozer.util.mapping.MapperIF; 24 import net.sf.dozer.util.mapping.util.MapperConstants; 25 26 import org.springframework.beans.factory.FactoryBean; 27 import org.springframework.beans.factory.InitializingBean; 28 import org.springframework.core.io.Resource; 29 30 33 public class DozerBeanMapperFactoryBean implements FactoryBean, InitializingBean { 34 private DozerBeanMapper beanMapper; 35 private Resource[] mappingFiles; 36 private List customConverters; 37 private List eventListeners; 38 private Map factories; 39 40 public final void setMappingFiles(final Resource[] mappingFiles) { 41 this.mappingFiles = mappingFiles; 42 } 43 44 public final void setCustomConverters(final List customConverters) { 45 this.customConverters = customConverters; 46 } 47 48 public final void setEventListeners(final List eventListeners) { 49 this.eventListeners = eventListeners; 50 } 51 52 public final void setFactories(final Map factories) { 53 this.factories = factories; 54 } 55 56 public final Object getObject() throws Exception { 60 return this.beanMapper; 61 } 62 public final Class getObjectType() { 63 return MapperIF.class; 64 } 65 public final boolean isSingleton() { 66 return true; 67 } 68 69 public final void afterPropertiesSet() throws Exception { 73 this.beanMapper = new DozerBeanMapper(); 74 75 if (this.mappingFiles != null) { 76 final List mappings = new ArrayList (this.mappingFiles.length); 77 for (int i = 0; i < this.mappingFiles.length; i++) { 78 mappings.add(MapperConstants.FILE_PREFIX + this.mappingFiles[i].getFile().toString()); 79 } 80 this.beanMapper.setMappingFiles(mappings); 81 } 82 if (this.customConverters != null) { 83 this.beanMapper.setCustomConverters(this.customConverters); 84 } 85 if (this.eventListeners != null) { 86 this.beanMapper.setEventListeners(this.eventListeners); 87 } 88 if (this.factories != null) { 89 this.beanMapper.setFactories(this.factories); 90 } 91 } 92 93 } 94 95 96 | Popular Tags |