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
|
|
10
|
package eu.etaxonomy.cdm.io.common;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
|
19
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.IDbExportMapper;
|
20
|
|
21
|
|
22
|
/**
|
23
|
* @author a.mueller
|
24
|
* @created 27.07.2008
|
25
|
* @version 1.0
|
26
|
*/
|
27
|
public class CdmIoMapping {
|
28
|
private static final Logger logger = Logger.getLogger(CdmIoMapping.class);
|
29
|
|
30
|
//protected List<CdmAttributeMapperBase> mapperList = new ArrayList<CdmAttributeMapperBase>();
|
31
|
protected List<CdmAttributeMapperBase> mapperList = new ArrayList<CdmAttributeMapperBase>();
|
32
|
Set<String> sourceAttributes = new HashSet<String>();
|
33
|
Set<String> destinationAttributes = new HashSet<String>();
|
34
|
List<String> sourceAttributeList = new ArrayList<String>();
|
35
|
List<String> destinationAttributeList = new ArrayList<String>();
|
36
|
|
37
|
|
38
|
public void addMapper(CdmAttributeMapperBase mapper){
|
39
|
if (mapper == null){
|
40
|
return;
|
41
|
}
|
42
|
mapperList.add(mapper);
|
43
|
if (mapper instanceof CdmSingleAttributeMapperBase){
|
44
|
CdmSingleAttributeMapperBase singleMapper = (CdmSingleAttributeMapperBase)mapper;
|
45
|
sourceAttributes.addAll(singleMapper.getSourceAttributes());
|
46
|
sourceAttributeList.addAll(singleMapper.getSourceAttributeList());
|
47
|
destinationAttributes.addAll(singleMapper.getDestinationAttributes());
|
48
|
destinationAttributeList.addAll(singleMapper.getDestinationAttributeList());
|
49
|
}else if (mapper instanceof MultipleAttributeMapperBase){
|
50
|
MultipleAttributeMapperBase<?> multipleMapper = (MultipleAttributeMapperBase<?>)mapper;
|
51
|
sourceAttributes.addAll(multipleMapper.getSourceAttributes());
|
52
|
sourceAttributeList.addAll(multipleMapper.getSourceAttributes());
|
53
|
destinationAttributes.addAll(multipleMapper.getDestinationAttributes());
|
54
|
destinationAttributeList.addAll(multipleMapper.getDestinationAttributeList());
|
55
|
}else{
|
56
|
logger.error("Unknown mapper type: " + mapper.getClass().getSimpleName());
|
57
|
throw new IllegalArgumentException("Unknown mapper type: " + mapper.getClass().getSimpleName());
|
58
|
}
|
59
|
}
|
60
|
|
61
|
public Set<String> getSourceAttributes(){
|
62
|
Set<String> result = new HashSet<String>();
|
63
|
result.addAll(sourceAttributes);
|
64
|
return result;
|
65
|
}
|
66
|
|
67
|
public Set<String> getSourceAttributesLowerCase(){
|
68
|
Set<String> result = new HashSet<String>();
|
69
|
for(String attr : sourceAttributes){
|
70
|
if (attr != null){
|
71
|
result.add(attr.toLowerCase());
|
72
|
}else{
|
73
|
result.add(null);
|
74
|
}
|
75
|
}
|
76
|
return result;
|
77
|
}
|
78
|
|
79
|
public Set<String> getDestinationAttributes(){
|
80
|
Set<String> result = new HashSet<String>();
|
81
|
result.addAll(destinationAttributes);
|
82
|
return result;
|
83
|
}
|
84
|
|
85
|
public List<String> getDestinationAttributeList(){
|
86
|
List<String> result = new ArrayList<String>();
|
87
|
result.addAll(destinationAttributeList);
|
88
|
return result;
|
89
|
}
|
90
|
|
91
|
}
|