Project

General

Profile

Download (3.51 KB) Statistics
| Branch: | Tag: | Revision:
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.common;
11

    
12
import javax.persistence.Column;
13
import javax.persistence.Entity;
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.XmlRootElement;
19
import javax.xml.bind.annotation.XmlType;
20

    
21
import org.apache.log4j.Logger;
22
import org.springframework.security.core.GrantedAuthority;
23

    
24
@XmlAccessorType(XmlAccessType.FIELD)
25
@XmlType(name = "GrantedAuthority", propOrder = { "authority" })
26
@XmlRootElement(name = "Group")
27
@Entity
28
public class GrantedAuthorityImpl extends CdmBase implements GrantedAuthority {
29

    
30
    private static final long serialVersionUID = 2651969425860655040L;
31
    private static final Logger logger = Logger.getLogger(GrantedAuthority.class);
32

    
33
    @XmlElement(name = "Authority")
34
    @Column(unique = true)
35
    @NotNull
36
    private String authority;
37

    
38
// ********************** FACTORY *********************************/
39

    
40
    public static GrantedAuthorityImpl NewInstance(String authority) {
41
        GrantedAuthorityImpl result = new GrantedAuthorityImpl();
42
        result.setAuthority(authority);
43
        return result;
44
    }
45

    
46
// ************* CONSTRUCTOR ********************/
47

    
48
    protected GrantedAuthorityImpl() {
49
        super();
50
    }
51

    
52
// *************** GETTER / SETTER ********************/
53

    
54
    @Override
55
    public String getAuthority() {
56
        return authority;
57
    }
58

    
59
    public void setAuthority(String authority) {
60
    	this.authority = authority;
61
    }
62

    
63
// ******************* METHODS ***********************************/
64

    
65
    /**
66
     * @param o
67
     * @return
68
     */
69
    public int compareTo(Object o) {
70
        if (o instanceof GrantedAuthority) {
71
            return this.authority.compareTo(((GrantedAuthority) o).getAuthority());
72
        }
73
        return 0;
74
    }
75

    
76
    @Override
77
    public boolean equals(Object o) {
78
        if (o instanceof GrantedAuthority) {
79
        	if(this.authority == null && ((GrantedAuthority) o).getAuthority() == null) {
80
        		return true;
81
        	} else {
82
        		return this.authority.equals(((GrantedAuthority) o).getAuthority());
83
        	}
84
        }
85
        return false;
86
    }
87

    
88
// ******************** TO STRING() **************************/
89

    
90
    @Override
91
    public String toString() {
92
        return getAuthority();
93
    }
94

    
95
// ***************** CLONE **********************************/
96

    
97
    /**
98
     * Clones <i>this</i> Granted Authority. This is a shortcut that enables to
99
     * create a new instance that differs only slightly from <i>this</i> Granted
100
     * Authority by modifying only some of the attributes.<BR>
101

    
102
     *
103
     * @see eu.etaxonomy.cdm.model.common.CdmBase#clone()
104
     * @see java.lang.Object#clone()
105
     */
106
    @Override
107
    public Object clone() {
108
        GrantedAuthority result;
109
        try {
110
            result = (GrantedAuthority) super.clone();
111
            // no changes to authority
112
            return result;
113
        } catch (CloneNotSupportedException e) {
114
            logger.warn("Object does not implement cloneable");
115
            e.printStackTrace();
116
            return null;
117
        }
118
    }
119
}
(13-13/77)