Opportunity to omit term loading during DB initialization.
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / description / DescriptionElementBase.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
13 import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;
14 import eu.etaxonomy.cdm.model.media.IMediaEntity;
15 import eu.etaxonomy.cdm.model.media.Media;
16 import eu.etaxonomy.cdm.model.common.Language;
17 import eu.etaxonomy.cdm.model.common.LanguageString;
18
19 import eu.etaxonomy.cdm.model.common.MultilanguageText;
20 import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
21
22 import org.apache.log4j.Logger;
23 import org.hibernate.annotations.Cascade;
24 import org.hibernate.annotations.CascadeType;
25
26 import java.util.*;
27
28 import javax.persistence.*;
29 import javax.xml.bind.annotation.XmlAccessType;
30 import javax.xml.bind.annotation.XmlAccessorType;
31 import javax.xml.bind.annotation.XmlElement;
32 import javax.xml.bind.annotation.XmlElementWrapper;
33 import javax.xml.bind.annotation.XmlIDREF;
34 import javax.xml.bind.annotation.XmlSchemaType;
35 import javax.xml.bind.annotation.XmlType;
36 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
37
38 /**
39 * The upmost (abstract) class for a description element of a specimen
40 * or of a taxon. A concrete description element assigns descriptive data to
41 * the feature. As experts use the word feature for the property itself but not
42 * for the actual description naming this class FeatureBase would make no sense.
43 *
44 *
45 * @author m.doering
46 * @version 1.0
47 * @created 08-Nov-2007 13:06:24
48 */
49 @XmlAccessorType(XmlAccessType.FIELD)
50 @XmlType(name = "DescriptionElementBase", propOrder = {
51 "feature",
52 "modifiers",
53 "modifyingText",
54 "media"
55 })
56 @Entity
57 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
58 public abstract class DescriptionElementBase extends ReferencedEntityBase implements IMediaEntity{
59 private static final Logger logger = Logger.getLogger(DescriptionElementBase.class);
60
61 protected DescriptionElementBase(){
62 }
63
64 protected DescriptionElementBase(Feature feature){
65 if (feature == null){
66 feature = Feature.UNKNOWN();
67 }
68 this.feature = feature;
69 }
70
71 //type, category of information. In structured descriptions characters
72 @XmlElement(name = "Feature")
73 @XmlIDREF
74 @XmlSchemaType(name = "IDREF")
75 private Feature feature;
76
77 @XmlElementWrapper(name = "Modifiers")
78 @XmlElement(name = "Modifier")
79 private Set<Modifier> modifiers = new HashSet<Modifier>();
80
81 @XmlElement(name = "ModifyingText")
82 @XmlJavaTypeAdapter(MultilanguageTextAdapter.class)
83 private MultilanguageText modifyingText;
84
85 @XmlElementWrapper(name = "Media")
86 @XmlElement(name = "Medium")
87 private Set<Media> media = new HashSet<Media>();
88
89
90 @OneToMany
91 @Cascade({CascadeType.SAVE_UPDATE})
92 public Set<Media> getMedia(){
93 return this.media;
94 }
95 protected void setMedia(Set<Media> media) {
96 this.media = media;
97 }
98 public void addMedia(Media media){
99 this.media.add(media);
100 }
101 public void removeMedia(Media media){
102 this.media.remove(media);
103 }
104
105
106 /**
107 * Same as getFeature()
108 * @see getFeature()
109 * @return
110 */
111 @Transient
112 public Feature getType(){
113 return this.getFeature();
114 }
115 /**
116 * Same as setFeature(Feature feature)
117 * @see setFeature(Feature feature)
118 * @param type
119 */
120 public void setType(Feature type){
121 this.setFeature(type);
122 }
123
124 @ManyToOne
125 @Cascade(CascadeType.SAVE_UPDATE)
126 public Feature getFeature(){
127 return this.feature;
128 }
129 public void setFeature(Feature feature){
130 this.feature = feature;
131 }
132
133
134 @OneToMany
135 public Set<Modifier> getModifiers(){
136 return this.modifiers;
137 }
138 protected void setModifiers(Set<Modifier> modifiers){
139 this.modifiers = modifiers;
140 }
141 public void addModifier(Modifier modifier){
142 this.modifiers.add(modifier);
143 }
144 public void removeModifier(Modifier modifier){
145 this.modifiers.remove(modifier);
146 }
147
148
149 public MultilanguageText getModifyingText(){
150 return this.modifyingText;
151 }
152 protected void setModifyingText(MultilanguageText modifyingText){
153 this.modifyingText = modifyingText;
154 }
155 public LanguageString addModifyingText(LanguageString description){
156 return this.modifyingText.add(description);
157 }
158 public LanguageString addModifyingText(String text, Language language){
159 return this.modifyingText.put(language, LanguageString.NewInstance(text, language));
160 }
161 public LanguageString removeModifyingText(Language language){
162 return this.modifyingText.remove(language);
163 }
164 }