001package org.biopax.paxtools.impl.level3;
002
003
004import org.biopax.paxtools.model.level3.*;
005import org.biopax.paxtools.model.level3.Process;
006import org.biopax.paxtools.util.BPCollections;
007import org.biopax.paxtools.util.IllegalBioPAXArgumentException;
008import org.hibernate.annotations.Cache;
009import org.hibernate.annotations.*;
010import org.hibernate.search.annotations.Indexed;
011
012import javax.persistence.Entity;
013import javax.persistence.*;
014import java.util.Set;
015
016/**
017 */
018@Entity
019@Proxy(proxyClass= Catalysis.class)
020@Indexed
021@DynamicUpdate @DynamicInsert
022@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
023public class CatalysisImpl extends ControlImpl implements Catalysis
024{
025// ------------------------------ FIELDS ------------------------------
026
027        private CatalysisDirectionType catalysisDirection;
028
029        private Set<PhysicalEntity> cofactor;
030
031// --------------------------- CONSTRUCTORS ---------------------------
032
033        public CatalysisImpl()
034        {
035                this.cofactor = BPCollections.I.createSafeSet();
036        }
037
038// ------------------------ INTERFACE METHODS ------------------------
039
040
041// --------------------- Interface BioPAXElement ---------------------
042
043
044        @Transient
045        public Class<? extends Catalysis> getModelInterface()
046        {
047                return Catalysis.class;
048        }
049
050// --------------------- Interface catalysis ---------------------
051
052// --------------------- ACCESORS and MUTATORS---------------------
053
054        @Enumerated
055        public CatalysisDirectionType getCatalysisDirection()
056        {
057                return catalysisDirection;
058        }
059
060        public void setCatalysisDirection(CatalysisDirectionType catalysisDirection)
061        {
062                this.catalysisDirection = catalysisDirection;
063        }
064
065    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
066        @ManyToMany(targetEntity = PhysicalEntityImpl.class) @JoinTable(name = "cofactor")
067        public Set<PhysicalEntity> getCofactor()
068        {
069                return cofactor;
070        }
071
072        protected void setCofactor(Set<PhysicalEntity> cofactor)
073        {
074                this.cofactor = cofactor;
075        }
076
077        public void addCofactor(PhysicalEntity cofactor)
078        {
079                if (cofactor != null)
080                {
081                        this.cofactor.add(cofactor);
082                        super.addParticipant(cofactor);
083                }
084        }
085
086        public void removeCofactor(PhysicalEntity cofactor)
087        {
088                if (cofactor != null)
089                {
090                        super.removeParticipant(cofactor);
091                        this.cofactor.remove(cofactor);
092                }
093        }
094
095
096        @Override public void addController(Controller controller)
097        {
098                if (controller instanceof PhysicalEntity) super.addController(controller);
099                else throw new IllegalBioPAXArgumentException("Catalysis can only be controlled with a Physical Entity");
100
101        }
102
103        protected boolean checkControlled(Process controlled)
104        {
105                return controlled instanceof Conversion;
106        }
107}