(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / OriginalSource.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 javax.persistence.Entity;
14 import javax.persistence.Transient;
15
16 import org.apache.log4j.Logger;
17
18 /**
19 * Other names/labels/titles (abreviated or not) for the same object (person,
20 * reference, source, etc.)
21 * @author m.doering
22 * @version 1.0
23 * @created 08-Nov-2007 13:06:22
24 */
25
26 @Entity
27 public class OriginalSource extends ReferencedEntityBase implements Cloneable{
28 static Logger logger = Logger.getLogger(OriginalSource.class);
29 //The object's ID in the source, where the alternative string comes from
30 private String idInSource;
31 private String idNamespace;
32 private IdentifiableEntity sourcedObj;
33
34 /**
35 * Factory method
36 * @return
37 */
38 public static OriginalSource NewInstance(){
39 return new OriginalSource();
40 }
41
42 public static OriginalSource NewInstance(String id){
43 OriginalSource result = new OriginalSource();
44 result.setIdInSource(id);
45 return result;
46 }
47
48 public static OriginalSource NewInstance(String id, String idNamespace){
49 OriginalSource result = new OriginalSource();
50 result.setIdInSource(id);
51 result.setIdNamespace(idNamespace);
52 return result;
53 }
54
55
56 /**
57 * Constructor
58 */
59 public OriginalSource(){
60 super();
61 }
62
63 /*************** GETTER /SETTER ************************************/
64
65 public String getIdInSource(){
66 return this.idInSource;
67 }
68 public void setIdInSource(String idInSource){
69 this.idInSource = idInSource;
70 }
71
72
73 /**
74 * Returns the id namespace. The id namespace is a String that further defines the origin of
75 * the original record. In the combination with the id it should be unique within one a source.
76 * E.g. if a record comes from table ABC and has the id 345, 'ABC' is a suitable namespace and the
77 * combination of 'ABC' and 345 is a unique id for this source.
78 * The namespace is meant to distinguish import records that come from two different tables, elements, objects, ...
79 * and end up in the same CDM class. In this case the id may not be enough to identify the original record.
80 * @return the idNamespace
81 */
82 public String getIdNamespace() {
83 return idNamespace;
84 }
85
86 /**
87 * @param idNamespace the idNamespace to set
88 */
89 public void setIdNamespace(String idNamespace) {
90 this.idNamespace = idNamespace;
91 }
92
93
94 // @ManyToOne
95 // @Cascade(CascadeType.SAVE_UPDATE)
96 @Transient //beacause IdentifiableEntity is MappedSuperclass
97 public IdentifiableEntity getSourcedObj() {
98 return sourcedObj;
99 }
100 public void setSourcedObj(IdentifiableEntity sourcedObj) {
101 this.sourcedObj = sourcedObj;
102 }
103
104
105
106 //****************** CLONE ************************************************/
107
108 /* (non-Javadoc)
109 * @see java.lang.Object#clone()
110 */
111 @Override
112 public Object clone() throws CloneNotSupportedException{
113 OriginalSource result = (OriginalSource)super.clone();
114
115 //no changes to: idInSource, sourcedObj
116 return result;
117 }
118
119 /**
120 * Clones this original source and sets the clones sourced object to 'sourceObj'
121 * @see java.lang.Object#clone()
122 */
123 public OriginalSource clone(IdentifiableEntity sourcedObj) throws CloneNotSupportedException{
124 OriginalSource result = (OriginalSource)clone();
125 result.setSourcedObj(sourcedObj);
126 return result;
127 }
128
129 }