Media service added. Marshall FeatureNode and FeatureTree.
[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 @XmlIDREF
88 @XmlSchemaType(name = "IDREF")
89 private Set<Media> media = new HashSet<Media>();
90
91
92 @OneToMany
93 @Cascade({CascadeType.SAVE_UPDATE})
94 public Set<Media> getMedia(){
95 return this.media;
96 }
97 protected void setMedia(Set<Media> media) {
98 this.media = media;
99 }
100 public void addMedia(Media media){
101 this.media.add(media);
102 }
103 public void removeMedia(Media media){
104 this.media.remove(media);
105 }
106
107
108 /**
109 * Same as getFeature()
110 * @see getFeature()
111 * @return
112 */
113 @Transient
114 public Feature getType(){
115 return this.getFeature();
116 }
117 /**
118 * Same as setFeature(Feature feature)
119 * @see setFeature(Feature feature)
120 * @param type
121 */
122 public void setType(Feature type){
123 this.setFeature(type);
124 }
125
126 @ManyToOne
127 @Cascade(CascadeType.SAVE_UPDATE)
128 public Feature getFeature(){
129 return this.feature;
130 }
131 public void setFeature(Feature feature){
132 this.feature = feature;
133 }
134
135
136 @OneToMany
137 public Set<Modifier> getModifiers(){
138 return this.modifiers;
139 }
140 protected void setModifiers(Set<Modifier> modifiers){
141 this.modifiers = modifiers;
142 }
143 public void addModifier(Modifier modifier){
144 this.modifiers.add(modifier);
145 }
146 public void removeModifier(Modifier modifier){
147 this.modifiers.remove(modifier);
148 }
149
150
151 public MultilanguageText getModifyingText(){
152 return this.modifyingText;
153 }
154 protected void setModifyingText(MultilanguageText modifyingText){
155 this.modifyingText = modifyingText;
156 }
157 public LanguageString addModifyingText(LanguageString description){
158 return this.modifyingText.add(description);
159 }
160 public LanguageString addModifyingText(String text, Language language){
161 return this.modifyingText.put(language, LanguageString.NewInstance(text, language));
162 }
163 public LanguageString removeModifyingText(Language language){
164 return this.modifyingText.remove(language);
165 }
166 }