Project

General

Profile

Download (2.84 KB) Statistics
| Branch: | Tag: | Revision:
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

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