2 * Copyright (C) 2019 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.model
.description
;
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
;
23 import org
.apache
.logging
.log4j
.LogManager
;
24 import org
.apache
.logging
.log4j
.Logger
;
25 import org
.hibernate
.envers
.Audited
;
27 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
28 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
29 import eu
.etaxonomy
.cdm
.model
.term
.TermNode
;
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()}.
41 @XmlAccessorType(XmlAccessType
.FIELD
)
42 @XmlType(name
="FeatureState", factoryMethod
="NewInstance", propOrder
= {
46 @XmlRootElement(name
= "FeatureState")
49 public class FeatureState
extends VersionableEntity
{
51 private static final long serialVersionUID
= -421832597710084356L;
52 @SuppressWarnings("unused")
53 private static final Logger logger
= LogManager
.getLogger();
55 @XmlElement(name
= "Feature")
57 @XmlSchemaType(name
= "IDREF")
58 @ManyToOne(fetch
= FetchType
.LAZY
, targetEntity
=Feature
.class)
60 private Feature feature
;
62 @XmlElement(name
= "State", type
=DefinedTermBase
.class)
64 @XmlSchemaType(name
= "IDREF")
65 @ManyToOne(fetch
= FetchType
.LAZY
, targetEntity
=DefinedTermBase
.class)
67 private DefinedTermBase
<?
> state
;
69 //*************** CONSTRUCTOR AND FACTORY METHODS **********************************/
71 public static FeatureState
NewInstance() {
72 return new FeatureState();
75 public static FeatureState
NewInstance(Feature feature
, State state
){
76 return new FeatureState(feature
, state
);
79 public static FeatureState
NewInstance(Feature feature
, DefinedTermBase
<?
> state
){
80 return new FeatureState(feature
, state
);
83 //for hibernate use only
85 protected FeatureState() {}
87 protected FeatureState(Feature feature
, DefinedTermBase
<?
> state
) {
88 this.feature
= feature
;
92 //************************************ GETTER /SETTER ***************************************/
94 public Feature
getFeature() {
97 public void setFeature(Feature feature
) {
98 this.feature
= feature
;
101 public DefinedTermBase
<?
> getState() {
104 public void setState(DefinedTermBase
<?
> state
) {
108 // ******************************* TO STRING *******************************************/
111 public String
toString() {
112 return "FeatureState [feature=" + feature
+ ", state=" + state
+ "]";
115 //*********************************** CLONE ********************************************/
118 public FeatureState
clone() throws CloneNotSupportedException
{
119 FeatureState result
= (FeatureState
)super.clone();
121 //no changes to: feature, state