Project

General

Profile

Download (3.86 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2019 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
package eu.etaxonomy.cdm.model.reference;
10

    
11
import javax.persistence.Entity;
12
import javax.persistence.FetchType;
13
import javax.persistence.ManyToOne;
14
import javax.xml.bind.annotation.XmlAccessType;
15
import javax.xml.bind.annotation.XmlAccessorType;
16
import javax.xml.bind.annotation.XmlElement;
17
import javax.xml.bind.annotation.XmlIDREF;
18
import javax.xml.bind.annotation.XmlRootElement;
19
import javax.xml.bind.annotation.XmlSchemaType;
20
import javax.xml.bind.annotation.XmlType;
21

    
22
import org.hibernate.envers.Audited;
23

    
24
import eu.etaxonomy.cdm.model.common.CdmBase;
25
import eu.etaxonomy.cdm.model.common.CdmLinkBase;
26
import eu.etaxonomy.cdm.model.common.IntextReference;
27
import eu.etaxonomy.cdm.model.description.DescriptionBase;
28
import eu.etaxonomy.cdm.model.taxon.Taxon;
29

    
30
/**
31
 * Class to link to other CdmBase objects within the context of
32
 * {@link OriginalSourceBase information sources}.
33
 *
34
 * @author a.mueller
35
 * @since 09.11.2019
36
 */
37
@XmlAccessorType(XmlAccessType.FIELD)
38
@XmlType(name = "CdmLinkSource", propOrder = {
39
    "description"
40
})
41
@XmlRootElement(name = "CdmLinkSource")
42
@Entity
43
@Audited
44
public class CdmLinkSource extends CdmLinkBase {
45

    
46
    private static final long serialVersionUID = 6600576878001716986L;
47

    
48
// // ************* Source ***********************/
49
//
50
//    @XmlElement(name = "Source")
51
//    @XmlIDREF
52
//    @XmlSchemaType(name = "IDREF")
53
//    @OneToOne(fetch = FetchType.LAZY, mappedBy="cdmSource")
54
//    private OriginalSourceBase source;
55

    
56
// **************** Targets ************************/
57

    
58
    @XmlElement(name = "Description")
59
    @XmlIDREF
60
    @XmlSchemaType(name = "IDREF")
61
    @ManyToOne(fetch = FetchType.LAZY)
62
    private DescriptionBase<?> description;
63

    
64
// ************************ FACTORY *********************/
65

    
66
    public static CdmLinkSource NewInstance(ICdmTarget target) {
67
        return new CdmLinkSource(target);
68
    }
69

    
70
//******************* CONSTRUCTOR *********************/
71

    
72
    public CdmLinkSource(){}  //mayb protected is enough, needs to be tested for loading
73

    
74
    public CdmLinkSource(ICdmTarget target) {
75
//        this.source = source;
76
        setTarget(target);
77
    }
78

    
79
//***************** GETTER / SETTER *****************/
80

    
81
    /**
82
     * Returns the target object. Throws an {@link IllegalStateException} if no target
83
     * is defined.
84
     *
85
     * @see IntextReference#getTarget()
86
     */
87
    public ICdmTarget getTarget() {
88
        if (taxon != null){
89
            return CdmBase.deproxy(taxon, Taxon.class);
90
        }else if (description != null){
91
            return description;
92
        }else{
93
            throw new IllegalStateException("CdmSource has no target object defined");
94
        }
95
    }
96

    
97
    public void setTarget(ICdmTarget target) {
98
        target = CdmBase.deproxy(target);
99
        if (target instanceof DescriptionBase<?>){
100
            this.description = (DescriptionBase<?>)target;
101
        }else if (target instanceof Taxon){
102
            this.taxon = (Taxon)target;
103
        }else{
104
            throw new IllegalArgumentException("Target class not supported by CdmSource");
105
        }
106
    }
107

    
108
// ********************************* CLONE **********************************/
109

    
110
    @Override
111
    public CdmLinkSource clone() throws CloneNotSupportedException {
112
        CdmLinkSource result = (CdmLinkSource)super.clone();
113

    
114
        return result;
115
    }
116

    
117
//    public CdmLinkSource clone(OriginalSourceBase source) {
118
//        CdmLinkSource result;
119
//        try {
120
//            result = (CdmLinkSource)super.clone();
121
////            result.source = source;
122
//            return result;
123
//        } catch (CloneNotSupportedException e) {
124
//            throw new RuntimeException(e);  //does not happen
125
//        }
126
//    }
127

    
128
}
(1-1/41)