more tests and features for #476: Implement free-text search methods for TaxonBase...
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / description / TaxonNameDescription.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.description;
11
12 import javax.persistence.Entity;
13 import javax.persistence.FetchType;
14 import javax.persistence.ManyToOne;
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlIDREF;
19 import javax.xml.bind.annotation.XmlRootElement;
20 import javax.xml.bind.annotation.XmlSchemaType;
21 import javax.xml.bind.annotation.XmlType;
22
23 import org.apache.log4j.Logger;
24 import org.hibernate.annotations.Cascade;
25 import org.hibernate.annotations.CascadeType;
26 import org.hibernate.envers.Audited;
27 import org.hibernate.search.annotations.Indexed;
28 import org.springframework.beans.factory.annotation.Configurable;
29
30 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
31 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
32 import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
33 import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
34
35 /**
36 * This class represents all piece of information (not ruled by a {@link NomenclaturalCode nomenclatural code})
37 * concerning a {@link TaxonNameBase taxon name} like for instance the content of its first
38 * publication (protolog) or a picture of this publication.
39 *
40 * @author a.mueller
41 * @version 1.0
42 * @created 08-Jul-2008
43 */
44 @XmlAccessorType(XmlAccessType.FIELD)
45 @XmlType(name = "TaxonNameDescription", propOrder = {
46 "taxonName"
47 })
48 @XmlRootElement(name = "TaxonNameDescription")
49 @Entity
50 @Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionBase")
51 @Audited
52 @Configurable
53 public class TaxonNameDescription extends DescriptionBase<IIdentifiableEntityCacheStrategy<TaxonNameDescription>> implements Cloneable{
54 private static final long serialVersionUID = -7349160369642038687L;
55 @SuppressWarnings("unused")
56 private static final Logger logger = Logger.getLogger(TaxonNameDescription.class);
57
58 @XmlElement(name="TaxonName")
59 @XmlIDREF
60 @XmlSchemaType(name="IDREF")
61 @ManyToOne(fetch = FetchType.LAZY)
62 // @JoinColumn(name="taxonName_id")
63 @Cascade(CascadeType.SAVE_UPDATE)
64 private TaxonNameBase<?,?> taxonName;
65
66 /**
67 * Creates a new taxon name description instance for the given {@link TaxonNameBase name}.
68 * The new taxon name description will be also added to the {@link TaxonNameBase#getDescriptions() set of descriptions}
69 * assigned to the given name.
70 *
71 * @see #NewInstance()
72 */
73 public static TaxonNameDescription NewInstance(TaxonNameBase name){
74 TaxonNameDescription description = new TaxonNameDescription();
75 name.addDescription(description);
76 return description;
77 }
78
79 /**
80 * Class constructor: creates a new empty taxon name description instance.
81 */
82 public TaxonNameDescription() {
83 super();
84 this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy();
85 }
86
87 /**
88 * Creates a new empty taxon name description instance.
89 */
90 public static TaxonNameDescription NewInstance(){
91 return new TaxonNameDescription();
92 }
93
94 /**
95 * Returns the {@link TaxonNameBase taxon name} to which <i>this</i> taxon name description
96 * provides additional information not ruled by a {@link NomenclaturalCode nomenclatural code}.
97 */
98 public TaxonNameBase<?,?> getTaxonName() {
99 return taxonName;
100 }
101
102
103 //*********************** CLONE ********************************************************/
104
105 /**
106 * Clones <i>this</i> taxon name description. This is a shortcut that enables to create
107 * a new instance that differs only slightly from <i>this</i> taxon name description by
108 * modifying only some of the attributes.
109 *
110 * @see eu.etaxonomy.cdm.model.description.DescriptionBase#clone()
111 * @see java.lang.Object#clone()
112 */
113 @Override
114 public Object clone() {
115 TaxonNameDescription result;
116 result = (TaxonNameDescription)super.clone();
117 //no changes to: taxonName
118 return result;
119 }
120 }