cleanup
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / description / FeatureState.java
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.description;
10
11 import javax.persistence.Entity;
12 import javax.persistence.FetchType;
13 import javax.persistence.ManyToOne;
14 import javax.validation.constraints.NotNull;
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlIDREF;
19 import javax.xml.bind.annotation.XmlRootElement;
20 import javax.xml.bind.annotation.XmlSchemaType;
21 import javax.xml.bind.annotation.XmlType;
22
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
25 import org.hibernate.envers.Audited;
26
27 import eu.etaxonomy.cdm.model.common.VersionableEntity;
28 import eu.etaxonomy.cdm.model.term.DefinedTermBase;
29 import eu.etaxonomy.cdm.model.term.TermNode;
30
31 /**
32 * A class representing a state for a given feature. As instances of {@link State state}
33 * are reusable they may represent multiple states in e.g. a given feature tree.
34 * By handling them as a pair with feature it is expected to be explicit within a certain
35 * feature tree branch and therefore can be used to define values like {@link TermNode#getInapplicableIf()}
36 * or {@link TermNode#getOnlyApplicableIf()}.
37 *
38 * @author a.mueller
39 * @since 08.08.2019
40 */
41 @XmlAccessorType(XmlAccessType.FIELD)
42 @XmlType(name="FeatureState", factoryMethod="NewInstance", propOrder = {
43 "feature",
44 "state"
45 })
46 @XmlRootElement(name = "FeatureState")
47 @Entity
48 @Audited
49 public class FeatureState extends VersionableEntity {
50
51 private static final long serialVersionUID = -421832597710084356L;
52 @SuppressWarnings("unused")
53 private static final Logger logger = LogManager.getLogger();
54
55 @XmlElement(name = "Feature")
56 @XmlIDREF
57 @XmlSchemaType(name = "IDREF")
58 @ManyToOne(fetch = FetchType.LAZY, targetEntity=Feature.class)
59 @NotNull
60 private Feature feature;
61
62 @XmlElement(name = "State", type=DefinedTermBase.class)
63 @XmlIDREF
64 @XmlSchemaType(name = "IDREF")
65 @ManyToOne(fetch = FetchType.LAZY, targetEntity=DefinedTermBase.class)
66 @NotNull
67 private DefinedTermBase<?> state;
68
69 //*************** CONSTRUCTOR AND FACTORY METHODS **********************************/
70
71 public static FeatureState NewInstance() {
72 return new FeatureState();
73 }
74
75 public static FeatureState NewInstance(Feature feature, State state){
76 return new FeatureState(feature, state);
77 }
78
79 public static FeatureState NewInstance(Feature feature, DefinedTermBase<?> state){
80 return new FeatureState(feature, state);
81 }
82
83 //for hibernate use only
84 @Deprecated
85 protected FeatureState() {}
86
87 protected FeatureState(Feature feature, DefinedTermBase<?> state) {
88 this.feature = feature;
89 this.state = state;
90 }
91
92 //************************************ GETTER /SETTER ***************************************/
93
94 public Feature getFeature() {
95 return feature;
96 }
97 public void setFeature(Feature feature) {
98 this.feature = feature;
99 }
100
101 public DefinedTermBase<?> getState() {
102 return state;
103 }
104 public void setState(DefinedTermBase<?> state) {
105 this.state = state;
106 }
107
108 // ******************************* TO STRING *******************************************/
109
110 @Override
111 public String toString() {
112 return "FeatureState [feature=" + feature + ", state=" + state + "]";
113 }
114
115 //*********************************** CLONE ********************************************/
116
117 @Override
118 public FeatureState clone() throws CloneNotSupportedException {
119 FeatureState result = (FeatureState)super.clone();
120
121 //no changes to: feature, state
122 return result;
123 }
124 }