KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > bean > ControlBeanInfo


1 package org.apache.beehive.controls.runtime.bean;
2 /*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * $Header:$
18  */

19
20 import java.util.Locale JavaDoc;
21 import java.util.MissingResourceException JavaDoc;
22 import java.util.ResourceBundle JavaDoc;
23
24 /**
25  * The ControlBeanInfo class is an abstract base class for the JavaBean BeanInfo classes generated
26  * to support Beehive controls. It is used to bundle helper code common across all generated
27  * BeanInfo classes.
28  */

29 abstract public class ControlBeanInfo extends java.beans.SimpleBeanInfo JavaDoc
30 {
31     /**
32      * Protected constructor that is called from generated BeanInfo subclasses.
33      * @param beanClass the JavaBean class for which BeanInfo is being provided.
34      */

35     protected ControlBeanInfo(Class JavaDoc beanClass)
36     {
37         super();
38         _beanClass = beanClass;
39     }
40
41     /*
42      * Gets a possibly-localized string for the given input string.
43      * @param input This the the string that may be localizable. If it is of the form
44      * "%foo.bar.Baz%", then the resource Baz will be looked up in the foo.bar bundle using
45      * standard ResourceBundle rules for the default Locale using the control's classloader.
46      * If the input does not start and end with '%', or if the bundle is not located, the string
47      * will be returned verbatim.
48      * @return the string to be displayed, or the input string if no resource is found.
49      */

50     final protected String JavaDoc localizeString(String JavaDoc input)
51     {
52         if (input == null || !input.startsWith("%") || !input.endsWith("%"))
53             return input;
54         String JavaDoc bundleName = input.substring(1, input.length()-1);
55         String JavaDoc resourceName = null;
56         String JavaDoc output = input;
57         int lastDot = bundleName.lastIndexOf('.');
58         while (lastDot != -1 && lastDot != 0 && (lastDot+1 < bundleName.length()))
59         {
60             // move last element from bundle to resource. foo.bar.Baz could be the
61
// Baz property in foo.bar, or the bar.Baz property in foo.
62
if (resourceName == null)
63                 resourceName = bundleName.substring(lastDot+1);
64             else
65                 resourceName = bundleName.substring(lastDot+1) + '.' + resourceName;
66             bundleName = bundleName.substring(0, lastDot);
67
68             try
69             {
70                 ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault(),
71                                                                  _beanClass.getClassLoader());
72                 if (bundle != null)
73                 {
74                     String JavaDoc lookup = bundle.getString(resourceName);
75                     if (lookup != null)
76                         return lookup;
77                 }
78             }
79             catch (MissingResourceException JavaDoc mre)
80             { }
81                 
82             lastDot = bundleName.lastIndexOf('.');
83
84         }
85
86         return input;
87     }
88
89     Class JavaDoc _beanClass;
90 }
91
Popular Tags