1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.remote.dto.assembler;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
import java.util.Map;
|
14
|
|
15
|
import org.dozer.BeanFactory;
|
16
|
import org.dozer.CustomConverter;
|
17
|
import org.dozer.CustomFieldMapper;
|
18
|
import org.dozer.DozerBeanMapper;
|
19
|
import org.dozer.DozerEventListener;
|
20
|
import org.dozer.Mapper;
|
21
|
import org.springframework.beans.factory.FactoryBean;
|
22
|
import org.springframework.beans.factory.InitializingBean;
|
23
|
import org.springframework.core.io.Resource;
|
24
|
|
25
|
/**
|
26
|
* extended version of Sören Chittka's DozerBeanMapperFactoryBean, allowing other
|
27
|
* properties to be set.
|
28
|
* @author Sören Chittka
|
29
|
*/
|
30
|
public class DozerBeanMapperFactoryBean implements FactoryBean, InitializingBean {
|
31
|
|
32
|
private DozerBeanMapper beanMapper;
|
33
|
private Resource[] mappingFiles;
|
34
|
private List<CustomConverter> customConverters;
|
35
|
private Map<String,CustomConverter> customConvertersWithId;
|
36
|
private List<DozerEventListener> eventListeners;
|
37
|
private Map<String, BeanFactory> factories;
|
38
|
private CustomFieldMapper customFieldMapper;
|
39
|
|
40
|
|
41
|
public final void setMappingFiles(final Resource[] mappingFiles) {
|
42
|
this.mappingFiles = mappingFiles;
|
43
|
}
|
44
|
|
45
|
public final void setCustomConverters(final List<CustomConverter> customConverters) {
|
46
|
this.customConverters = customConverters;
|
47
|
}
|
48
|
|
49
|
public final void setEventListeners(final List<DozerEventListener> eventListeners) {
|
50
|
this.eventListeners = eventListeners;
|
51
|
}
|
52
|
|
53
|
public final void setFactories(final Map<String, BeanFactory> factories) {
|
54
|
this.factories = factories;
|
55
|
}
|
56
|
|
57
|
public final void setCustomFieldMapper(final CustomFieldMapper customFieldMapper) {
|
58
|
this.customFieldMapper = customFieldMapper;
|
59
|
}
|
60
|
|
61
|
public final void setCustomConvertersWithId(final Map<String,CustomConverter> customConvertersWithId) {
|
62
|
this.customConvertersWithId = customConvertersWithId;
|
63
|
}
|
64
|
|
65
|
// ==================================================================================================================================
|
66
|
// interface 'FactoryBean'
|
67
|
// ==================================================================================================================================
|
68
|
public final Object getObject() throws Exception {
|
69
|
return this.beanMapper;
|
70
|
}
|
71
|
public final Class<Mapper> getObjectType() {
|
72
|
return Mapper.class;
|
73
|
}
|
74
|
public final boolean isSingleton() {
|
75
|
return true;
|
76
|
}
|
77
|
|
78
|
// ==================================================================================================================================
|
79
|
// interface 'InitializingBean'
|
80
|
// ==================================================================================================================================
|
81
|
public final void afterPropertiesSet() throws Exception {
|
82
|
this.beanMapper = new DozerBeanMapper();
|
83
|
|
84
|
if (this.mappingFiles != null) {
|
85
|
final List<String> mappings = new ArrayList<String>(this.mappingFiles.length);
|
86
|
for (Resource mappingFile : this.mappingFiles) {
|
87
|
mappings.add(mappingFile.getURL().toString());
|
88
|
}
|
89
|
this.beanMapper.setMappingFiles(mappings);
|
90
|
}
|
91
|
if (this.customConverters != null) {
|
92
|
this.beanMapper.setCustomConverters(this.customConverters);
|
93
|
}
|
94
|
if (this.eventListeners != null) {
|
95
|
this.beanMapper.setEventListeners(this.eventListeners);
|
96
|
}
|
97
|
if (this.factories != null) {
|
98
|
this.beanMapper.setFactories(this.factories);
|
99
|
}
|
100
|
|
101
|
if(this.customFieldMapper != null) {
|
102
|
this.beanMapper.setCustomFieldMapper(customFieldMapper);
|
103
|
}
|
104
|
|
105
|
if(this.customConvertersWithId != null) {
|
106
|
this.beanMapper.setCustomConvertersWithId(customConvertersWithId);
|
107
|
}
|
108
|
}
|
109
|
|
110
|
}
|