Project

General

Profile

Download (1.88 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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.io.dwca.out;
10

    
11
import java.util.UUID;
12

    
13
import org.apache.log4j.Logger;
14

    
15
import eu.etaxonomy.cdm.common.URI;
16
import eu.etaxonomy.cdm.model.common.CdmBase;
17
import eu.etaxonomy.cdm.model.common.ICdmBase;
18
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
19
import eu.etaxonomy.cdm.model.common.LSID;
20

    
21
/**
22
 * @author a.mueller
23
 * @since 29.04.2011
24
 */
25
public class DwcaId {
26
	@SuppressWarnings("unused")
27
	private static final Logger logger = Logger.getLogger(DwcaId.class);
28

    
29
	private Integer intId;
30
	private String strId;
31
	private UUID uuidId;
32
	private URI uriId;
33
	private LSID lsidId;
34

    
35
	private DwcaTaxExportConfigurator config;
36

    
37
	public DwcaId(DwcaTaxExportConfigurator config){
38
		this.config = config;
39
	}
40

    
41
	public void setId(Integer id){
42
		this.intId = id;
43
	}
44
	public void setId(UUID uuid){
45
		this.uuidId = uuid;
46
	}
47
	public void setId(LSID lsid){
48
		this.lsidId = lsid;
49
	}
50

    
51

    
52
	public void setId(ICdmBase cdmBase) {
53
		this.setId(cdmBase.getId());
54
		this.setId(cdmBase.getUuid());
55
		if (cdmBase.isInstanceOf(IdentifiableEntity.class)){
56
			this.setId(CdmBase.deproxy(cdmBase,IdentifiableEntity.class).getLsid());
57
		}
58
	}
59

    
60
	public String getId(){
61
		Object object;
62
		if (config.isUseIdWherePossible()){
63
			object = intId;
64
		}else if (lsidId != null){
65
			object = lsidId;
66
		}else if (uriId != null){
67
			object = uriId;
68
		}else if(uuidId != null){
69
			object = uuidId;
70
		}else if(intId != null){
71
			object = intId;
72
		}else{
73
			object = strId;
74
		}
75
		return nullSafe(object);
76
	}
77

    
78
	private String nullSafe(Object o){
79
		return o == null ? null : o.toString();
80
	}
81

    
82

    
83
}
(9-9/33)