1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.policy.bean.basic; |
11 | |
|
12 | |
import static org.openpermis.policy.bean.basic.BasicUtilities.equalObjects; |
13 | |
import static org.openpermis.policy.bean.basic.BasicUtilities.getIdentityDetails; |
14 | |
import static org.openpermis.policy.bean.basic.BasicUtilities.getNameDetails; |
15 | |
import static org.openpermis.policy.bean.basic.BasicUtilities.multiHashCode; |
16 | |
|
17 | |
import java.net.URI; |
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.openpermis.policy.Action; |
21 | |
import org.openpermis.policy.PartProblemReporter; |
22 | |
import org.openpermis.policy.PartProblemReporter.ProblemMessage; |
23 | |
import org.openpermis.policy.bean.ActionBean; |
24 | |
import org.openpermis.policy.bean.ActionBeanCollection; |
25 | |
import org.openpermis.policy.bean.DomainBean; |
26 | |
import org.openpermis.policy.bean.PartBean; |
27 | |
import org.openpermis.policy.bean.SerialNumber; |
28 | |
import org.openpermis.policy.bean.TargetBean; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class BasicTarget |
36 | |
extends BasicPartBean |
37 | |
implements TargetBean |
38 | |
{ |
39 | |
|
40 | |
|
41 | |
|
42 | |
private static final long serialVersionUID = -4155346349094013032L; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
private DomainBean domain; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
private ActionBeanCollection actions; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
protected BasicTarget ( |
67 | |
SerialNumber serialNumber, |
68 | |
DomainBean resourceDomain, |
69 | |
ActionBeanCollection actions |
70 | |
) { |
71 | 591 | super(TargetBean.class, serialNumber); |
72 | 591 | this.actions = new BasicActionCollection(serialNumber.next()); |
73 | 591 | setResourceDomain(resourceDomain); |
74 | 591 | setActions(actions); |
75 | 591 | } |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public Action findAction (URI resourceUri, String actionName, List<?> arguments) { |
85 | 52 | if (getResourceDomain() != null && getResourceDomain().contains(resourceUri)) { |
86 | 52 | return getActions().findMatch(actionName, arguments); |
87 | |
} |
88 | 0 | return null; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public DomainBean getResourceDomain () { |
97 | 1675 | return this.domain; |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
public void setResourceDomain (DomainBean resourceDomain) { |
104 | 591 | final DomainBean oldResourceDomain = getResourceDomain(); |
105 | 591 | this.domain = resourceDomain; |
106 | 591 | firePropertyChange("resourceDomain", oldResourceDomain, getResourceDomain()); |
107 | 591 | } |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public ActionBeanCollection getActions () { |
113 | 1560 | return this.actions; |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public void setActions (ActionBeanCollection actions) { |
120 | 593 | final ActionBeanCollection oldActions = getActions(); |
121 | 593 | if (actions == null) { |
122 | 2 | this.actions = new BasicActionCollection(getSerialNumber().next()); |
123 | |
} else { |
124 | 591 | this.actions = actions; |
125 | |
} |
126 | 593 | firePropertyChange("actions", oldActions, getActions()); |
127 | 593 | } |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
@Deprecated |
134 | |
public void removeChild (ActionBean part) { |
135 | 0 | final ActionBeanCollection oldCollection = this.getActions(); |
136 | 0 | final List<ActionBean> list = oldCollection.toList(); |
137 | 0 | list.remove(part); |
138 | 0 | setActions(oldCollection.create(list)); |
139 | 0 | } |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
@Override |
147 | |
public boolean isPartValid (PartProblemReporter reporter) { |
148 | |
boolean valid; |
149 | |
|
150 | |
|
151 | 9 | valid = true; |
152 | |
|
153 | |
|
154 | 9 | if (!isChildValid(reporter, getResourceDomain())) { |
155 | 1 | valid = false; |
156 | 1 | reportProblem(reporter, ProblemMessage.illegalResourceDomain); |
157 | |
} |
158 | |
|
159 | |
|
160 | 9 | if (!isChildCollectionValid(reporter, getActions(), true, true, true, true, false)) { |
161 | 3 | valid = false; |
162 | 3 | reportProblem(reporter, ProblemMessage.illegalActions); |
163 | |
} |
164 | |
|
165 | |
|
166 | 9 | return valid; |
167 | |
} |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
@Override |
173 | |
protected boolean comparablePart (BasicPart part) { |
174 | 216 | return part instanceof TargetBean; |
175 | |
} |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
@Override |
181 | |
protected boolean equalPart (BasicPart part) { |
182 | 108 | final TargetBean target = (TargetBean) part; |
183 | 108 | return |
184 | |
equalObjects(getResourceDomain(), target.getResourceDomain()) && |
185 | |
equalObjects(getActions(), target.getActions()); |
186 | |
} |
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
@Override |
192 | |
protected int partHashCode () { |
193 | 68 | return multiHashCode( |
194 | |
getResourceDomain() == null ? 0 : getResourceDomain().hashCode(), |
195 | |
getActions().hashCode() |
196 | |
); |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
@Override |
203 | |
protected String getSimpleClassName () { |
204 | 0 | return TargetBean.class.getSimpleName(); |
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
@Override |
211 | |
protected void appendPartDetails (StringBuilder sb) { |
212 | 0 | appendDetails(sb, "resourceDomain", getIdentityDetails(getResourceDomain())); |
213 | 0 | appendDetails(sb, "actions", getNameDetails(getActions())); |
214 | 0 | } |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
@Override |
222 | |
public PartBean findBySerialNumber (SerialNumber partSerialNumber) { |
223 | 5 | PartBean bean = getResourceDomain().findBySerialNumber(partSerialNumber); |
224 | 5 | if (bean != null) { |
225 | 1 | return bean; |
226 | |
} |
227 | |
|
228 | 4 | for (final ActionBean action : getActions()) { |
229 | 4 | bean = action.findBySerialNumber(partSerialNumber); |
230 | 4 | if (bean != null) { |
231 | 1 | return bean; |
232 | |
} |
233 | |
} |
234 | |
|
235 | 3 | return super.findBySerialNumber(partSerialNumber); |
236 | |
} |
237 | |
|
238 | |
} |