KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > spring > DozerBeanMapperFactoryBean


1 /*
2  * Copyright 2005-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package net.sf.dozer.util.mapping.spring;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
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 /**
31  * @author Sören Chittka
32  */

33 public class DozerBeanMapperFactoryBean implements FactoryBean, InitializingBean {
34   private DozerBeanMapper beanMapper;
35   private Resource[] mappingFiles;
36   private List JavaDoc customConverters;
37   private List JavaDoc eventListeners;
38   private Map JavaDoc factories;
39   
40   public final void setMappingFiles(final Resource[] mappingFiles) {
41     this.mappingFiles = mappingFiles;
42   }
43     
44   public final void setCustomConverters(final List JavaDoc customConverters) {
45     this.customConverters = customConverters;
46   }
47     
48   public final void setEventListeners(final List JavaDoc eventListeners) {
49     this.eventListeners = eventListeners;
50   }
51
52   public final void setFactories(final Map JavaDoc factories) {
53     this.factories = factories;
54   }
55     
56   //==================================================================================================================================
57
//interface 'FactoryBean'
58
//==================================================================================================================================
59
public final Object JavaDoc getObject() throws Exception JavaDoc {
60     return this.beanMapper;
61   }
62   public final Class JavaDoc getObjectType() {
63     return MapperIF.class;
64   }
65   public final boolean isSingleton() {
66     return true;
67   }
68     
69   //==================================================================================================================================
70
//interface 'InitializingBean'
71
//==================================================================================================================================
72
public final void afterPropertiesSet() throws Exception JavaDoc {
73     this.beanMapper = new DozerBeanMapper();
74         
75     if (this.mappingFiles != null) {
76       final List JavaDoc mappings = new ArrayList JavaDoc(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