KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > binding > MessageBinding


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 JavaDoc _key;
37
38     protected MessageBinding(String JavaDoc description, ValueConverter valueConverter, Location location,
39             IComponent component, String JavaDoc key)
40     {
41         super(description, valueConverter, location);
42
43         Defense.notNull(component, "component");
44         Defense.notNull(key, "key");
45
46         _component = component;
47         _key = key;
48     }
49
50     public Object JavaDoc getComponent()
51     {
52         return _component;
53     }
54
55     public String JavaDoc getKey()
56     {
57         return _key;
58     }
59
60     /**
61      * Accesses the specified localized string. Never returns null.
62      */

63
64     public Object JavaDoc getObject()
65     {
66         return _component.getMessages().getMessage(_key);
67     }
68
69     public String JavaDoc toString()
70     {
71         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("StringBinding");
72         buffer.append('[');
73         buffer.append(_component.getExtendedId());
74         buffer.append(' ');
75         buffer.append(_key);
76         buffer.append(']');
77
78         return buffer.toString();
79     }
80 }
Popular Tags