06877b14d1d0ffc8d3dd47ae6de0697f5e560e8f
[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.FieldBridge;
28 import org.springframework.beans.factory.annotation.Configurable;
29
30 import eu.etaxonomy.cdm.hibernate.search.NotNullAwareIdBridge;
31 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
32 import eu.etaxonomy.cdm.model.name.TaxonName;
33 import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
34 import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
35
36 /**
37 * This class represents all piece of information (not ruled by a {@link NomenclaturalCode nomenclatural code})
38 * concerning a {@link TaxonName taxon name} like for instance the content of its first
39 * publication (protolog) or a picture of this publication.
40 *
41 * @author a.mueller
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 disabled to reduce clutter in indexes, since this type is not used by any search
51 //@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionBase")
52 @Audited
53 @Configurable
54 public class TaxonNameDescription extends DescriptionBase<IIdentifiableEntityCacheStrategy<TaxonNameDescription>> implements Cloneable{
55 private static final long serialVersionUID = -7349160369642038687L;
56 @SuppressWarnings("unused")
57 private static final Logger logger = Logger.getLogger(TaxonNameDescription.class);
58
59 @XmlElement(name="TaxonName")
60 @XmlIDREF
61 @XmlSchemaType(name="IDREF")
62 @ManyToOne(fetch = FetchType.LAZY)
63 @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
64 @FieldBridge(impl=NotNullAwareIdBridge.class)
65 private TaxonName<?,?> taxonName;
66
67 //******************* FACTORY ********************************************/
68
69 /**
70 * Creates a new empty taxon name description instance.
71 */
72 public static TaxonNameDescription NewInstance(){
73 return new TaxonNameDescription();
74 }
75
76
77 /**
78 * Creates a new taxon name description instance for the given {@link TaxonName name}.
79 * The new taxon name description will be also added to the {@link TaxonName#getDescriptions() set of descriptions}
80 * assigned to the given name.
81 *
82 * @see #NewInstance()
83 */
84 public static TaxonNameDescription NewInstance(TaxonName name){
85 TaxonNameDescription description = new TaxonNameDescription();
86 name.addDescription(description);
87 return description;
88 }
89
90 // ********************** CONSTRUCTOR ***************************************/
91
92 /**
93 * Class constructor: creates a new empty taxon name description instance.
94 */
95 private TaxonNameDescription() {
96 super();
97 this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy();
98 }
99
100 //************************* GETTER /SETTER ***************************************/
101
102 /**
103 * Returns the {@link TaxonName taxon name} to which <i>this</i> taxon name description
104 * provides additional information not ruled by a {@link NomenclaturalCode nomenclatural code}.
105 */
106 public TaxonName<?,?> getTaxonName() {
107 return taxonName;
108 }
109
110
111 //*********************** CLONE ********************************************************/
112
113 /**
114 * Clones <i>this</i> taxon name description. This is a shortcut that enables to create
115 * a new instance that differs only slightly from <i>this</i> taxon name description by
116 * modifying only some of the attributes.
117 *
118 * @see eu.etaxonomy.cdm.model.description.DescriptionBase#clone()
119 * @see java.lang.Object#clone()
120 */
121 @Override
122 public Object clone() {
123 TaxonNameDescription result;
124 result = (TaxonNameDescription)super.clone();
125 //no changes to: taxonName
126 return result;
127 }
128 }