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.
9 package eu
.etaxonomy
.cdm
.model
.common
;
11 import javax
.persistence
.FetchType
;
12 import javax
.persistence
.MappedSuperclass
;
13 import javax
.persistence
.OneToOne
;
14 import javax
.persistence
.Transient
;
15 import javax
.xml
.bind
.annotation
.XmlAccessType
;
16 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
17 import javax
.xml
.bind
.annotation
.XmlElement
;
18 import javax
.xml
.bind
.annotation
.XmlIDREF
;
19 import javax
.xml
.bind
.annotation
.XmlRootElement
;
20 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
21 import javax
.xml
.bind
.annotation
.XmlType
;
23 import org
.apache
.commons
.lang3
.StringUtils
;
24 import org
.apache
.log4j
.Logger
;
25 import org
.hibernate
.annotations
.Cascade
;
26 import org
.hibernate
.annotations
.CascadeType
;
27 import org
.hibernate
.envers
.Audited
;
29 import eu
.etaxonomy
.cdm
.model
.reference
.NamedSource
;
30 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceType
;
31 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
34 * Abstract class for all objects that may have a reference
36 * @since 08-Nov-2007 13:06:47
38 @XmlAccessorType(XmlAccessType
.FIELD
)
39 @XmlType(name
= "SingleSourcedEntityBase", propOrder
= {
42 @XmlRootElement(name
= "SingleSourcedEntityBase")
45 public abstract class SingleSourcedEntityBase
46 extends AnnotatableEntity
{
48 static final long serialVersionUID
= 2035568689268762760L;
49 @SuppressWarnings("unused")
50 private static final Logger logger
= Logger
.getLogger(SingleSourcedEntityBase
.class);
52 //the source for this single sourced entity
53 @XmlElement(name
= "source")
55 @XmlSchemaType(name
= "IDREF")
56 @OneToOne(fetch
= FetchType
.LAZY
, orphanRemoval
=true)
57 @Cascade({CascadeType
.SAVE_UPDATE
,CascadeType
.MERGE
, CascadeType
.DELETE
})
58 private NamedSource source
;
60 // ************ CONSTRUCTOR ********************************************/
62 //for hibernate use only
63 protected SingleSourcedEntityBase() {
67 protected SingleSourcedEntityBase(Reference reference
, String microReference
,
68 String originalNameString
) {
70 this.setCitation(reference
);
71 this.setCitationMicroReference(microReference
);
72 if (StringUtils
.isNotEmpty(originalNameString
)){
73 getSource(true).setOriginalNameString(originalNameString
);
77 protected SingleSourcedEntityBase(NamedSource source
) {
81 //********************* GETTER / SETTER *******************************/
84 public String
getCitationMicroReference() {
85 return source
== null ?
null : this.source
.getCitationMicroReference();
87 public void setCitationMicroReference(String microReference
) {
88 this.getSource(true).setCitationMicroReference(isBlank(microReference
)?
null : microReference
);
93 public Reference
getCitation() {
94 return (this.source
== null) ?
null : source
.getCitation();
96 public void setCitation(Reference reference
) {
97 getSource(true).setCitation(reference
);
101 public NamedSource
getSource() {
104 public void setSource(NamedSource source
) {
105 this.source
= source
;
108 private void checkNullSource() {
109 if (this.source
!= null && this.source
.checkEmpty(true)){
114 private NamedSource
getSource(boolean createIfNotExist
){
115 if (this.source
== null && createIfNotExist
){
116 this.source
= NamedSource
.NewInstance(OriginalSourceType
.PrimaryTaxonomicSource
);
121 // **************** EMPTY ************************/
124 protected boolean checkEmpty(){
125 return super.checkEmpty()
126 && this.source
== null
130 //****************** CLONE ************************************************/
133 public SingleSourcedEntityBase
clone() throws CloneNotSupportedException
{
134 SingleSourcedEntityBase result
= (SingleSourcedEntityBase
)super.clone();
136 if (this.source
!= null){
137 result
.source
= source
.clone();
144 //*********************************** EQUALS *********************************************************/