|
|||||||||||||||||||
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 | |||||||||||||||
MessageBinding.java | - | 100% | 100% | 100% |
|
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#getString(String) | |
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 | private final String _key; | |
37 | ||
38 | 12 | protected MessageBinding(String description, ValueConverter valueConverter, Location location, |
39 | IComponent component, String key) | |
40 | { | |
41 | 12 | super(description, valueConverter, location); |
42 | ||
43 | 12 | Defense.notNull(component, "component"); |
44 | 12 | Defense.notNull(key, "key"); |
45 | ||
46 | 12 | _component = component; |
47 | 12 | _key = key; |
48 | } | |
49 | ||
50 | 1 | public Object getComponent() |
51 | { | |
52 | 1 | return _component; |
53 | } | |
54 | ||
55 | 1 | public String getKey() |
56 | { | |
57 | 1 | return _key; |
58 | } | |
59 | ||
60 | /** | |
61 | * Accesses the specified localized string. Never returns null. | |
62 | */ | |
63 | ||
64 | 13 | public Object getObject() |
65 | { | |
66 | 13 | return _component.getMessages().getMessage(_key); |
67 | } | |
68 | ||
69 | 1 | public String toString() |
70 | { | |
71 | 1 | StringBuffer buffer = new StringBuffer("StringBinding"); |
72 | 1 | buffer.append('['); |
73 | 1 | buffer.append(_component.getExtendedId()); |
74 | 1 | buffer.append(' '); |
75 | 1 | buffer.append(_key); |
76 | 1 | buffer.append(']'); |
77 | ||
78 | 1 | return buffer.toString(); |
79 | } | |
80 | } |
|