KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > util > AdminLocalStringsManager


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.admin.util;
24
25 import java.util.ResourceBundle JavaDoc;
26 import java.util.Locale JavaDoc;
27 import java.text.MessageFormat JavaDoc;
28
29
30 /**
31  * Implementation of a Admin local string manager as Admin-specific wrapper around LocalStringsManager;
32  * Provides access to i18n messages for classes that need them.
33  * This particular implementation presents the following resources organization:
34  *<ul>
35  * <li>1. Resource files share locations with sources (same directories);</li>
36  * <li>2. Base directory is "com.sun.enterprise.admin";</li>
37  * <li>3. Search ONLY in first resource bundle, which found on the way up to basePackage( No additional hiearchical search of value if it is not found in that file)</li>
38  *</ul>
39  */

40
41 public class AdminLocalStringsManager extends LocalStringsManager
42 {
43     static final String JavaDoc ADMIN_BASE_PACKAGE = "com.sun.enterprise.admin";
44     static final String JavaDoc DEFAULT_PROPERTY_FILE_NAME = "LocalStrings";
45
46     /** <b>Messages</b> Property File Type (file name prefix) */
47     public static final String JavaDoc MESSAGES = "Messages";
48     /** <b>Decriptions</b> Property File Type (file name prefix) */
49     public static final String JavaDoc DESCRIPTIONS = "MBeansInfo";
50
51     /**
52      * Create a string manager that looks for default type properties(MESSAGES) in
53      * the package of the callerObject or parent Admin packages.
54      * @param callerObject the caller object (defines starting package for searching)
55      */

56     public AdminLocalStringsManager(Object JavaDoc callerObject)
57     {
58         this(callerObject, DEFAULT_PROPERTY_FILE_NAME);
59     }
60
61     /**
62      * Create a string manager that looks for -propertyFileName-.properties in
63      * the package of the callerObject or parent Admin packages;
64      * <br>It's supposed that propertyFileName should be one of well-known names,
65      * defined by constants: MESSAGES/DESCRIPTIONS/NOTIFICATIONS etc.
66      * @param callerObject The caller object (defines starting package for searching).
67      * @param propertyFileName property file name prefix (e.g. "myStrings");
68      */

69     public AdminLocalStringsManager(Object JavaDoc callerObject, String JavaDoc propertyFileName)
70     {
71         super(ADMIN_BASE_PACKAGE, propertyFileName);
72         String JavaDoc callerClassPath;
73         if(callerObject==null)
74             callerClassPath = ADMIN_BASE_PACKAGE; //reffer to base
75
else
76         {
77             callerClassPath = callerObject.getClass().getName();
78             callerClassPath = callerClassPath.substring(0, callerClassPath.lastIndexOf('.'));
79         }
80         setFixedResourceBundle(callerClassPath);
81     }
82
83     /**
84      * Convenient Factory class for obtaining a Admin string manager for message type strings.
85      * @param callerObject The caller object (defines starting package for searching).
86      */

87     public static AdminLocalStringsManager createMessagesManager(Object JavaDoc callerObject)
88     {
89        return new AdminLocalStringsManager(callerObject, MESSAGES);
90     }
91     /**
92      * Convenient Factory class for obtaining a Admin string manager for description type strings.
93      * @param callerObject The caller object (defines starting package for searching).
94      */

95     public static AdminLocalStringsManager createDescriptionsManager(Object JavaDoc callerObject)
96     {
97        return new AdminLocalStringsManager(callerObject, DESCRIPTIONS);
98     }
99     
100     
101     /**
102      * Get a localized string.
103      * @param key The name of the resource to fetch
104      * @param defaultValue The default return value if not found
105      * @return The localized string
106      */

107     public String JavaDoc getString( String JavaDoc key, String JavaDoc defaultValue)
108     {
109         return super.getString(key, defaultValue);
110     }
111
112     /**
113      * Get a local string and format the arguments accordingly.
114      * @param key The key to the local format string
115      * @param defaultFormat The default format if not found in the resources
116      * @param arguments The set of arguments to provide to the formatter
117      * @return A formatted localized string
118      */

119     public String JavaDoc getString( String JavaDoc key, String JavaDoc defaultFormat, Object JavaDoc[] args)
120     {
121         return super.getString(key, defaultFormat, args);
122     }
123
124     /**
125      * Convenience method - getString() overriding for fixed number of formatting arguments.
126      * @param key The key to the local format string
127      * @param defaultFormat The default format if not found in the resources
128      * @param arg1 The first argument to provide to the formatter
129      * @return A formatted localized string
130      */

131     public String JavaDoc getString( String JavaDoc key, String JavaDoc defaultFormat, Object JavaDoc arg1)
132     {
133         return getString(key, defaultFormat, (new Object JavaDoc[]{arg1}));
134     }
135
136     /**
137      * Convenience method - getString() overriding for fixed number of formatting arguments.
138      * @param key The key to the local format string
139      * @param defaultFormat The default format if not found in the resources
140      * @param arg1 The first argument to provide to the formatter
141      * @param arg1 The second argument to provide to the formatter
142      * @return A formatted localized string
143      */

144     public String JavaDoc getString( String JavaDoc key, String JavaDoc defaultFormat, Object JavaDoc arg1, Object JavaDoc arg2)
145     {
146         return getString(key, defaultFormat, (new Object JavaDoc[]{arg1, arg2}));
147     }
148
149     /**
150      * Convenience method - getString() overriding for fixed number of formatting arguments.
151      * @param key The key to the local format string
152      * @param defaultFormat The default format if not found in the resources
153      * @param arg1 The first argument to provide to the formatter
154      * @param arg2 The second argument to provide to the formatter
155      * @param arg3 The third argument to provide to the formatter
156      * @return A formatted localized string
157      */

158     public String JavaDoc getString( String JavaDoc key, String JavaDoc defaultFormat, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3)
159     {
160         return getString(key, defaultFormat, (new Object JavaDoc[]{arg1, arg2, arg3}));
161     }
162 }
163
164
Popular Tags