1 package eu
.etaxonomy
.cdm
.model
.common
;
3 import java
.util
.HashSet
;
6 import javax
.persistence
.FetchType
;
7 import javax
.persistence
.MappedSuperclass
;
8 import javax
.persistence
.OneToMany
;
9 import javax
.persistence
.Transient
;
11 import javax
.xml
.bind
.annotation
.XmlAccessType
;
12 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
13 import javax
.xml
.bind
.annotation
.XmlElement
;
14 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
15 import javax
.xml
.bind
.annotation
.XmlRootElement
;
16 import javax
.xml
.bind
.annotation
.XmlTransient
;
17 import javax
.xml
.bind
.annotation
.XmlType
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.hibernate
.annotations
.Cascade
;
21 import org
.hibernate
.annotations
.CascadeType
;
23 @XmlAccessorType(XmlAccessType
.FIELD
)
24 @XmlType(name
= "TermBase", propOrder
= {
28 @XmlRootElement(name
= "TermBase")
30 public abstract class TermBase
extends VersionableEntity
{
31 private static final Logger logger
= Logger
.getLogger(TermBase
.class);
33 @XmlElement(name
= "URI")
36 @XmlElementWrapper(name
= "Representations")
37 @XmlElement(name
= "Representation")
38 private Set
<Representation
> representations
= new HashSet
<Representation
>();
43 public TermBase(String term
, String label
, String labelAbbrev
) {
45 this.addRepresentation(new Representation(term
, label
, labelAbbrev
, Language
.DEFAULT()) );
48 @OneToMany(fetch
=FetchType
.LAZY
)
49 @Cascade( { CascadeType
.SAVE_UPDATE
, CascadeType
.DELETE
})
50 public Set
<Representation
> getRepresentations() {
51 return this.representations
;
54 public void setRepresentations(Set
<Representation
> representations
) {
55 this.representations
= representations
;
58 public void addRepresentation(Representation representation
) {
59 this.representations
.add(representation
);
62 public void removeRepresentation(Representation representation
) {
63 this.representations
.remove(representation
);
67 public Representation
getRepresentation(Language lang
) {
68 for (Representation repr
: representations
){
69 Language reprLanguage
= repr
.getLanguage();
70 if (reprLanguage
!= null && reprLanguage
.equals(lang
)){
77 public String
getUri() {
81 public void setUri(String uri
) {
86 public String
getLabel() {
87 if(getLabel(Language
.DEFAULT())!=null){
88 Representation repr
= getRepresentation(Language
.DEFAULT());
89 return (repr
== null)?
null :repr
.getLabel();
91 for (Representation r
: representations
){
95 return super.getUuid().toString();
99 public String
getLabel(Language lang
) {
100 Representation repr
= this.getRepresentation(lang
);
101 return (repr
== null) ?
null : repr
.getLabel();
105 public String
getDescription() {
106 return this.getDescription(Language
.DEFAULT());
110 public String
getDescription(Language lang
) {
111 Representation repr
= this.getRepresentation(lang
);
112 return (repr
== null) ?
null :repr
.getDescription();
116 public boolean equals(Object obj
) {
120 if (TermBase
.class.isAssignableFrom(obj
.getClass())){
121 TermBase dtb
= (TermBase
)obj
;
122 if (dtb
.getUuid().equals(this.getUuid())){
130 public String
toString() {
131 //FIXME make toString save as explained in CdmBase.toString
132 return super.toString()+" "+this.getLabel();