2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.common
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.hibernate
.annotations
.Cascade
;
15 import org
.hibernate
.annotations
.CascadeType
;
18 import java
.util
.HashSet
;
21 import javax
.persistence
.*;
24 * Superclass for the primary CDM classes that can be referenced from outside via LSIDs and contain a simple generated title string as a label for human reading.
25 * All subclasses inherit the ability to store additional properties that are stored as {@link Extension Extensions}, basically a string value with a type term.
26 * Any number of right statements can be attached as well as multiple {@link OriginalSource} objects.
27 * Original sources carry a reference to the source, an ID within that source and the original title/label of this object as it was used in that source (originalNameString).
28 * A Taxon for example that was taken from 2 sources like FaunaEuropaea and IPNI would have two originalSource objects.
29 * The originalSource representing that taxon as it was found in IPNI would contain IPNI as the reference, the IPNI id of the taxon and the name of the taxon exactly as it was used in IPNI.
33 * @created 08-Nov-2007 13:06:27
36 public abstract class IdentifiableEntity
<T
extends IdentifiableEntity
> extends AnnotatableEntity
<T
> implements IOriginalSource
{
37 static Logger logger
= Logger
.getLogger(IdentifiableEntity
.class);
39 public final boolean PROTECTED
= true;
40 public final boolean NOT_PROTECTED
= true;
43 private String titleCache
;
44 //if true titleCache will not be automatically generated/updated
45 private boolean protectedTitleCache
;
46 private Set
<Rights
> rights
= new HashSet
<Rights
>();
47 private Set
<Extension
> extensions
= new HashSet
<Extension
>();
48 private Set
<OriginalSource
> sources
= new HashSet
<OriginalSource
>();
51 public String
getLsid(){
54 public void setLsid(String lsid
){
58 public abstract String
generateTitle();
60 public String
getTitleCache(){
61 if (protectedTitleCache
){
62 return this.titleCache
;
64 // is title dirty, i.e. equal NULL?
65 if (titleCache
== null){
66 this.titleCache
= generateTitle();
70 public void setTitleCache(String titleCache
){
71 this.titleCache
= titleCache
;
72 this.setProtectedTitleCache(true);
74 public void setTitleCache(String titleCache
, boolean protectCache
){
75 this.titleCache
= titleCache
;
76 this.setProtectedTitleCache(protectCache
);
80 @Cascade({CascadeType
.SAVE_UPDATE
})
81 public Set
<Rights
> getRights(){
85 protected void setRights(Set
<Rights
> rights
) {
88 public void addRights(Rights right
){
89 this.rights
.add(right
);
91 public void removeRights(Rights right
){
92 this.rights
.remove(right
);
95 @OneToMany//(mappedBy="extendedObj")
96 @Cascade({CascadeType
.SAVE_UPDATE
})
97 public Set
<Extension
> getExtensions(){
98 return this.extensions
;
100 protected void setExtensions(Set
<Extension
> extensions
) {
101 this.extensions
= extensions
;
103 public void addExtension(Extension extension
){
104 this.extensions
.add(extension
);
106 public void removeExtension(Extension extension
){
107 this.extensions
.remove(extension
);
111 public boolean isProtectedTitleCache() {
112 return protectedTitleCache
;
115 public void setProtectedTitleCache(boolean protectedTitleCache
) {
116 this.protectedTitleCache
= protectedTitleCache
;
119 @OneToMany //(mappedBy="sourcedObj")
120 @Cascade({CascadeType
.SAVE_UPDATE
})
121 public Set
<OriginalSource
> getSources() {
124 protected void setSources(Set
<OriginalSource
> sources
) {
125 this.sources
= sources
;
127 public void addSource(OriginalSource source
) {
128 this.sources
.add(source
);
130 public void removeSource(OriginalSource source
) {
131 this.sources
.remove(source
);
134 private boolean executesToString
= false;
136 public String
toString() {
138 if (executesToString
){
139 result
= super.toString();
141 //avoid recursiv toString call
142 executesToString
= true;
143 result
= this.getTitleCache();
144 executesToString
= false;