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