Project

General

Profile

Download (7.27 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 *
3
 */
4
package eu.etaxonomy.cdm.model.common;
5

    
6
import javax.persistence.Entity;
7
import javax.persistence.FetchType;
8
import javax.persistence.ManyToOne;
9
import javax.xml.bind.annotation.XmlAccessType;
10
import javax.xml.bind.annotation.XmlAccessorType;
11
import javax.xml.bind.annotation.XmlElement;
12
import javax.xml.bind.annotation.XmlIDREF;
13
import javax.xml.bind.annotation.XmlSchemaType;
14
import javax.xml.bind.annotation.XmlType;
15

    
16
import org.hibernate.envers.Audited;
17

    
18
import eu.etaxonomy.cdm.model.agent.AgentBase;
19
import eu.etaxonomy.cdm.model.media.Media;
20
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
21
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
22
import eu.etaxonomy.cdm.model.reference.Reference;
23
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
24

    
25
/**
26
 * This class represents a link to another CDM Base class from within a text.
27
 * If a text, e.g. a LanguageString links parts of its text to an other CDM Base
28
 * one may create a tag around the according text including id and uuid as attributes
29
 * and adding an IntextReference to the LanguageString. The IntextReference then points
30
 * to the according CdmBase.
31
 * This way we may keep referential integrity and we may also support correct
32
 * deduplication or deletion of the referenced objects.
33
 *
34
 * @see #4706
35
 *
36
 * @author a.mueller
37
 *
38
 */
39
@XmlAccessorType(XmlAccessType.FIELD)
40
@XmlType(name = "IntextReference", propOrder = {
41
    "taxonName",
42
    "taxon",
43
    "occurrence",
44
    "agent",
45
    "reference",
46
    "media",
47
    "languageString",
48
    "annotation",
49
    "startPos",
50
    "endPos"
51
})
52
@Entity
53
@Audited
54
public class IntextReference extends VersionableEntity {
55
	private static final long serialVersionUID = -7002541566256975424L;
56

    
57
    @XmlElement(name = "TaxonName")
58
    @XmlIDREF
59
    @XmlSchemaType(name = "IDREF")
60
    @ManyToOne(fetch = FetchType.LAZY)
61
	private TaxonNameBase<?,?> taxonName;
62

    
63
    @XmlElement(name = "Taxon")
64
    @XmlIDREF
65
    @XmlSchemaType(name = "IDREF")
66
    @ManyToOne(fetch = FetchType.LAZY)
67
	private TaxonBase<?> taxon;
68

    
69
    @XmlElement(name = "Occurrence")
70
    @XmlIDREF
71
    @XmlSchemaType(name = "IDREF")
72
    @ManyToOne(fetch = FetchType.LAZY)
73
	private SpecimenOrObservationBase<?> occurrence;
74

    
75
    @XmlElement(name = "Agent")
76
    @XmlIDREF
77
    @XmlSchemaType(name = "IDREF")
78
    @ManyToOne(fetch = FetchType.LAZY)
79
	private AgentBase<?> agent;
80

    
81
    @XmlElement(name = "Reference")
82
    @XmlIDREF
83
    @XmlSchemaType(name = "IDREF")
84
    @ManyToOne(fetch = FetchType.LAZY)
85
	private Reference<?> reference;
86

    
87
    @XmlElement(name = "Media")
88
    @XmlIDREF
89
    @XmlSchemaType(name = "IDREF")
90
    @ManyToOne(fetch = FetchType.LAZY)
91
	private Media media;
92

    
93
    //TODO or do we want to link to LanguageString Base??
94
    @XmlElement(name = "LanguageString")
95
    @XmlIDREF
96
    @XmlSchemaType(name = "IDREF")
97
    @ManyToOne(fetch = FetchType.LAZY)
98
    private LanguageString languageString;
99

    
100
    //TODO or do we want to link to LanguageString Base??
101
    @XmlElement(name = "Annotation")
102
    @XmlIDREF
103
    @XmlSchemaType(name = "IDREF")
104
    @ManyToOne(fetch = FetchType.LAZY)
105
    private Annotation annotation;
106

    
107
	private int startPos;
108

    
109
	private int endPos;
110

    
111
// ***************** FACTORY METHOD ***********************************
112

    
113
	public static IntextReference NewTaxonNameInstance(TaxonNameBase<?,?> taxonName, LanguageStringBase languageString, int start, int end){
114
		return new IntextReference(taxonName, null, null, null, null, null, languageString, start, end);
115
	}
116

    
117
	public static IntextReference NewTaxonInstance(TaxonBase<?> taxon, LanguageStringBase languageString, int start, int end){
118
		return new IntextReference(null, taxon, null, null, null, null, languageString, start, end);
119
	}
120

    
121
	public static IntextReference NewOccurrenceInstance(SpecimenOrObservationBase<?> occurrence, LanguageStringBase languageString, int start, int end){
122
		return new IntextReference(null, null, occurrence, null, null, null, languageString, start, end);
123
	}
124

    
125
	public static IntextReference NewAgentInstance(AgentBase<?> agent, LanguageStringBase languageString, int start, int end){
126
		return new IntextReference(null, null, null, agent, null, null, languageString, start, end);
127
	}
128

    
129
	public static IntextReference NewReferenceInstance(Reference<?> reference, LanguageStringBase languageString, int start, int end){
130
		return new IntextReference(null, null, null, null, reference, null, languageString, start, end);
131
	}
132

    
133
	public static IntextReference NewReferenceInstance(Media media, LanguageStringBase languageString, int start, int end){
134
		return new IntextReference(null, null, null, null, null, media, languageString, start, end);
135
	}
136

    
137
//********************** CONSTRUCTOR ********************************************/
138

    
139
	/**
140
	 * @deprecated for internal use only
141
	 */
142
	@Deprecated //for hibernate use only
143
	private IntextReference(){}
144

    
145
	private IntextReference(TaxonNameBase<?, ?> taxonName, TaxonBase<?> taxon,
146
				SpecimenOrObservationBase<?> occurrence, AgentBase<?> agent,
147
				Reference<?> reference, Media media, LanguageStringBase languageString, int start, int end) {
148
			super();
149
			this.taxonName = taxonName;
150
			this.taxon = taxon;
151
			this.occurrence = occurrence;
152
			this.agent = agent;
153
			this.reference = reference;
154
			if (languageString != null && languageString.isInstanceOf(LanguageString.class)){
155
				this.languageString = CdmBase.deproxy(languageString, LanguageString.class);
156
				this.languageString.addIntextReference(this);
157
			}else if (languageString != null && languageString.isInstanceOf(Annotation.class)){
158
				this.annotation = CdmBase.deproxy(languageString, Annotation.class);
159
				this.annotation.addIntextReference(this);
160
			}
161
			this.startPos = start;
162
			this.endPos = end;
163
	}
164

    
165

    
166
// ****************    GETTER / SETTER ******************************************/
167

    
168
	public TaxonNameBase<?, ?> getTaxonName() {
169
		return taxonName;
170
	}
171
	public void setTaxonName(TaxonNameBase<?, ?> taxonName) {
172
		this.taxonName = taxonName;
173
	}
174

    
175

    
176
	public TaxonBase<?> getTaxon() {
177
		return taxon;
178
	}
179
	public void setTaxon(TaxonBase<?> taxon) {
180
		this.taxon = taxon;
181
	}
182

    
183
	public SpecimenOrObservationBase<?> getOccurrence() {
184
		return occurrence;
185
	}
186
	public void setOccurrence(SpecimenOrObservationBase<?> occurrence) {
187
		this.occurrence = occurrence;
188
	}
189

    
190
	public AgentBase<?> getAgent() {
191
		return agent;
192
	}
193
	public void setAgent(AgentBase<?> agent) {
194
		this.agent = agent;
195
	}
196

    
197
	public Reference<?> getReference() {
198
		return reference;
199
	}
200
	public void setReference(Reference<?> reference) {
201
		this.reference = reference;
202
	}
203

    
204

    
205

    
206
	public Media getMedia() {
207
		return media;
208
	}
209
	public void setMedia(Media media) {
210
		this.media = media;
211
	}
212

    
213
	public LanguageString getLanguageString() {
214
		return languageString;
215
	}
216
	public void setLanguageString(LanguageString languageString) {
217
		this.languageString = languageString;
218
	}
219

    
220
	public Annotation getAnnotation() {
221
		return annotation;
222
	}
223

    
224
	public void setAnnotation(Annotation annotation) {
225
		this.annotation = annotation;
226
	}
227

    
228
	public int getStartPos() {
229
		return startPos;
230
	}
231
	public void setStartPos(int startPos) {
232
		this.startPos = startPos;
233
	}
234

    
235
	public int getEndPos() {
236
		return endPos;
237
	}
238
	public void setEndPos(int endPos) {
239
		this.endPos = endPos;
240
	}
241

    
242
}
(39-39/72)