Project

General

Profile

Download (4.04 KB) Statistics
| Branch: | Tag: | Revision:
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.molecular;
11

    
12

    
13
import java.util.HashSet;
14
import java.util.Set;
15

    
16
import javax.persistence.Entity;
17
import javax.persistence.FetchType;
18
import javax.persistence.JoinColumn;
19
import javax.persistence.JoinTable;
20
import javax.persistence.ManyToMany;
21
import javax.validation.constraints.NotNull;
22
import javax.xml.bind.annotation.XmlAccessType;
23
import javax.xml.bind.annotation.XmlAccessorType;
24
import javax.xml.bind.annotation.XmlElement;
25
import javax.xml.bind.annotation.XmlElementWrapper;
26
import javax.xml.bind.annotation.XmlIDREF;
27
import javax.xml.bind.annotation.XmlRootElement;
28
import javax.xml.bind.annotation.XmlSchemaType;
29
import javax.xml.bind.annotation.XmlType;
30

    
31
import org.apache.log4j.Logger;
32
import org.hibernate.envers.Audited;
33

    
34
import eu.etaxonomy.cdm.model.media.Media;
35

    
36
/**
37
 * "A phylogenetic tree or evolutionary tree is a branching diagram or "tree" showing the
38
 * inferred evolutionary relationships among various biological species or other entities
39
 * based upon similarities and differences in their physical and/or genetic characteristics.
40
 * The taxa joined together in the tree are implied to have descended from a common ancestor."
41
 * (Wikipedia).
42
 * <BR> In the CDM we currently store phylogenetic trees only as media. This may change in future.
43
 *
44
 * @author m.doering
45
 * @created 08-Nov-2007
46
 */
47
@XmlAccessorType(XmlAccessType.FIELD)
48
@XmlType(name = "PhylogeneticTree", propOrder = {
49
	"usedSequences"
50
})
51
@XmlRootElement(name = "PhylogeneticTree")
52
@Entity
53
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
54
//@Indexed(index = "eu.etaxonomy.cdm.model.media.Media")
55
@Audited
56
public class PhylogeneticTree extends Media implements Cloneable{
57
	private static final long serialVersionUID = -7020182117362324067L;
58
	private static final  Logger logger = Logger.getLogger(PhylogeneticTree.class);
59

    
60

    
61
	@XmlElementWrapper(name = "UsedSequences")
62
	@XmlElement(name = "UsedSequence")
63
    @XmlIDREF
64
    @XmlSchemaType(name = "IDREF")
65
    @ManyToMany(fetch = FetchType.LAZY)
66
	//preliminary  #5369
67
    @JoinTable(
68
            joinColumns = @JoinColumn( name="Media_id")
69
    )
70
    @NotNull
71
	private Set<Sequence> usedSequences = new HashSet<Sequence>();
72

    
73
//********************** Factory Method **********************************/
74

    
75
    /**
76
     * Factory method
77
     * @return
78
     */
79
    public static PhylogeneticTree NewInstance(){
80
        return new PhylogeneticTree();
81
    }
82

    
83

    
84
//***************** Constructor ****************************/
85

    
86
    private PhylogeneticTree(){
87
    	super();
88
    }
89

    
90

    
91

    
92
// ********************** GETTER / SETTER **************************/
93

    
94
	public Set<Sequence> getUsedSequences() {
95
		if(usedSequences == null) {
96
			this.usedSequences = new HashSet<Sequence>();
97
		}
98
		return usedSequences;
99
	}
100

    
101
	public void addUsedSequences(Sequence usedSequence) {
102
		this.usedSequences.add(usedSequence);
103
	}
104

    
105
	public void removeUsedSequences(Sequence usedSequence) {
106
		this.usedSequences.remove(usedSequence);
107

    
108
	}
109

    
110
//*********** CLONE **********************************/
111

    
112
	/**
113
	 * Clones <i>this</i> phylogenetic tree. This is a shortcut that enables to
114
	 * create a new instance that differs only slightly from <i>this</i> phylogenetic tree
115
	 * by modifying only some of the attributes.<BR>
116
	 * This method overrides the clone method from {@link Media Media}.
117
	 *
118
	 * @see eu.etaxonomy.cdm.model.media.Media#clone()
119
	 * @see java.lang.Object#clone()
120
	 */
121
	@Override
122

    
123
	public Object clone(){
124
		PhylogeneticTree result;
125
		try{
126
			result= (PhylogeneticTree) super.clone();
127
			result.usedSequences = new HashSet<Sequence>();
128
			for (Sequence seq: this.usedSequences){
129
				result.addUsedSequences((Sequence)seq.clone());
130
			}
131

    
132
			return result;
133
		}catch (CloneNotSupportedException e) {
134
			logger.warn("Object does not implement cloneable");
135
			e.printStackTrace();
136
			return null;
137
		}
138
	}
139
}
(6-6/14)