fix bug for getBoldUri
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / molecular / PhylogeneticTree.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.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.ManyToMany;
19 import javax.validation.constraints.NotNull;
20 import javax.xml.bind.annotation.XmlAccessType;
21 import javax.xml.bind.annotation.XmlAccessorType;
22 import javax.xml.bind.annotation.XmlElement;
23 import javax.xml.bind.annotation.XmlElementWrapper;
24 import javax.xml.bind.annotation.XmlIDREF;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import javax.xml.bind.annotation.XmlSchemaType;
27 import javax.xml.bind.annotation.XmlType;
28
29 import org.apache.log4j.Logger;
30 import org.hibernate.envers.Audited;
31 import org.hibernate.search.annotations.Indexed;
32
33 import eu.etaxonomy.cdm.model.media.Media;
34
35 /**
36 * "A phylogenetic tree or evolutionary tree is a branching diagram or "tree" showing the
37 * inferred evolutionary relationships among various biological species or other entities
38 * based upon similarities and differences in their physical and/or genetic characteristics.
39 * The taxa joined together in the tree are implied to have descended from a common ancestor."
40 * (Wikipedia).
41 * <BR> In the CDM we currently store phylogenetic trees only as media. This may change in future.
42 *
43 * @author m.doering
44 * @created 08-Nov-2007
45 */
46 @XmlAccessorType(XmlAccessType.FIELD)
47 @XmlType(name = "PhylogeneticTree", propOrder = {
48 "usedSequences"
49 })
50 @XmlRootElement(name = "PhylogeneticTree")
51 @Entity
52 @Indexed(index = "eu.etaxonomy.cdm.model.media.Media")
53 @Audited
54 public class PhylogeneticTree extends Media implements Cloneable{
55 private static final long serialVersionUID = -7020182117362324067L;
56 private static final Logger logger = Logger.getLogger(PhylogeneticTree.class);
57
58
59 @XmlElementWrapper(name = "UsedSequences")
60 @XmlElement(name = "UsedSequence")
61 @XmlIDREF
62 @XmlSchemaType(name = "IDREF")
63 @ManyToMany(fetch = FetchType.LAZY)
64 @NotNull
65 private Set<Sequence> usedSequences = new HashSet<Sequence>();
66
67 //********************** Factory Method **********************************/
68
69 /**
70 * Factory method
71 * @return
72 */
73 public static PhylogeneticTree NewInstance(){
74 return new PhylogeneticTree();
75 }
76
77
78 //***************** Constructor ****************************/
79
80 private PhylogeneticTree(){
81 super();
82 }
83
84
85
86 // ********************** GETTER / SETTER **************************/
87
88 public Set<Sequence> getUsedSequences() {
89 if(usedSequences == null) {
90 this.usedSequences = new HashSet<Sequence>();
91 }
92 return usedSequences;
93 }
94
95 public void addUsedSequences(Sequence usedSequence) {
96 this.usedSequences.add(usedSequence);
97 }
98
99 public void removeUsedSequences(Sequence usedSequence) {
100 this.usedSequences.remove(usedSequence);
101
102 }
103
104 //*********** CLONE **********************************/
105
106 /**
107 * Clones <i>this</i> phylogenetic tree. This is a shortcut that enables to
108 * create a new instance that differs only slightly from <i>this</i> phylogenetic tree
109 * by modifying only some of the attributes.<BR>
110 * This method overrides the clone method from {@link Media Media}.
111 *
112 * @see eu.etaxonomy.cdm.model.media.Media#clone()
113 * @see java.lang.Object#clone()
114 */
115 @Override
116
117 public Object clone(){
118 PhylogeneticTree result;
119 try{
120 result= (PhylogeneticTree) super.clone();
121 result.usedSequences = new HashSet<Sequence>();
122 for (Sequence seq: this.usedSequences){
123 result.addUsedSequences((Sequence)seq.clone());
124 }
125
126 return result;
127 }catch (CloneNotSupportedException e) {
128 logger.warn("Object does not implement cloneable");
129 e.printStackTrace();
130 return null;
131 }
132 }
133 }