(no commit message)
[cdmlib.git] / cdmlibrary / src / main / java / eu / etaxonomy / cdm / model / common / RelationshipTermBase.java
1 package eu.etaxonomy.cdm.model.common;
2
3 import java.util.Set;
4
5 import javax.persistence.Entity;
6 import javax.persistence.Inheritance;
7 import javax.persistence.InheritanceType;
8 import javax.persistence.OneToMany;
9 import javax.persistence.Transient;
10
11 import org.apache.log4j.Logger;
12
13 @Entity
14 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
15 public abstract class RelationshipTermBase extends EnumeratedTermBase {
16 static Logger logger = Logger.getLogger(RelationshipTermBase.class);
17
18 private boolean symmetric;
19 private boolean transitive;
20 private Set<Representation> inverseRepresentations;
21
22 public RelationshipTermBase(String term, String label, Enumeration enumeration, boolean symmetric, boolean transitive) {
23 super(term, label, enumeration);
24 setSymmetric(symmetric);
25 setTransitive(transitive);
26 }
27
28
29 public boolean isSymmetric() {
30 return symmetric;
31 }
32 public void setSymmetric(boolean symmetric) {
33 this.symmetric = symmetric;
34 }
35
36 public boolean isTransitive() {
37 return transitive;
38 }
39 public void setTransitive(boolean transitive) {
40 this.transitive = transitive;
41 }
42
43
44 @OneToMany
45 public Set<Representation> getInverseRepresentations() {
46 return inverseRepresentations;
47 }
48 protected void setInverseRepresentations(
49 Set<Representation> inverseRepresentations) {
50 this.inverseRepresentations = inverseRepresentations;
51 }
52 public void addRepresentation(Representation representation) {
53 this.inverseRepresentations.add(representation);
54 }
55 public void removeRepresentation(Representation representation) {
56 this.inverseRepresentations.remove(representation);
57 }
58
59 @Transient
60 public Representation getInverseRepresentation(Language lang) {
61 Representation result = null;
62 if (this.isSymmetric()){
63 for (Representation repr : this.getRepresentations()){
64 if (repr.getLanguage() == lang){
65 result = repr;
66 }
67 }
68 }else{
69 for (Representation repr : this.getInverseRepresentations()){
70 if (repr.getLanguage() == lang){
71 result = repr;
72 }
73 }
74 }
75 return result;
76 }
77 }