| 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 eu.etaxonomy.cdm.model.media.ReferencedMediaBase; |
|---|
| 14 | |
|---|
| 15 | import org.apache.log4j.Logger; |
|---|
| 16 | import org.hibernate.envers.Audited; |
|---|
| 17 | import org.hibernate.search.annotations.Indexed; |
|---|
| 18 | |
|---|
| 19 | import java.util.*; |
|---|
| 20 | |
|---|
| 21 | import javax.persistence.*; |
|---|
| 22 | import javax.validation.constraints.NotNull; |
|---|
| 23 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 24 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 25 | import javax.xml.bind.annotation.XmlElement; |
|---|
| 26 | import javax.xml.bind.annotation.XmlElementWrapper; |
|---|
| 27 | import javax.xml.bind.annotation.XmlIDREF; |
|---|
| 28 | import javax.xml.bind.annotation.XmlRootElement; |
|---|
| 29 | import javax.xml.bind.annotation.XmlSchemaType; |
|---|
| 30 | import javax.xml.bind.annotation.XmlType; |
|---|
| 31 | |
|---|
| 32 | /** |
|---|
| 33 | * @author m.doering |
|---|
| 34 | * @version 1.0 |
|---|
| 35 | * @created 08-Nov-2007 13:06:43 |
|---|
| 36 | */ |
|---|
| 37 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 38 | @XmlType(name = "PhylogeneticTree", propOrder = { |
|---|
| 39 | "usedSequences" |
|---|
| 40 | }) |
|---|
| 41 | @XmlRootElement(name = "PhylogeneticTree") |
|---|
| 42 | @Entity |
|---|
| 43 | @Indexed(index = "eu.etaxonomy.cdm.model.media.Media") |
|---|
| 44 | @Audited |
|---|
| 45 | public class PhylogeneticTree extends ReferencedMediaBase implements Cloneable{ |
|---|
| 46 | private static final long serialVersionUID = -7020182117362324067L; |
|---|
| 47 | private static final Logger logger = Logger.getLogger(PhylogeneticTree.class); |
|---|
| 48 | |
|---|
| 49 | @XmlElementWrapper(name = "UsedSequences") |
|---|
| 50 | @XmlElement(name = "UsedSequence") |
|---|
| 51 | @XmlIDREF |
|---|
| 52 | @XmlSchemaType(name = "IDREF") |
|---|
| 53 | @OneToMany(fetch = FetchType.LAZY)// FIXME surely should be ManyToMany - you can use a sequence to construct several different phylogenetic trees |
|---|
| 54 | @NotNull |
|---|
| 55 | private Set<Sequence> usedSequences = new HashSet<Sequence>(); |
|---|
| 56 | |
|---|
| 57 | public Set<Sequence> getUsedSequences() { |
|---|
| 58 | if(usedSequences == null) { |
|---|
| 59 | this.usedSequences = new HashSet<Sequence>(); |
|---|
| 60 | } |
|---|
| 61 | return usedSequences; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | public void addUsedSequences(Sequence usedSequence) { |
|---|
| 65 | this.usedSequences.add(usedSequence); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | public void removeUsedSequences(Sequence usedSequence) { |
|---|
| 69 | this.usedSequences.remove(usedSequence); |
|---|
| 70 | |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | //*********** CLONE **********************************/ |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * Clones <i>this</i> phylogenetic tree. This is a shortcut that enables to |
|---|
| 77 | * create a new instance that differs only slightly from <i>this</i> phylogenetic tree |
|---|
| 78 | * by modifying only some of the attributes.<BR> |
|---|
| 79 | * This method overrides the clone method from {@link Media Media}. |
|---|
| 80 | * |
|---|
| 81 | * @see eu.etaxonomy.cdm.model.media.Media#clone() |
|---|
| 82 | * @see java.lang.Object#clone() |
|---|
| 83 | */ |
|---|
| 84 | @Override |
|---|
| 85 | |
|---|
| 86 | public Object clone(){ |
|---|
| 87 | PhylogeneticTree result; |
|---|
| 88 | try{ |
|---|
| 89 | result= (PhylogeneticTree) super.clone(); |
|---|
| 90 | result.usedSequences = new HashSet<Sequence>(); |
|---|
| 91 | for (Sequence seq: this.usedSequences){ |
|---|
| 92 | result.addUsedSequences((Sequence)seq.clone()); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | return result; |
|---|
| 96 | }catch (CloneNotSupportedException e) { |
|---|
| 97 | logger.warn("Object does not implement cloneable"); |
|---|
| 98 | e.printStackTrace(); |
|---|
| 99 | return null; |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | } |
|---|