1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package org.apache.tapestry.portlet.bindings; |
16 | |
|
17 | |
import java.util.Map; |
18 | |
|
19 | |
import javax.portlet.PortletRequest; |
20 | |
|
21 | |
import org.apache.hivemind.ApplicationRuntimeException; |
22 | |
import org.apache.hivemind.Location; |
23 | |
import org.apache.hivemind.util.Defense; |
24 | |
import org.apache.tapestry.binding.AbstractBinding; |
25 | |
import org.apache.tapestry.coerce.ValueConverter; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public class UserAttributeBinding extends AbstractBinding |
34 | |
{ |
35 | |
private final PortletRequest _request; |
36 | |
|
37 | |
private final String _attributeName; |
38 | |
|
39 | |
public UserAttributeBinding(String description, ValueConverter valueConverter, |
40 | |
Location location, PortletRequest request, String attributeName) |
41 | |
{ |
42 | 0 | super(description, valueConverter, location); |
43 | |
|
44 | 0 | Defense.notNull(request, "request"); |
45 | 0 | Defense.notNull(attributeName, "attributeName"); |
46 | |
|
47 | 0 | _request = request; |
48 | 0 | _attributeName = attributeName; |
49 | 0 | } |
50 | |
|
51 | |
public boolean isInvariant() |
52 | |
{ |
53 | |
|
54 | 0 | return false; |
55 | |
} |
56 | |
|
57 | |
private Map getUserInfo() |
58 | |
{ |
59 | 0 | Map result = (Map) _request.getAttribute(PortletRequest.USER_INFO); |
60 | |
|
61 | 0 | if (result == null) |
62 | 0 | throw new ApplicationRuntimeException(BindingsMessages.noUserInfo(), getLocation(), |
63 | |
null); |
64 | |
|
65 | 0 | return result; |
66 | |
} |
67 | |
|
68 | |
public Object getObject() |
69 | |
{ |
70 | 0 | return getUserInfo().get(_attributeName); |
71 | |
} |
72 | |
|
73 | |
public void setObject(Object value) |
74 | |
{ |
75 | 0 | String asString = (String) getValueConverter().coerceValue(value, String.class); |
76 | |
|
77 | 0 | getUserInfo().put(_attributeName, asString); |
78 | 0 | } |
79 | |
} |