minor
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / GrantedAuthorityImpl.java
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.Entity;
13 import javax.xml.bind.annotation.XmlAccessType;
14 import javax.xml.bind.annotation.XmlAccessorType;
15 import javax.xml.bind.annotation.XmlElement;
16 import javax.xml.bind.annotation.XmlRootElement;
17 import javax.xml.bind.annotation.XmlType;
18
19 import org.apache.log4j.Logger;
20 import org.hibernate.annotations.NaturalId;
21 import org.springframework.security.core.GrantedAuthority;
22
23 @XmlAccessorType(XmlAccessType.FIELD)
24 @XmlType(name = "GrantedAuthority", propOrder = { "authority" })
25 @XmlRootElement(name = "Group")
26 @Entity
27 public class GrantedAuthorityImpl extends CdmBase implements GrantedAuthority {
28
29 private static final long serialVersionUID = 2651969425860655040L;
30 private static final Logger logger = Logger
31 .getLogger(GrantedAuthority.class);
32
33 @XmlElement(name = "Authority")
34 @NaturalId
35 private String authority;
36
37 protected GrantedAuthorityImpl() {
38 super();
39 }
40
41 public static GrantedAuthorityImpl NewInstance() {
42 return new GrantedAuthorityImpl();
43 }
44
45 /* (non-Javadoc)
46 * @see org.springframework.security.core.GrantedAuthority#getAuthority()
47 */
48 @Override
49 public String getAuthority() {
50 return authority;
51 }
52
53 public void setAuthority(String authority) {
54 this.authority = authority;
55 }
56
57 /**
58 * @param o
59 * @return
60 */
61 public int compareTo(Object o) {
62 if (o instanceof GrantedAuthority) {
63 return this.authority.compareTo(((GrantedAuthority) o).getAuthority());
64 }
65 return 0;
66 }
67
68 @Override
69 public boolean equals(Object o) {
70 if (o instanceof GrantedAuthority) {
71 if(this.authority == null && ((GrantedAuthority) o).getAuthority() == null) {
72 return true;
73 } else {
74 return this.authority.equals(((GrantedAuthority) o).getAuthority());
75 }
76 }
77 return false;
78 }
79
80 /* (non-Javadoc)
81 * @see eu.etaxonomy.cdm.model.common.CdmBase#toString()
82 */
83 @Override
84 public String toString() {
85 return getAuthority();
86 }
87
88 // *********** CLONE **********************************/
89
90 /**
91 * Clones <i>this</i> Granted Authority. This is a shortcut that enables to
92 * create a new instance that differs only slightly from <i>this</i> Granted
93 * Authority by modifying only some of the attributes.<BR>
94 *
95 *
96 *
97 * @see eu.etaxonomy.cdm.model.common.CdmBase#clone()
98 * @see java.lang.Object#clone()
99 */
100 @Override
101 public Object clone() {
102 GrantedAuthority result;
103 try {
104 result = (GrantedAuthority) super.clone();
105 // no changes to authority
106 return result;
107 } catch (CloneNotSupportedException e) {
108 logger.warn("Object does not implement cloneable");
109 e.printStackTrace();
110 return null;
111 }
112 }
113 }