Project

General

Profile

Download (3.15 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.cdm.io.common.mapping;
12

    
13
import java.sql.ResultSet;
14
import java.sql.SQLException;
15
import java.util.ArrayList;
16
import java.util.HashSet;
17
import java.util.List;
18
import java.util.Set;
19

    
20
import org.apache.log4j.Logger;
21

    
22
import eu.etaxonomy.cdm.common.CdmUtils;
23

    
24

    
25

    
26
/**
27
 * @author a.mueller
28
 * @created 12.05.2009
29
 * @version 1.0
30
 */
31
public abstract class MultipleAttributeMapperBase<SINGLE_MAPPER extends CdmSingleAttributeMapperBase> extends CdmAttributeMapperBase {
32
	@SuppressWarnings("unused")
33
	private static final Logger logger = Logger.getLogger(MultipleAttributeMapperBase.class);
34

    
35
	
36
//******************************* ATTRIBUTES ***************************************/
37

    
38
	protected List<SINGLE_MAPPER> singleMappers = new ArrayList<SINGLE_MAPPER>();
39

    
40
	
41
	
42
//********************************* CONSTRUCTOR ****************************************/
43

    
44
	/**
45
	 * 
46
	 */
47
	public MultipleAttributeMapperBase() {
48
		singleMappers = new ArrayList<SINGLE_MAPPER>();
49
	}
50

    
51

    
52
//************************************ METHODS *******************************************/
53
	
54
	/* (non-Javadoc)
55
	 * @see eu.etaxonomy.cdm.io.common.CdmAttributeMapperBase#getDestinationAttributeList()
56
	 */
57
	@Override
58
	public List<String> getDestinationAttributeList() {
59
		List<String> result = new ArrayList<String>();
60
		for (SINGLE_MAPPER singleMapper : singleMappers){
61
			result.add(singleMapper.getDestinationAttribute());
62
		}
63
		return result;
64
	}
65

    
66
	/* (non-Javadoc)
67
	 * @see eu.etaxonomy.cdm.io.common.CdmAttributeMapperBase#getDestinationAttributes()
68
	 */
69
	@Override
70
	public Set<String> getDestinationAttributes() {
71
		Set<String> result = new HashSet<String>();
72
		result.addAll(getDestinationAttributeList());
73
		return result;
74
	}
75

    
76
	/* (non-Javadoc)
77
	 * @see eu.etaxonomy.cdm.io.common.CdmAttributeMapperBase#getSourceAttributeList()
78
	 */
79
	@Override
80
	public List<String> getSourceAttributeList() {
81
		List<String> result = new ArrayList<String>();
82
		for (SINGLE_MAPPER singleMapper : singleMappers){
83
			result.add(singleMapper.getSourceAttribute());
84
		}
85
		return result;
86
	}
87

    
88
	/* (non-Javadoc)
89
	 * @see eu.etaxonomy.cdm.io.common.CdmAttributeMapperBase#getSourceAttributes()
90
	 */
91
	@Override
92
	public Set<String> getSourceAttributes() {
93
		Set<String> result = new HashSet<String>();
94
		result.addAll(getSourceAttributeList());
95
		return result;
96
	}
97
	
98

    
99
/**
100
	 * Returns the value of a result set attribute in its String representation.
101
	 * Better move this to a subclass for DbImportMappers (does not exist yet)
102
	 * @param rs
103
	 * @param attribute
104
	 * @return
105
	 * @throws SQLException
106
	 */
107
	protected String getStringDbValue(ResultSet rs, String attribute) throws SQLException {
108
		if (CdmUtils.isEmpty(attribute)){
109
			return null;
110
		}
111
		Object oId = rs.getObject(attribute);
112
		if (oId == null){
113
			return null;
114
		}
115
		String id = String.valueOf(oId);
116
		return id;
117
	}
118
}
(43-43/44)