|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.binding; |
|
16 |
| |
|
17 |
| import org.apache.hivemind.Location; |
|
18 |
| import org.apache.hivemind.util.Defense; |
|
19 |
| import org.apache.tapestry.BindingException; |
|
20 |
| import org.apache.tapestry.IBinding; |
|
21 |
| import org.apache.tapestry.coerce.ValueConverter; |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| public abstract class AbstractBinding implements IBinding |
|
30 |
| { |
|
31 |
| |
|
32 |
| |
|
33 |
| private final String _description; |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| private final ValueConverter _valueConverter; |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| private final Location _location; |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
5043
| protected AbstractBinding(String description, ValueConverter valueConverter, Location location)
|
|
46 |
| { |
|
47 |
5043
| Defense.notNull(description, "description");
|
|
48 |
5043
| Defense.notNull(valueConverter, "valueConverter");
|
|
49 |
| |
|
50 |
5043
| _description = description;
|
|
51 |
5043
| _valueConverter = valueConverter;
|
|
52 |
5043
| _location = location;
|
|
53 |
| } |
|
54 |
| |
|
55 |
60
| public Location getLocation()
|
|
56 |
| { |
|
57 |
60
| return _location;
|
|
58 |
| } |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
3
| public void setObject(Object value)
|
|
68 |
| { |
|
69 |
3
| throw createReadOnlyBindingException(this);
|
|
70 |
| } |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
1926
| public boolean isInvariant()
|
|
79 |
| { |
|
80 |
1926
| return true;
|
|
81 |
| } |
|
82 |
| |
|
83 |
7386
| public Object getObject(Class type)
|
|
84 |
| { |
|
85 |
7386
| Defense.notNull(type, "type");
|
|
86 |
| |
|
87 |
7386
| Object raw = getObject();
|
|
88 |
| |
|
89 |
7383
| try
|
|
90 |
| { |
|
91 |
7383
| return _valueConverter.coerceValue(raw, type);
|
|
92 |
| } |
|
93 |
| catch (Exception ex) |
|
94 |
| { |
|
95 |
3
| String message = BindingMessages.convertObjectError(this, ex);
|
|
96 |
| |
|
97 |
3
| throw new BindingException(message, getComponent(), _location, this, ex);
|
|
98 |
| } |
|
99 |
| } |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
6
| public Object getComponent()
|
|
109 |
| { |
|
110 |
6
| return null;
|
|
111 |
| } |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
6
| protected BindingException createReadOnlyBindingException(IBinding binding)
|
|
116 |
| { |
|
117 |
6
| return new BindingException(BindingMessages.readOnlyBinding(binding), binding);
|
|
118 |
| } |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
24
| public String getDescription()
|
|
123 |
| { |
|
124 |
24
| return _description;
|
|
125 |
| } |
|
126 |
| |
|
127 |
| |
|
128 |
0
| public ValueConverter getValueConverter()
|
|
129 |
| { |
|
130 |
0
| return _valueConverter;
|
|
131 |
| } |
|
132 |
| |
|
133 |
3
| public String toString()
|
|
134 |
| { |
|
135 |
3
| StringBuffer buffer = new StringBuffer();
|
|
136 |
3
| buffer.append(getClass().getName());
|
|
137 |
3
| buffer.append("@");
|
|
138 |
3
| buffer.append(Integer.toHexString(hashCode()));
|
|
139 |
3
| buffer.append("[");
|
|
140 |
3
| buffer.append(_description);
|
|
141 |
| |
|
142 |
3
| extendDescription(buffer);
|
|
143 |
| |
|
144 |
3
| buffer.append(", location=");
|
|
145 |
3
| buffer.append(_location);
|
|
146 |
3
| buffer.append("]");
|
|
147 |
| |
|
148 |
3
| return buffer.toString();
|
|
149 |
| } |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
0
| protected void extendDescription(StringBuffer buffer)
|
|
155 |
| { |
|
156 |
| |
|
157 |
| } |
|
158 |
| } |