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 | 0 | super(description, valueConverter, location); |
33 | |
|
34 | 0 | Defense.notNull(component, "component"); |
35 | 0 | Defense.notNull(componentIds, "componentIds"); |
36 | |
|
37 | 0 | _target = component; |
38 | 0 | _componentIds = componentIds; |
39 | 0 | _targets = new IComponent[_componentIds.length]; |
40 | 0 | } |
41 | |
|
42 | |
public Object getObject() |
43 | |
{ |
44 | |
try |
45 | |
{ |
46 | 0 | List clientIds = new ArrayList(_componentIds.length); |
47 | |
|
48 | 0 | for (int i=0; i < _componentIds.length; i++) |
49 | |
{ |
50 | 0 | if (_targets[i] == null) |
51 | |
{ |
52 | 0 | if (_target.getComponents().containsKey(_componentIds[i])) |
53 | |
{ |
54 | 0 | _targets[i] = _target.getComponent(_componentIds[i]); |
55 | 0 | } else if (_target.getPage() != null) { |
56 | |
|
57 | 0 | _targets[i] = _target.getPage().getComponent(_componentIds[i]); |
58 | |
} |
59 | |
|
60 | |
|
61 | |
|
62 | 0 | if (_targets[i] == null) |
63 | 0 | throw new ApplicationRuntimeException(BindingMessages.unknownComponent(_target, _componentIds[i]), getLocation(), null); |
64 | |
} |
65 | |
|
66 | 0 | clientIds.add(_targets[i].getClientId()); |
67 | |
} |
68 | |
|
69 | 0 | return clientIds; |
70 | |
} |
71 | 0 | catch (Exception ex) |
72 | |
{ |
73 | 0 | throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex); |
74 | |
} |
75 | |
} |
76 | |
|
77 | |
public Object getComponent() |
78 | |
{ |
79 | 0 | return _target; |
80 | |
} |
81 | |
|
82 | |
public boolean isInvariant() |
83 | |
{ |
84 | 0 | return false; |
85 | |
} |
86 | |
} |