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.out;
|
11
|
|
12
|
import java.sql.Types;
|
13
|
|
14
|
import org.apache.logging.log4j.LogManager;
|
15
|
import org.apache.logging.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.io.common.DbExportStateBase;
|
18
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
19
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
20
|
import eu.etaxonomy.cdm.model.common.Marker;
|
21
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
22
|
|
23
|
/**
|
24
|
* @author a.mueller
|
25
|
* @since 12.05.2009
|
26
|
*/
|
27
|
public class DbMarkerMapper extends DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>> implements IDbExportMapper<DbExportStateBase<?, IExportTransformer>, IExportTransformer>{
|
28
|
|
29
|
@SuppressWarnings("unused")
|
30
|
private static final Logger logger = LogManager.getLogger();
|
31
|
|
32
|
private final MarkerType markerType;
|
33
|
|
34
|
public static DbMarkerMapper NewInstance(MarkerType markerType, String dbAttributeString){
|
35
|
return new DbMarkerMapper(markerType, dbAttributeString, null);
|
36
|
}
|
37
|
|
38
|
public static DbMarkerMapper NewInstance(MarkerType markerType, String dbAttributeString, boolean defaultValue){
|
39
|
return new DbMarkerMapper(markerType, dbAttributeString, defaultValue);
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* @param dbAttributeString
|
44
|
* @param cdmAttributeString
|
45
|
*/
|
46
|
private DbMarkerMapper(MarkerType markerType, String dbAttributeString, Boolean defaultValue) {
|
47
|
super("markers", dbAttributeString, defaultValue);
|
48
|
this.markerType = markerType;
|
49
|
|
50
|
}
|
51
|
|
52
|
|
53
|
/* (non-Javadoc)
|
54
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValue(eu.etaxonomy.cdm.model.common.CdmBase)
|
55
|
*/
|
56
|
@Override
|
57
|
protected Object getValue(CdmBase cdmBase) {
|
58
|
Boolean result = (Boolean)this.defaultValue;
|
59
|
if (cdmBase.isInstanceOf(AnnotatableEntity.class)){
|
60
|
AnnotatableEntity annotatableEntity = (AnnotatableEntity)cdmBase;
|
61
|
for (Marker marker : annotatableEntity.getMarkers()){
|
62
|
if (this.markerType != null && this.markerType.equals(marker.getMarkerType())){
|
63
|
return marker.getFlag();
|
64
|
}
|
65
|
}
|
66
|
}else{
|
67
|
throw new ClassCastException("CdmBase for DbMarkerMapper must be of type AnnotatableEntity, but was " + cdmBase.getClass());
|
68
|
}
|
69
|
return result;
|
70
|
}
|
71
|
|
72
|
/* (non-Javadoc)
|
73
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValueType()
|
74
|
*/
|
75
|
@Override
|
76
|
protected int getSqlType() {
|
77
|
return Types.BOOLEAN;
|
78
|
}
|
79
|
|
80
|
|
81
|
/* (non-Javadoc)
|
82
|
* @see eu.etaxonomy.cdm.io.common.CdmSingleAttributeMapperBase#getTypeClass()
|
83
|
*/
|
84
|
@Override
|
85
|
public Class<?> getTypeClass() {
|
86
|
return Boolean.class;
|
87
|
}
|
88
|
}
|