Project

General

Profile

Download (2.91 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2021 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.common;
10

    
11
import java.util.EnumSet;
12

    
13
import javax.persistence.Entity;
14
import javax.validation.constraints.NotNull;
15
import javax.xml.bind.annotation.XmlAttribute;
16

    
17
import org.apache.log4j.Logger;
18
import org.hibernate.annotations.Parameter;
19
import org.hibernate.annotations.Type;
20
import org.hibernate.envers.Audited;
21

    
22
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
23
import eu.etaxonomy.cdm.model.term.TermType;
24

    
25
/**
26
 * This
27
 *
28
 * @author a.mueller
29
 * @since 22.04.2021
30
 */
31
@Entity
32
@Audited
33
public abstract class AvailableForTermBase<T extends DefinedTermBase>
34
        extends DefinedTermBase<T>{
35

    
36
    private static final long serialVersionUID = 7991846649037898325L;
37
    @SuppressWarnings("unused")
38
    private static final Logger logger = Logger.getLogger(AvailableForTermBase.class);
39

    
40
    @XmlAttribute(name ="availableFor")
41
    @NotNull
42
    @Type(type = "eu.etaxonomy.cdm.hibernate.EnumSetUserType",
43
        parameters = {@Parameter(name = "enumClass", value = "eu.etaxonomy.cdm.model.common.CdmClass")}
44
    )
45
    private EnumSet<CdmClass> availableFor = EnumSet.noneOf(CdmClass.class);
46

    
47
    //for hibernate use only
48
    @Deprecated
49
    protected AvailableForTermBase() {
50
        super();
51
    }
52
    @Deprecated
53
    protected AvailableForTermBase(TermType type) {
54
        super(type);
55
    }
56

    
57
    protected AvailableForTermBase(TermType type, String term, String label, String labelAbbrev) {
58
        super(type, term, label, labelAbbrev);
59
    }
60

    
61
// ****************************** GETTER_SETTER *******************************/
62

    
63
    protected EnumSet<CdmClass> getAvailableFor() {
64
        return availableFor;
65
    }
66

    
67
    /**
68
     * for know it is private and the boolean getters and setters should be used instead.
69
     * If you make it public make sure to guarantee that any change to the enum set results
70
     * in a new enum set (see also {@link #newEnumSet(EnumSet, CdmClass, CdmClass)}
71
     * and that the client is aware of the enum set being immutable.
72
     */
73
    private void setAvailableFor(EnumSet<CdmClass> availableFor){
74
        this.availableFor = availableFor;
75
    }
76

    
77
    /**
78
     * Sets the value for supported classes
79
     * @param cdmClass the supported class
80
     * @param value the value if it is supported (<code>true</code>) or not (<code>false</code>)
81
     */
82
    protected void setAvailableFor(CdmClass cdmClass, boolean value) {
83
        if (value && !this.availableFor.contains(cdmClass)){
84
            setAvailableFor(newEnumSet(this.availableFor, cdmClass, null));
85
        }else if (!value && this.availableFor.contains(cdmClass)){
86
            setAvailableFor(newEnumSet(this.availableFor, null, cdmClass));
87
        }else{
88
            return;
89
        }
90
    }
91

    
92

    
93
}
(6-6/58)