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