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.model.taxon;
|
11
|
|
12
|
|
13
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
14
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
15
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
16
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.hibernate.annotations.Cascade;
|
20
|
import org.hibernate.annotations.CascadeType;
|
21
|
import org.hibernate.collection.PersistentSet;
|
22
|
|
23
|
|
24
|
import java.lang.reflect.Field;
|
25
|
import java.util.*;
|
26
|
|
27
|
import javax.persistence.*;
|
28
|
|
29
|
/**
|
30
|
* {unique name within view/treatment}
|
31
|
* @author m.doering
|
32
|
* @version 1.0
|
33
|
* @created 08-Nov-2007 13:06:56
|
34
|
*/
|
35
|
@Entity
|
36
|
public abstract class TaxonBase extends IdentifiableEntity {
|
37
|
static Logger logger = Logger.getLogger(TaxonBase.class);
|
38
|
|
39
|
//TODO make static for performance reasons
|
40
|
private static Field taxonBaseField;
|
41
|
|
42
|
protected TaxonBase(){
|
43
|
super();
|
44
|
}
|
45
|
|
46
|
|
47
|
//The assignment to the Taxon or to the Synonym class is not definitive
|
48
|
private boolean isDoubtful;
|
49
|
private TaxonNameBase name;
|
50
|
// The concept reference
|
51
|
private ReferenceBase sec;
|
52
|
|
53
|
@Override
|
54
|
public String generateTitle() {
|
55
|
String title;
|
56
|
if (name != null){
|
57
|
title = name.getTitleCache() + " sec. ";
|
58
|
if (sec != null){
|
59
|
title += sec.getTitleCache();
|
60
|
}else{
|
61
|
title += "???";
|
62
|
}
|
63
|
}else{
|
64
|
title = this.toString();
|
65
|
}
|
66
|
return title;
|
67
|
}
|
68
|
|
69
|
@ManyToOne
|
70
|
@Cascade(CascadeType.SAVE_UPDATE)
|
71
|
public TaxonNameBase getName(){
|
72
|
return this.name;
|
73
|
}
|
74
|
public void setName(TaxonNameBase newName){
|
75
|
try {
|
76
|
initTaxonBaseField();
|
77
|
if (this.name == newName) return;
|
78
|
if (this.name != null) {
|
79
|
Set<TaxonBase> taxonBases = (Set<TaxonBase>) taxonBaseField.get(this.name);
|
80
|
taxonBases.remove(this);
|
81
|
}
|
82
|
if (newName != null) {
|
83
|
Set<TaxonBase> taxonBases = (Set<TaxonBase>) taxonBaseField.get(newName);
|
84
|
//hack for avoiding org.hibernate.LazyInitializationException: illegal access to loading collection
|
85
|
if (taxonBases instanceof PersistentSet){
|
86
|
//
|
87
|
}else{
|
88
|
taxonBases.add(this);
|
89
|
}
|
90
|
}
|
91
|
this.name = newName;
|
92
|
} catch (Exception e) {
|
93
|
logger.error(e.getMessage());
|
94
|
System.out.println( e.getStackTrace());
|
95
|
}
|
96
|
}
|
97
|
|
98
|
|
99
|
private void initTaxonBaseField()throws NoSuchFieldException {
|
100
|
if (taxonBaseField == null) {
|
101
|
taxonBaseField = TaxonNameBase.class.getDeclaredField("taxonBases");
|
102
|
taxonBaseField.setAccessible(true);
|
103
|
}
|
104
|
}
|
105
|
|
106
|
@Transient
|
107
|
public HomotypicalGroup getHomotypicGroup(){
|
108
|
if (this.getName() == null){
|
109
|
return null;
|
110
|
}else{
|
111
|
return this.getName().getHomotypicalGroup();
|
112
|
}
|
113
|
}
|
114
|
|
115
|
public boolean isDoubtful(){
|
116
|
return this.isDoubtful;
|
117
|
}
|
118
|
public void setDoubtful(boolean isDoubtful){
|
119
|
this.isDoubtful = isDoubtful;
|
120
|
}
|
121
|
|
122
|
@ManyToOne
|
123
|
@Cascade(CascadeType.SAVE_UPDATE)
|
124
|
public ReferenceBase getSec() {
|
125
|
return sec;
|
126
|
}
|
127
|
|
128
|
public void setSec(ReferenceBase sec) {
|
129
|
this.sec = sec;
|
130
|
}
|
131
|
|
132
|
@Transient
|
133
|
public boolean isSaveable(){
|
134
|
if ( (this.getName() == null) || (this.getSec() == null) ){
|
135
|
return false;
|
136
|
}else{
|
137
|
this.toString();
|
138
|
return true;
|
139
|
}
|
140
|
}
|
141
|
|
142
|
|
143
|
}
|