1 |
|
package org.apache.tapestry.binding; |
2 |
|
|
3 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
4 |
|
import org.apache.hivemind.Location; |
5 |
|
import org.apache.hivemind.util.Defense; |
6 |
|
import org.apache.tapestry.IComponent; |
7 |
|
import org.apache.tapestry.coerce.ValueConverter; |
8 |
|
|
9 |
|
import java.util.ArrayList; |
10 |
|
import java.util.List; |
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
public class ClientIdListBinding extends AbstractBinding { |
23 |
|
|
24 |
|
private final IComponent _target; |
25 |
|
|
26 |
|
private final String[] _componentIds; |
27 |
|
private IComponent[] _targets; |
28 |
|
|
29 |
|
public ClientIdListBinding(String description, ValueConverter valueConverter, |
30 |
|
Location location, IComponent component, String[] componentIds) |
31 |
|
{ |
32 |
3 |
super(description, valueConverter, location); |
33 |
|
|
34 |
3 |
Defense.notNull(component, "component"); |
35 |
3 |
Defense.notNull(componentIds, "componentIds"); |
36 |
|
|
37 |
3 |
_target = component; |
38 |
3 |
_componentIds = componentIds; |
39 |
3 |
_targets = new IComponent[_componentIds.length]; |
40 |
3 |
} |
41 |
|
|
42 |
|
public Object getObject() |
43 |
|
{ |
44 |
|
try |
45 |
|
{ |
46 |
3 |
List clientIds = new ArrayList(_componentIds.length); |
47 |
|
|
48 |
6 |
for (int i=0; i < _componentIds.length; i++) |
49 |
|
{ |
50 |
4 |
if (_targets[i] == null) |
51 |
|
{ |
52 |
4 |
if (_target.getComponents().containsKey(_componentIds[i])) |
53 |
|
{ |
54 |
3 |
_targets[i] = _target.getComponent(_componentIds[i]); |
55 |
1 |
} else if (_target.getPage() != null) { |
56 |
|
|
57 |
0 |
_targets[i] = _target.getPage().getComponent(_componentIds[i]); |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
4 |
if (_targets[i] == null) |
63 |
1 |
throw new ApplicationRuntimeException(BindingMessages.unknownComponent(_target, _componentIds[i]), getLocation(), null); |
64 |
|
} |
65 |
|
|
66 |
3 |
clientIds.add(_targets[i].getClientId()); |
67 |
|
} |
68 |
|
|
69 |
2 |
return clientIds; |
70 |
|
} |
71 |
1 |
catch (Exception ex) |
72 |
|
{ |
73 |
1 |
throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex); |
74 |
|
} |
75 |
|
} |
76 |
|
|
77 |
|
public Object getComponent() |
78 |
|
{ |
79 |
2 |
return _target; |
80 |
|
} |
81 |
|
|
82 |
|
public boolean isInvariant() |
83 |
|
{ |
84 |
0 |
return false; |
85 |
|
} |
86 |
|
} |