(no commit message)
[cdmlib.git] / cdmlibrary / src / main / java / eu / etaxonomy / cdm / model / common / IdentifiableEntity.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.common;
11
12
13 import org.apache.log4j.Logger;
14 import org.hibernate.annotations.Cascade;
15 import org.hibernate.annotations.CascadeType;
16
17
18 import java.util.HashSet;
19 import java.util.Set;
20
21 import javax.persistence.*;
22
23 /**
24 * @author m.doering
25 * @version 1.0
26 * @created 08-Nov-2007 13:06:27
27 */
28 @MappedSuperclass
29 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
30 public abstract class IdentifiableEntity<T extends IdentifiableEntity> extends AnnotatableEntity<T> implements IOriginalSource {
31 static Logger logger = Logger.getLogger(IdentifiableEntity.class);
32
33 private String lsid;
34 private String titleCache;
35 //if true titleCache will not be automatically generated/updated
36 private boolean protectedTitleCache;
37 private Set<Rights> rights = new HashSet();
38 private Set<Extension> extensions = new HashSet();
39 private Set<OriginalSource> sources = new HashSet();
40
41 public IdentifiableEntity() {
42 super();
43 }
44
45
46 public String getLsid(){
47 return this.lsid;
48 }
49 public void setLsid(String lsid){
50 this.lsid = lsid;
51 }
52
53 public abstract String generateTitle();
54
55 public String getTitleCache(){
56 if (protectedTitleCache){
57 return this.titleCache;
58 }
59 // is title dirty, i.e. equal NULL?
60 if (titleCache == null){
61 this.titleCache = generateTitle();
62 }
63 return titleCache;
64 }
65 public void setTitleCache(String titleCache){
66 this.titleCache = titleCache;
67 this.setProtectedTitleCache(true);
68 }
69
70 @ManyToMany
71 @Cascade({CascadeType.SAVE_UPDATE})
72 public Set<Rights> getRights(){
73 return this.rights;
74 }
75
76 protected void setRights(Set<Rights> rights) {
77 this.rights = rights;
78 }
79 public void addRights(Rights right){
80 this.rights.add(right);
81 }
82 public void removeRights(Rights right){
83 this.rights.remove(right);
84 }
85
86 @OneToMany//(mappedBy="extendedObj")
87 @Cascade({CascadeType.SAVE_UPDATE})
88 public Set<Extension> getExtensions(){
89 return this.extensions;
90 }
91 protected void setExtensions(Set<Extension> extensions) {
92 this.extensions = extensions;
93 }
94 public void addExtension(Extension extension){
95 this.extensions.add(extension);
96 }
97 public void removeExtension(Extension extension){
98 this.extensions.remove(extension);
99 }
100
101
102 public boolean isProtectedTitleCache() {
103 return protectedTitleCache;
104 }
105
106 public void setProtectedTitleCache(boolean protectedTitleCache) {
107 this.protectedTitleCache = protectedTitleCache;
108 }
109
110
111 @OneToMany //(mappedBy="sourcedObj")
112 @Cascade({CascadeType.SAVE_UPDATE})
113 public Set<OriginalSource> getSources() {
114 return this.sources;
115 }
116
117 protected void setSources(Set<OriginalSource> sources) {
118 this.sources = sources;
119 }
120
121 public void addSource(OriginalSource source) {
122 this.sources.add(source);
123 }
124
125 public void removeSource(OriginalSource source) {
126 this.sources.remove(source);
127 }
128
129 }