2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.occurrence
;
12 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
13 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
14 import eu
.etaxonomy
.cdm
.model
.common
.MultilanguageText
;
15 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
16 import eu
.etaxonomy
.cdm
.model
.description
.Sex
;
17 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
18 import eu
.etaxonomy
.cdm
.model
.description
.Stage
;
19 import eu
.etaxonomy
.cdm
.model
.media
.IdentifyableMediaEntity
;
20 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.hibernate
.annotations
.Cascade
;
24 import org
.hibernate
.annotations
.CascadeType
;
25 import org
.hibernate
.annotations
.Index
;
26 import org
.hibernate
.annotations
.Table
;
30 import javax
.persistence
.*;
31 import javax
.xml
.bind
.annotation
.XmlAccessType
;
32 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
33 import javax
.xml
.bind
.annotation
.XmlElement
;
34 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
35 import javax
.xml
.bind
.annotation
.XmlIDREF
;
36 import javax
.xml
.bind
.annotation
.XmlRootElement
;
37 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
38 import javax
.xml
.bind
.annotation
.XmlType
;
41 * type figures are observations with at least a figure object in media
44 * @created 08-Nov-2007 13:06:41
46 @XmlAccessorType(XmlAccessType
.FIELD
)
47 @XmlType(name
= "SpecimenOrObservationBase", propOrder
= {
56 @XmlRootElement(name
= "SpecimenOrObservationBase")
58 @Inheritance(strategy
=InheritanceType
.SINGLE_TABLE
)
59 @Table(appliesTo
="SpecimenOrObservationBase", indexes
= { @Index(name
= "specimenOrObservationBaseTitleCacheIndex", columnNames
= { "persistentTitleCache" }) })
60 public abstract class SpecimenOrObservationBase
extends IdentifyableMediaEntity
{
62 private static final Logger logger
= Logger
.getLogger(SpecimenOrObservationBase
.class);
64 @XmlElementWrapper(name
= "Descriptions")
65 @XmlElement(name
= "Description")
66 private Set
<SpecimenDescription
> descriptions
= getNewDescriptionSet();
68 @XmlElementWrapper(name
= "Determinations")
69 @XmlElement(name
= "Determination")
70 private Set
<DeterminationEvent
> determinations
= getNewDeterminationEventSet();
72 @XmlElement(name
= "Sex")
74 @XmlSchemaType(name
= "IDREF")
77 @XmlElement(name
= "LifeStage")
79 @XmlSchemaType(name
= "IDREF")
80 private Stage lifeStage
;
82 @XmlElement(name
= "IndividualCount")
83 private Integer individualCount
;
85 // the verbatim description of this occurrence. Free text usable when no atomised data is available.
86 // in conjunction with titleCache which serves as the "citation" string for this object
87 @XmlElement(name
= "Description")
88 private MultilanguageText description
;
90 // events that created derivedUnits from this unit
91 @XmlElementWrapper(name
= "DerivationEvents")
92 @XmlElement(name
= "DerivationEvent")
94 @XmlSchemaType(name
= "IDREF")
95 private Set
<DerivationEvent
> derivationEvents
= getNewDerivationEventSet();
100 protected SpecimenOrObservationBase(){
104 // @ManyToMany //FIXME
105 // @Cascade( { CascadeType.SAVE_UPDATE })
107 public Set
<SpecimenDescription
> getDescriptions() {
108 return this.descriptions
;
110 protected void setDescriptions(Set
<SpecimenDescription
> descriptions
) {
111 this.descriptions
= descriptions
;
113 public void addDescription(SpecimenDescription description
) {
114 if (this.descriptions
== null){
115 this.descriptions
= getNewDescriptionSet();
117 this.descriptions
.add(description
);
119 public void removeDescription(SpecimenDescription description
) {
120 this.descriptions
.remove(description
);
124 @Cascade( { CascadeType
.SAVE_UPDATE
})
125 public Set
<DerivationEvent
> getDerivationEvents() {
126 return this.derivationEvents
;
128 protected void setDerivationEvents(Set
<DerivationEvent
> derivationEvents
) {
129 this.derivationEvents
= derivationEvents
;
131 public void addDerivationEvent(DerivationEvent derivationEvent
) {
132 if (! this.derivationEvents
.contains(derivationEvent
)){
133 this.derivationEvents
.add(derivationEvent
);
134 derivationEvent
.addOriginal(this);
137 public void removeDerivationEvent(DerivationEvent derivationEvent
) {
138 this.derivationEvents
.remove(derivationEvent
);
143 @OneToMany(mappedBy
="identifiedUnit")
144 @Cascade({CascadeType
.SAVE_UPDATE
})
145 public Set
<DeterminationEvent
> getDeterminations() {
146 return this.determinations
;
148 protected void setDeterminations(Set
<DeterminationEvent
> determinations
) {
149 this.determinations
= determinations
;
151 public void addDetermination(DeterminationEvent determination
) {
152 // FIXME bidirectional integrity. Use protected Determination setter
153 this.determinations
.add(determination
);
155 public void removeDetermination(DeterminationEvent determination
) {
156 // FIXME bidirectional integrity. Use protected Determination setter
157 this.determinations
.remove(determination
);
162 public Sex
getSex() {
166 public void setSex(Sex sex
) {
171 public Stage
getLifeStage() {
175 public void setLifeStage(Stage lifeStage
) {
176 this.lifeStage
= lifeStage
;
181 public String
generateTitle(){
186 public Integer
getIndividualCount() {
187 return individualCount
;
190 public void setIndividualCount(Integer individualCount
) {
191 this.individualCount
= individualCount
;
195 public MultilanguageText
getDefinition(){
196 return this.description
;
198 private void setDefinition(MultilanguageText description
){
199 this.description
= description
;
201 public void addDefinition(LanguageString description
){
203 this.description
.add(description
);
205 public void addDefinition(String text
, Language language
){
207 this.description
.put(language
, LanguageString
.NewInstance(text
, language
));
209 public void removeDefinition(Language lang
){
210 this.description
.remove(lang
);
215 * for derived units get the single next higher parental/original unit.
216 * If multiple original units exist throw error
220 public SpecimenOrObservationBase
getOriginalUnit(){
225 public abstract GatheringEvent
getGatheringEvent();
228 //******************** CLONE **********************************************/
231 * @see eu.etaxonomy.cdm.model.media.IdentifyableMediaEntity#clone()
232 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#clone()
233 * @see java.lang.Object#clone()
236 public Object
clone() throws CloneNotSupportedException
{
237 SpecimenOrObservationBase result
= null;
238 result
= (SpecimenOrObservationBase
)super.clone();
240 //defininion (description, languageString)
241 if (this.getDefinition() != null){
242 result
.setDefinition(this.getDefinition().clone());
245 result
.setSex(this.sex
);
247 result
.setLifeStage(this.lifeStage
);
250 Set
<SpecimenDescription
> descriptions
= getNewDescriptionSet();
251 descriptions
.addAll(this.descriptions
);
252 result
.setDescriptions(descriptions
);
255 Set
<DeterminationEvent
> determinationEvents
= getNewDeterminationEventSet();
256 determinationEvents
.addAll(this.determinations
);
257 result
.setDeterminations(determinationEvents
);
260 Set
<DerivationEvent
> derivationEvent
= getNewDerivationEventSet();
261 derivationEvent
.addAll(this.getDerivationEvents());
262 result
.setDerivationEvents(derivationEvent
);
264 //no changes to: individualCount
269 private Set
<SpecimenDescription
> getNewDescriptionSet(){
270 return new HashSet
<SpecimenDescription
>();
274 private Set
<DeterminationEvent
> getNewDeterminationEventSet(){
275 return new HashSet
<DeterminationEvent
>();
280 private Set
<DerivationEvent
> getNewDerivationEventSet(){
281 return new HashSet
<DerivationEvent
>();
285 * Initializes the description multilanguage text if it is not yet initialized (== null).
288 private void initDescription(){
289 if (this.description
== null){
290 this.description
= new MultilanguageText();