Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
MessageBinding |
|
| 1.0;1 |
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.IComponent; |
|
20 | import org.apache.tapestry.coerce.ValueConverter; |
|
21 | ||
22 | /** |
|
23 | * A binding that connects directly to a localized string for a component. |
|
24 | * <p> |
|
25 | * Note: Renamed from StringBinding to MessageBinding in release 4.0. |
|
26 | * |
|
27 | * @see IComponent#getMessages() |
|
28 | * @author Howard Lewis Ship |
|
29 | * @since 2.0.4 |
|
30 | */ |
|
31 | ||
32 | public class MessageBinding extends AbstractBinding |
|
33 | { |
|
34 | private final IComponent _component; |
|
35 | ||
36 | protected MessageBinding(String description, ValueConverter valueConverter, Location location, |
|
37 | IComponent component, String key) |
|
38 | { |
|
39 | 3 | super(key, valueConverter, location); |
40 | ||
41 | 3 | Defense.notNull(component, "component"); |
42 | 3 | Defense.notNull(key, "key"); |
43 | ||
44 | 3 | _component = component; |
45 | 3 | } |
46 | ||
47 | public Object getComponent() |
|
48 | { |
|
49 | 1 | return _component; |
50 | } |
|
51 | ||
52 | public String getKey() |
|
53 | { |
|
54 | 1 | return _description; |
55 | } |
|
56 | ||
57 | /** |
|
58 | * Accesses the specified localized string. Never returns null. |
|
59 | */ |
|
60 | ||
61 | public Object getObject() |
|
62 | { |
|
63 | 1 | return _component.getMessages().getMessage(_description); |
64 | } |
|
65 | ||
66 | public String toString() |
|
67 | { |
|
68 | 1 | StringBuffer buffer = new StringBuffer("MessageBinding"); |
69 | 1 | buffer.append('['); |
70 | 1 | buffer.append(_component.getExtendedId()); |
71 | 1 | buffer.append(' '); |
72 | 1 | buffer.append(_description); |
73 | 1 | buffer.append(']'); |
74 | ||
75 | 1 | return buffer.toString(); |
76 | } |
|
77 | } |