|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AbstractBinding.java | - | 94.4% | 88.9% | 92.6% |
|
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
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 | * Base class for {@link IBinding}implementations. | |
25 | * | |
26 | * @author Howard Lewis Ship | |
27 | */ | |
28 | ||
29 | public abstract class AbstractBinding implements IBinding | |
30 | { | |
31 | /** @since 4.0 */ | |
32 | ||
33 | private final String _description; | |
34 | ||
35 | /** @since 4.0 */ | |
36 | ||
37 | private final ValueConverter _valueConverter; | |
38 | ||
39 | /** @since 3.0 */ | |
40 | ||
41 | private final Location _location; | |
42 | ||
43 | /** @since 3.0 */ | |
44 | ||
45 | 1705 | protected AbstractBinding(String description, ValueConverter valueConverter, Location location) |
46 | { | |
47 | 1705 | Defense.notNull(description, "description"); |
48 | 1705 | Defense.notNull(valueConverter, "valueConverter"); |
49 | ||
50 | 1705 | _description = description; |
51 | 1705 | _valueConverter = valueConverter; |
52 | 1705 | _location = location; |
53 | } | |
54 | ||
55 | 25 | public Location getLocation() |
56 | { | |
57 | 25 | return _location; |
58 | } | |
59 | ||
60 | /** | |
61 | * Overridden in subclasses that are not invariant. | |
62 | * | |
63 | * @throws ReadOnlyBindingException | |
64 | * always. | |
65 | */ | |
66 | ||
67 | 1 | public void setObject(Object value) |
68 | { | |
69 | 1 | throw createReadOnlyBindingException(this); |
70 | } | |
71 | ||
72 | /** | |
73 | * Default implementation: returns true. | |
74 | * | |
75 | * @since 2.0.3 | |
76 | */ | |
77 | ||
78 | 675 | public boolean isInvariant() |
79 | { | |
80 | 675 | return true; |
81 | } | |
82 | ||
83 | 2688 | public Object getObject(Class type) |
84 | { | |
85 | 2688 | Defense.notNull(type, "type"); |
86 | ||
87 | 2688 | Object raw = getObject(); |
88 | ||
89 | 2687 | try |
90 | { | |
91 | 2687 | return _valueConverter.coerceValue(raw, type); |
92 | } | |
93 | catch (Exception ex) | |
94 | { | |
95 | 1 | String message = BindingMessages.convertObjectError(this, ex); |
96 | ||
97 | 1 | throw new BindingException(message, getComponent(), _location, this, ex); |
98 | } | |
99 | } | |
100 | ||
101 | /** | |
102 | * Returns the component to which this binding is connected; this is currently only used when | |
103 | * building certain exceptions. This implementation returns null. | |
104 | * | |
105 | * @since 4.0 | |
106 | */ | |
107 | ||
108 | 2 | public Object getComponent() |
109 | { | |
110 | 2 | return null; |
111 | } | |
112 | ||
113 | /** @since 3.0 */ | |
114 | ||
115 | 2 | protected BindingException createReadOnlyBindingException(IBinding binding) |
116 | { | |
117 | 2 | return new BindingException(BindingMessages.readOnlyBinding(binding), binding); |
118 | } | |
119 | ||
120 | /** @since 4.0 */ | |
121 | ||
122 | 8 | public String getDescription() |
123 | { | |
124 | 8 | return _description; |
125 | } | |
126 | ||
127 | /** @since 4.0 */ | |
128 | 0 | public ValueConverter getValueConverter() |
129 | { | |
130 | 0 | return _valueConverter; |
131 | } | |
132 | } |
|