Project

General

Profile

Download (3.25 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.commons.lang.StringUtils;
22
import org.apache.log4j.Logger;
23
import org.springframework.security.core.GrantedAuthority;
24

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

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

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

    
39
    protected GrantedAuthorityImpl() {
40
        super();
41
    }
42

    
43
    public static GrantedAuthorityImpl NewInstance() {
44
        return new GrantedAuthorityImpl();
45
    }
46

    
47
    @Override
48
    public String getAuthority() {
49
        return authority;
50
    }
51

    
52
    public void setAuthority(String authority) {
53
    	this.authority = authority;
54
    }
55

    
56
    /**
57
     * @param o
58
     * @return
59
     */
60
    public int compareTo(Object o) {
61
        if (o instanceof GrantedAuthority) {
62
            return this.authority.compareTo(((GrantedAuthority) o).getAuthority());
63
        }
64
        return 0;
65
    }
66
    
67
    @Override
68
    public boolean equals(Object o) {
69
        if (o instanceof GrantedAuthority) {
70
        	if(this.authority == null && ((GrantedAuthority) o).getAuthority() == null) {
71
        		return true;
72
        	} else {
73
        		return this.authority.equals(((GrantedAuthority) o).getAuthority());
74
        	}
75
        }
76
        return false;
77
    }
78

    
79
    /* (non-Javadoc)
80
     * @see eu.etaxonomy.cdm.model.common.CdmBase#toString()
81
     */
82
    @Override
83
    public String toString() {
84
        return getAuthority();
85
    }
86

    
87
    // *********** CLONE **********************************/
88

    
89
    /**
90
     * Clones <i>this</i> Granted Authority. This is a shortcut that enables to
91
     * create a new instance that differs only slightly from <i>this</i> Granted
92
     * Authority by modifying only some of the attributes.<BR>
93
     *
94
     *
95
     *
96
     * @see eu.etaxonomy.cdm.model.common.CdmBase#clone()
97
     * @see java.lang.Object#clone()
98
     */
99
    @Override
100
    public Object clone() {
101
        GrantedAuthority result;
102
        try {
103
            result = (GrantedAuthority) super.clone();
104
            // no changes to authority
105
            return result;
106
        } catch (CloneNotSupportedException e) {
107
            logger.warn("Object does not implement cloneable");
108
            e.printStackTrace();
109
            return null;
110
        }
111
    }
112
}
(13-13/72)