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