1 package eu
.etaxonomy
.cdm
.model
.common
;
3 import java
.util
.HashSet
;
6 import javax
.persistence
.FetchType
;
7 import javax
.persistence
.JoinTable
;
8 import javax
.persistence
.MappedSuperclass
;
9 import javax
.persistence
.OneToMany
;
10 import javax
.persistence
.Transient
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.hibernate
.annotations
.Cascade
;
14 import org
.hibernate
.annotations
.CascadeType
;
17 public abstract class TermBase
extends VersionableEntity
{
18 static Logger logger
= Logger
.getLogger(TermBase
.class);
21 private Set
<Representation
> representations
= new HashSet
<Representation
>();
26 public TermBase(String term
, String label
) {
28 this.addRepresentation(new Representation(term
, label
, Language
.DEFAULT()) );
31 @OneToMany//(fetch=FetchType.EAGER)
32 @Cascade( { CascadeType
.SAVE_UPDATE
, CascadeType
.DELETE
})
33 public Set
<Representation
> getRepresentations() {
34 return this.representations
;
37 public void setRepresentations(Set
<Representation
> representations
) {
38 this.representations
= representations
;
41 public void addRepresentation(Representation representation
) {
42 this.representations
.add(representation
);
45 public void removeRepresentation(Representation representation
) {
46 this.representations
.remove(representation
);
50 public Representation
getRepresentation(Language lang
) {
51 for (Representation repr
: representations
){
52 Language reprLanguage
= repr
.getLanguage();
53 if (reprLanguage
!= null && reprLanguage
.equals(lang
)){
60 public String
getUri() {
64 public void setUri(String uri
) {
69 public String
getLabel() {
70 if(getLabel(Language
.DEFAULT())!=null){
71 Representation repr
= getRepresentation(Language
.DEFAULT());
72 return (repr
== null)?
null :repr
.getLabel();
74 for (Representation r
: representations
){
78 return super.getUuid().toString();
82 public String
getLabel(Language lang
) {
83 Representation repr
= this.getRepresentation(lang
);
84 return (repr
== null) ?
null : repr
.getLabel();
88 public String
getDescription() {
89 return this.getDescription(Language
.DEFAULT());
93 public String
getDescription(Language lang
) {
94 Representation repr
= this.getRepresentation(lang
);
95 return (repr
== null) ?
null :repr
.getDescription();
99 public boolean equals(Object obj
) {
100 if (DefinedTermBase
.class.isAssignableFrom(obj
.getClass())){
101 DefinedTermBase dtb
= (DefinedTermBase
)obj
;
102 if (dtb
.getUuid().equals(this.getUuid())){
110 public String
toString() {
111 return super.toString()+" "+this.getLabel();