|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.acl.basic; |
|
17 |
| |
|
18 |
| import org.springframework.util.Assert; |
|
19 |
| |
|
20 |
| import java.lang.reflect.InvocationTargetException; |
|
21 |
| import java.lang.reflect.Method; |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| public class NamedEntityObjectIdentity implements AclObjectIdentity { |
|
34 |
| |
|
35 |
| |
|
36 |
| private String classname; |
|
37 |
| private String id; |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
168
| public NamedEntityObjectIdentity(String classname, String id) {
|
|
42 |
168
| Assert.hasText(classname, "classname required");
|
|
43 |
166
| Assert.hasText(id, "id required");
|
|
44 |
164
| this.classname = classname;
|
|
45 |
164
| this.id = id;
|
|
46 |
| } |
|
47 |
| |
|
48 |
1
| protected NamedEntityObjectIdentity() {
|
|
49 |
1
| throw new IllegalArgumentException("Cannot use default constructor");
|
|
50 |
| } |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
9
| public NamedEntityObjectIdentity(Object object)
|
|
64 |
| throws IllegalAccessException, InvocationTargetException { |
|
65 |
9
| Assert.notNull(object, "object cannot be null");
|
|
66 |
| |
|
67 |
8
| this.classname = object.getClass().getName();
|
|
68 |
| |
|
69 |
8
| Class clazz = object.getClass();
|
|
70 |
| |
|
71 |
8
| try {
|
|
72 |
8
| Method method = clazz.getMethod("getId", new Class[] {});
|
|
73 |
3
| Object result = method.invoke(object, new Object[] {});
|
|
74 |
3
| this.id = result.toString();
|
|
75 |
| } catch (NoSuchMethodException nsme) { |
|
76 |
5
| throw new IllegalArgumentException("Object of class '" + clazz
|
|
77 |
| + "' does not provide the required getId() method: " + object); |
|
78 |
| } |
|
79 |
| } |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
13
| public boolean equals(Object arg0) {
|
|
96 |
13
| if (arg0 == null) {
|
|
97 |
1
| return false;
|
|
98 |
| } |
|
99 |
| |
|
100 |
12
| if (!(arg0 instanceof NamedEntityObjectIdentity)) {
|
|
101 |
1
| return false;
|
|
102 |
| } |
|
103 |
| |
|
104 |
11
| NamedEntityObjectIdentity other = (NamedEntityObjectIdentity) arg0;
|
|
105 |
| |
|
106 |
11
| if (this.getId().equals(other.getId())
|
|
107 |
| && this.getClassname().equals(other.getClassname())) { |
|
108 |
10
| return true;
|
|
109 |
| } |
|
110 |
| |
|
111 |
1
| return false;
|
|
112 |
| } |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
82
| public String getClassname() {
|
|
120 |
82
| return classname;
|
|
121 |
| } |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
84
| public String getId() {
|
|
129 |
84
| return id;
|
|
130 |
| } |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
15
| public int hashCode() {
|
|
138 |
15
| StringBuffer sb = new StringBuffer();
|
|
139 |
15
| sb.append(this.classname).append(this.id);
|
|
140 |
| |
|
141 |
15
| return sb.toString().hashCode();
|
|
142 |
| } |
|
143 |
| |
|
144 |
63
| public String toString() {
|
|
145 |
63
| StringBuffer sb = new StringBuffer();
|
|
146 |
63
| sb.append(this.getClass().getName()).append("[");
|
|
147 |
63
| sb.append("Classname: ").append(this.classname);
|
|
148 |
63
| sb.append("; Identity: ").append(this.id).append("]");
|
|
149 |
| |
|
150 |
63
| return sb.toString();
|
|
151 |
| } |
|
152 |
| } |