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);
40 private String titleCache
;
41 //if true titleCache will not be automatically generated/updated
42 private boolean protectedTitleCache
;
43 private Set
<Rights
> rights
= new HashSet();
44 private Set
<Extension
> extensions
= new HashSet();
45 private Set
<OriginalSource
> sources
= new HashSet();
48 public String
getLsid(){
51 public void setLsid(String lsid
){
55 public abstract String
generateTitle();
57 public String
getTitleCache(){
58 if (protectedTitleCache
){
59 return this.titleCache
;
61 // is title dirty, i.e. equal NULL?
62 if (titleCache
== null){
63 this.titleCache
= generateTitle();
67 public void setTitleCache(String titleCache
){
68 this.titleCache
= titleCache
;
69 this.setProtectedTitleCache(true);
71 public void setTitleCache(String titleCache
, boolean protectCache
){
72 this.titleCache
= titleCache
;
73 this.setProtectedTitleCache(protectCache
);
77 @Cascade({CascadeType
.SAVE_UPDATE
})
78 public Set
<Rights
> getRights(){
82 protected void setRights(Set
<Rights
> rights
) {
85 public void addRights(Rights right
){
86 this.rights
.add(right
);
88 public void removeRights(Rights right
){
89 this.rights
.remove(right
);
92 @OneToMany//(mappedBy="extendedObj")
93 @Cascade({CascadeType
.SAVE_UPDATE
})
94 public Set
<Extension
> getExtensions(){
95 return this.extensions
;
97 protected void setExtensions(Set
<Extension
> extensions
) {
98 this.extensions
= extensions
;
100 public void addExtension(Extension extension
){
101 this.extensions
.add(extension
);
103 public void removeExtension(Extension extension
){
104 this.extensions
.remove(extension
);
108 public boolean isProtectedTitleCache() {
109 return protectedTitleCache
;
112 public void setProtectedTitleCache(boolean protectedTitleCache
) {
113 this.protectedTitleCache
= protectedTitleCache
;
117 @OneToMany //(mappedBy="sourcedObj")
118 @Cascade({CascadeType
.SAVE_UPDATE
})
119 public Set
<OriginalSource
> getSources() {
123 protected void setSources(Set
<OriginalSource
> sources
) {
124 this.sources
= sources
;
127 public void addSource(OriginalSource source
) {
128 this.sources
.add(source
);
131 public void removeSource(OriginalSource source
) {
132 this.sources
.remove(source
);
135 public String
toString() {
136 return this.getTitleCache();