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