Major changes to the cdmlib default term loading and initialization, plus indexing...
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / name / TypeDesignationBase.java
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.name;
11
12 import java.util.HashSet;
13 import java.util.Set;
14
15 import javax.persistence.Entity;
16 import javax.persistence.Inheritance;
17 import javax.persistence.InheritanceType;
18 import javax.persistence.FetchType;
19 import javax.persistence.ManyToMany;
20 import javax.persistence.ManyToOne;
21 import javax.persistence.OneToMany;
22 import javax.xml.bind.annotation.XmlElement;
23 import javax.xml.bind.annotation.XmlElementWrapper;
24 import javax.xml.bind.annotation.XmlIDREF;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import javax.xml.bind.annotation.XmlSchemaType;
27 import javax.xml.bind.annotation.XmlTransient;
28 import javax.xml.bind.annotation.XmlType;
29
30 import org.apache.log4j.Logger;
31 import org.hibernate.annotations.Cascade;
32 import org.hibernate.annotations.CascadeType;
33
34 import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
35 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
36
37 /**
38 * The (abstract) class representing a typification of one or several {@link TaxonNameBase taxon names}.<BR>
39 * All taxon names which have a {@link Rank rank} "species aggregate" or lower
40 * can only be typified by specimens (a {@link SpecimenTypeDesignation specimen type designation}), but taxon
41 * names with a higher rank might be typified by an other taxon name with
42 * rank "species" or "genus" (a {@link NameTypeDesignation name type designation}).
43 *
44 * @see TaxonNameBase
45 * @see NameTypeDesignation
46 * @see SpecimenTypeDesignation
47 * @author a.mueller
48 * @created 07.08.2008
49 * @version 1.0
50 */
51 @XmlRootElement(name = "TypeDesignationBase")
52 @XmlType(name = "TypeDesignationBase", propOrder = {
53 "typifiedNames",
54 "homotypicalGroup",
55 "isNotDesignated"
56 })
57 @Entity
58 //@Audited
59 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
60 public abstract class TypeDesignationBase extends ReferencedEntityBase implements ITypeDesignation {
61 private static final Logger logger = Logger.getLogger(TypeDesignationBase.class);
62
63
64 @XmlElement(name = "IsNotDesignated")
65 private boolean isNotDesignated;
66
67 @XmlElementWrapper(name = "TypifiedNames")
68 @XmlElement(name = "TypifiedName")
69 @XmlIDREF
70 @XmlSchemaType(name = "IDREF")
71 // Need these references (bidirectional) to fill table TypeDesignationBase_TaxonNameBase
72 private Set<TaxonNameBase> typifiedNames = new HashSet<TaxonNameBase>();
73
74 @XmlElement(name = "HomotypicalGroup")
75 @XmlIDREF
76 @XmlSchemaType(name = "IDREF")
77 private HomotypicalGroup homotypicalGroup;
78
79 // **************** CONSTRUCTOR *************************************/
80
81 /**
82 * Class constructor: creates a new empty type designation.
83 *
84 * @see #TypeDesignationBase(ReferenceBase, String, String, Boolean)
85 */
86 protected TypeDesignationBase(){
87 super();
88 }
89
90 /**
91 * Class constructor: creates a new type designation
92 * (including its {@link ReferenceBase reference source} and eventually
93 * the taxon name string originally used by this reference when establishing
94 * the former designation).
95 *
96 * @param citation the reference source for the new designation
97 * @param citationMicroReference the string with the details describing the exact localisation within the reference
98 * @param originalNameString the taxon name string used originally in the reference source for the new designation
99 * @param isNotDesignated the boolean flag indicating whether there is no type at all for
100 * <i>this</i> type designation
101 * @see #TypeDesignationBase()
102 * @see #isNotDesignated()
103 * @see TaxonNameBase#getTypeDesignations()
104 */
105 protected TypeDesignationBase(ReferenceBase citation, String citationMicroReference, String originalNameString, boolean isNotDesignated){
106 super(citation, citationMicroReference, originalNameString);
107 this.isNotDesignated = isNotDesignated;
108 }
109
110
111 // **************** METHODS *************************************/
112
113
114 /* (non-Javadoc)
115 * @see eu.etaxonomy.cdm.model.name.ITypeDesignation#getHomotypicalGroup()
116 */
117 /**
118 * Returns the {@link HomotypicalGroup homotypical group} to which all (in <i>this</i>
119 * type designation) typified {@link TaxonNameBase taxon names} belong.
120 *
121 * @see #getTypifiedNames()
122 */
123 @ManyToOne(fetch = FetchType.LAZY)
124 @Cascade({CascadeType.SAVE_UPDATE})
125 public HomotypicalGroup getHomotypicalGroup() {
126 return homotypicalGroup;
127 }
128
129 @Deprecated //for hibernate use only
130 private void setHomotypicalGroup(HomotypicalGroup homotypicalGroup) {
131 this.homotypicalGroup = homotypicalGroup;
132 }
133
134 /* (non-Javadoc)
135 * @see eu.etaxonomy.cdm.model.name.ITypeDesignation#getTypifiedNames()
136 */
137 /**
138 * Returns the set of {@link TaxonNameBase taxon names} typified in <i>this</i>
139 * type designation. This is a subset of the taxon names belonging to the
140 * corresponding {@link #getHomotypicalGroup() homotypical group}.
141 */
142 @ManyToMany(fetch = FetchType.LAZY)
143 @Cascade({CascadeType.SAVE_UPDATE})
144 public Set<TaxonNameBase> getTypifiedNames() {
145 return typifiedNames;
146 }
147
148 /**
149 * Returns the boolean value "true" if it is known that a type does not
150 * exist and therefore the {@link TaxonNameBase taxon name} to which <i>this</i>
151 * type designation is assigned must still be typified. Two
152 * cases must be differentiated: <BR><ul>
153 * <li> a) it is unknown whether a type exists and
154 * <li> b) it is known that no type exists
155 * </ul>
156 * If a) is true there should be no TypeDesignation instance at all
157 * assigned to the "typified" taxon name.<BR>
158 * If b) is true there should be a TypeDesignation instance with the
159 * flag isNotDesignated set. The typeName attribute, in case of a
160 * {@link NameTypeDesignation name type designation}, or the typeSpecimen attribute,
161 * in case of a {@link SpecimenTypeDesignation specimen type designation}, should then be "null".
162 */
163 public boolean isNotDesignated() {
164 return isNotDesignated;
165 }
166
167 /**
168 * @see #isNotDesignated()
169 */
170 public void setNotDesignated(boolean isNotDesignated) {
171 this.isNotDesignated = isNotDesignated;
172 }
173
174
175 @Deprecated //for hibernate use only
176 private void setTypifiedNames(Set<TaxonNameBase> typifiedNames) {
177 this.typifiedNames = typifiedNames;
178 }
179
180 @Deprecated //for bidirectional use only
181 protected void addTypifiedName(TaxonNameBase taxonName){
182 this.typifiedNames.add(taxonName);
183 }
184
185
186 }