Revision 2610e050
Added by Andreas Müller almost 7 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IdentifiableSource.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.model.common; |
|
12 |
|
|
13 |
import javax.persistence.Column; |
|
14 |
import javax.persistence.Entity; |
|
15 |
import javax.persistence.FetchType; |
|
16 |
import javax.persistence.JoinColumn; |
|
17 |
import javax.xml.bind.annotation.XmlElement; |
|
18 |
import javax.xml.bind.annotation.XmlIDREF; |
|
19 |
import javax.xml.bind.annotation.XmlSchemaType; |
|
20 |
import javax.xml.bind.annotation.XmlType; |
|
21 |
|
|
22 |
import org.apache.log4j.Logger; |
|
23 |
import org.hibernate.annotations.Any; |
|
24 |
|
|
25 |
import org.hibernate.envers.Audited; |
|
26 |
import org.hibernate.envers.NotAudited; |
|
27 |
|
|
28 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
29 |
|
|
30 |
/** |
|
31 |
* This class represents an {@link eu.etaxonomy.cdm.model.common.IOriginalSource IOriginalSource} |
|
32 |
* that can be used with {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity identifiable entity}. |
|
33 |
* |
|
34 |
* @see eu.etaxonomy.cdm.model.common.IOriginalSource |
|
35 |
* |
|
36 |
* @author a.mueller |
|
37 |
* @created 18.09.2009 |
|
38 |
* @version 1.0 |
|
39 |
*/ |
|
40 |
@XmlType(name = "IdentifiableSource", propOrder = { |
|
41 |
"sourcedObj" |
|
42 |
}) |
|
43 |
@Entity |
|
44 |
@Audited |
|
45 |
public class IdentifiableSource extends OriginalSourceBase<IdentifiableEntity>{ |
|
46 |
private static final long serialVersionUID = -8487673428764273806L; |
|
47 |
@SuppressWarnings("unused") |
|
48 |
private static final Logger logger = Logger.getLogger(IdentifiableSource.class); |
|
49 |
|
|
50 |
//********************************* FACTORY ********************************************************/ |
|
51 |
|
|
52 |
public static IdentifiableSource NewInstance(OriginalSourceType type){ |
|
53 |
return new IdentifiableSource(type); |
|
54 |
} |
|
55 |
|
|
56 |
public static IdentifiableSource NewDataImportInstance(String id){ |
|
57 |
IdentifiableSource result = new IdentifiableSource(OriginalSourceType.Import); |
|
58 |
result.setIdInSource(id); |
|
59 |
return result; |
|
60 |
} |
|
61 |
|
|
62 |
public static IdentifiableSource NewDataImportInstance(String id, String idNamespace){ |
|
63 |
IdentifiableSource result = NewDataImportInstance(id); |
|
64 |
result.setIdNamespace(idNamespace); |
|
65 |
return result; |
|
66 |
} |
|
67 |
|
|
68 |
public static IdentifiableSource NewDataImportInstance(String id, String idNamespace, Reference ref){ |
|
69 |
IdentifiableSource result = NewDataImportInstance(id, idNamespace); |
|
70 |
result.setCitation(ref); |
|
71 |
return result; |
|
72 |
} |
|
73 |
|
|
74 |
public static IdentifiableSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation, String microCitation){ |
|
75 |
IdentifiableSource result = NewInstance(type); |
|
76 |
result.setIdInSource(id); |
|
77 |
result.setIdNamespace(idNamespace); |
|
78 |
result.setCitation(citation); |
|
79 |
result.setCitationMicroReference(microCitation); |
|
80 |
return result; |
|
81 |
} |
|
82 |
|
|
83 |
public static IdentifiableSource NewPrimarySourceInstance(Reference citation, String microCitation){ |
|
84 |
IdentifiableSource result = NewInstance(OriginalSourceType.PrimaryTaxonomicSource); |
|
85 |
result.setCitation(citation); |
|
86 |
result.setCitationMicroReference(microCitation); |
|
87 |
return result; |
|
88 |
} |
|
89 |
|
|
90 |
// ******************************** FIELDS ************************************/ |
|
91 |
|
|
92 |
@XmlElement(name = "SourcedObject") |
|
93 |
@XmlIDREF |
|
94 |
@XmlSchemaType(name = "IDREF") |
|
95 |
@Any(metaDef = "CdmBase", |
|
96 |
metaColumn=@Column(name = "sourcedObj_type"), |
|
97 |
fetch = FetchType.LAZY, |
|
98 |
optional = false) |
|
99 |
@JoinColumn(name = "sourcedObj_id") |
|
100 |
@NotAudited |
|
101 |
private IdentifiableEntity<?> sourcedObj; |
|
102 |
|
|
103 |
// ****************** CONSTRUCTOR ********************************/ |
|
104 |
|
|
105 |
//for hibernate only |
|
106 |
private IdentifiableSource() { |
|
107 |
} |
|
108 |
|
|
109 |
private IdentifiableSource(OriginalSourceType type) { |
|
110 |
super(type); |
|
111 |
} |
|
112 |
|
|
113 |
// ********************** GETTER /SETTER *****************************/ |
|
114 |
|
|
115 |
@Override |
|
116 |
public IdentifiableEntity getSourcedObj() { |
|
117 |
return sourcedObj; |
|
118 |
} |
|
119 |
|
|
120 |
@Override |
|
121 |
public void setSourcedObj(IdentifiableEntity sourcedObj) { |
|
122 |
this.sourcedObj = sourcedObj; |
|
123 |
} |
|
124 |
|
|
125 |
//*********************************** CLONE *********************************************************/ |
|
126 |
|
|
127 |
/** |
|
128 |
* Clones this original source and sets the clones sourced object to 'sourceObj' |
|
129 |
* @see java.lang.Object#clone() |
|
130 |
*/ |
|
131 |
public IdentifiableSource clone(IdentifiableEntity sourcedObj) throws CloneNotSupportedException{ |
|
132 |
IdentifiableSource result = (IdentifiableSource)clone(); |
|
133 |
result.setSourcedObj(sourcedObj); |
|
134 |
return result; |
|
135 |
} |
|
136 |
|
|
137 |
@Override |
|
138 |
public Object clone() throws CloneNotSupportedException{ |
|
139 |
IdentifiableSource result = (IdentifiableSource)super.clone(); |
|
140 |
|
|
141 |
//no changes to: sourcedObj |
|
142 |
return result; |
|
143 |
} |
|
144 |
|
|
145 |
|
|
146 |
} |
|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.model.common; |
|
12 |
|
|
13 |
import javax.persistence.Column; |
|
14 |
import javax.persistence.Entity; |
|
15 |
import javax.persistence.FetchType; |
|
16 |
import javax.persistence.JoinColumn; |
|
17 |
import javax.xml.bind.annotation.XmlElement; |
|
18 |
import javax.xml.bind.annotation.XmlIDREF; |
|
19 |
import javax.xml.bind.annotation.XmlSchemaType; |
|
20 |
import javax.xml.bind.annotation.XmlType; |
|
21 |
|
|
22 |
import org.apache.log4j.Logger; |
|
23 |
import org.hibernate.annotations.Any; |
|
24 |
import org.hibernate.envers.Audited; |
|
25 |
import org.hibernate.envers.NotAudited; |
|
26 |
|
|
27 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
28 |
|
|
29 |
/** |
|
30 |
* This class represents an {@link eu.etaxonomy.cdm.model.common.IOriginalSource IOriginalSource} |
|
31 |
* that can be used with {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity identifiable entity}. |
|
32 |
* |
|
33 |
* @see eu.etaxonomy.cdm.model.common.IOriginalSource |
|
34 |
* |
|
35 |
* @author a.mueller |
|
36 |
* @created 18.09.2009 |
|
37 |
* @version 1.0 |
|
38 |
*/ |
|
39 |
@XmlType(name = "IdentifiableSource", propOrder = { |
|
40 |
"sourcedObj" |
|
41 |
}) |
|
42 |
@Entity |
|
43 |
@Audited |
|
44 |
public class IdentifiableSource extends OriginalSourceBase<IdentifiableEntity>{ |
|
45 |
private static final long serialVersionUID = -8487673428764273806L; |
|
46 |
@SuppressWarnings("unused") |
|
47 |
private static final Logger logger = Logger.getLogger(IdentifiableSource.class); |
|
48 |
|
|
49 |
//********************************* FACTORY ********************************************************/ |
|
50 |
|
|
51 |
public static IdentifiableSource NewInstance(OriginalSourceType type){ |
|
52 |
return new IdentifiableSource(type); |
|
53 |
} |
|
54 |
|
|
55 |
public static IdentifiableSource NewDataImportInstance(String id){ |
|
56 |
IdentifiableSource result = new IdentifiableSource(OriginalSourceType.Import); |
|
57 |
result.setIdInSource(id); |
|
58 |
return result; |
|
59 |
} |
|
60 |
|
|
61 |
public static IdentifiableSource NewDataImportInstance(String id, String idNamespace){ |
|
62 |
IdentifiableSource result = NewDataImportInstance(id); |
|
63 |
result.setIdNamespace(idNamespace); |
|
64 |
return result; |
|
65 |
} |
|
66 |
|
|
67 |
public static IdentifiableSource NewDataImportInstance(String id, String idNamespace, Reference ref){ |
|
68 |
IdentifiableSource result = NewDataImportInstance(id, idNamespace); |
|
69 |
result.setCitation(ref); |
|
70 |
return result; |
|
71 |
} |
|
72 |
|
|
73 |
public static IdentifiableSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation, String microCitation){ |
|
74 |
IdentifiableSource result = NewInstance(type); |
|
75 |
result.setIdInSource(id); |
|
76 |
result.setIdNamespace(idNamespace); |
|
77 |
result.setCitation(citation); |
|
78 |
result.setCitationMicroReference(microCitation); |
|
79 |
return result; |
|
80 |
} |
|
81 |
|
|
82 |
public static IdentifiableSource NewPrimarySourceInstance(Reference citation, String microCitation){ |
|
83 |
IdentifiableSource result = NewInstance(OriginalSourceType.PrimaryTaxonomicSource); |
|
84 |
result.setCitation(citation); |
|
85 |
result.setCitationMicroReference(microCitation); |
|
86 |
return result; |
|
87 |
} |
|
88 |
|
|
89 |
// ******************************** FIELDS ************************************/ |
|
90 |
|
|
91 |
@XmlElement(name = "SourcedObject") |
|
92 |
@XmlIDREF |
|
93 |
@XmlSchemaType(name = "IDREF") |
|
94 |
@Any(metaDef = "CdmBase", |
|
95 |
metaColumn=@Column(name = "sourcedObj_type"), |
|
96 |
fetch = FetchType.LAZY, |
|
97 |
optional = false) |
|
98 |
@JoinColumn(name = "sourcedObj_id") |
|
99 |
@NotAudited |
|
100 |
|
|
101 |
// @org.hibernate.annotations.AnyMetaDef(name = "OriginalSource" , |
|
102 |
// metaType="string", |
|
103 |
// idType="integer", |
|
104 |
// metaValues={ |
|
105 |
// @MetaValue(value = "eu.etaxonomy.cdm.model.common.IdentifiableEntity", targetEntity = IdentifiableEntity.class), |
|
106 |
// @MetaValue(value = "eu.etaxonomy.cdm.model.description.DescriptionElementBase", targetEntity = DescriptionElementBase.class), |
|
107 |
// }) |
|
108 |
private IdentifiableEntity<?> sourcedObj; |
|
109 |
|
|
110 |
// ****************** CONSTRUCTOR ********************************/ |
|
111 |
|
|
112 |
//for hibernate only |
|
113 |
private IdentifiableSource() { |
|
114 |
} |
|
115 |
|
|
116 |
private IdentifiableSource(OriginalSourceType type) { |
|
117 |
super(type); |
|
118 |
} |
|
119 |
|
|
120 |
// ********************** GETTER /SETTER *****************************/ |
|
121 |
|
|
122 |
@Override |
|
123 |
public IdentifiableEntity getSourcedObj() { |
|
124 |
return sourcedObj; |
|
125 |
} |
|
126 |
|
|
127 |
@Override |
|
128 |
public void setSourcedObj(IdentifiableEntity sourcedObj) { |
|
129 |
this.sourcedObj = sourcedObj; |
|
130 |
} |
|
131 |
|
|
132 |
//*********************************** CLONE *********************************************************/ |
|
133 |
|
|
134 |
/** |
|
135 |
* Clones this original source and sets the clones sourced object to 'sourceObj' |
|
136 |
* @see java.lang.Object#clone() |
|
137 |
*/ |
|
138 |
public IdentifiableSource clone(IdentifiableEntity sourcedObj) throws CloneNotSupportedException{ |
|
139 |
IdentifiableSource result = (IdentifiableSource)clone(); |
|
140 |
result.setSourcedObj(sourcedObj); |
|
141 |
return result; |
|
142 |
} |
|
143 |
|
|
144 |
@Override |
|
145 |
public Object clone() throws CloneNotSupportedException{ |
|
146 |
IdentifiableSource result = (IdentifiableSource)super.clone(); |
|
147 |
|
|
148 |
//no changes to: sourcedObj |
|
149 |
return result; |
|
150 |
} |
|
151 |
|
|
152 |
|
|
153 |
} |
Also available in: Unified diff
Clean up IdentifiableSource java file