KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > jmx > remote > StringManager


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
24 package com.sun.enterprise.admin.jmx.remote;
25
26 import com.sun.enterprise.admin.jmx.remote.IStringManager;
27
28 import java.lang.reflect.Method JavaDoc;
29 //import java.lang.reflect.Constructor;
30
import java.util.logging.Logger JavaDoc;
31
32 /**
33  * This class acts as an adapter to use the appserver internal StringManager.
34  * It implements the IStringManager interface that is defined for an
35  * jmx-connector string-manager. At the same time it composes a delegatee
36  * com.sun.enterprise.util.i18n.StringManager object.
37  * The method invocation on this delegatee is through reflection to avoid any
38  * compile time dependencies
39  */

40 public class StringManager implements IStringManager {
41     
42     private static final Logger JavaDoc logger = Logger.getLogger(
43         DefaultConfiguration.JMXCONNECTOR_LOGGER);/*,
44         DefaultConfiguration.LOGGER_RESOURCE_BUNDLE_NAME );*/

45     
46     private static Class JavaDoc asStringManagerClass = null;
47     private static Method JavaDoc getStr = null;
48     private static Method JavaDoc getStrDef = null;
49     private static Method JavaDoc getStrGeneric = null;
50     private static Method JavaDoc getManager = null;
51     
52     //this is the composed AS9.0 internal default StringManager
53
private Object JavaDoc asStringManager = null;
54     
55     public StringManager(String JavaDoc packageName) {
56         try {
57             if (asStringManagerClass == null) {
58                 asStringManagerClass = Class.forName("com.sun.enterprise.util.i18n.StringManager");
59                 getStr = asStringManagerClass.getMethod("getString", new Class JavaDoc[] { String JavaDoc.class});
60                 getStrDef = asStringManagerClass.getMethod("getString", new Class JavaDoc[] { String JavaDoc.class, Object JavaDoc.class });
61                 getStrGeneric = asStringManagerClass.getMethod("getString", new Class JavaDoc[] { String JavaDoc.class, Object JavaDoc[].class });
62                 getManager = asStringManagerClass.getMethod("getManager", new Class JavaDoc[] { String JavaDoc.class });
63             }
64             
65             asStringManager = getManager.invoke(asStringManagerClass, new Object JavaDoc[] { packageName });
66         } catch (Throwable JavaDoc e) {
67             e.printStackTrace();
68             StackTraceElement JavaDoc[] ste = e.getStackTrace();
69             for (int i =0; i<ste.length; i++) logger.severe(ste[i].toString());
70             logger.severe("StringManager could not be configured");
71         }
72     }
73
74     public String JavaDoc getString(String JavaDoc key) {
75         try {
76             return (String JavaDoc) getStr.invoke(asStringManager, new Object JavaDoc[] { key });
77         } catch(Exception JavaDoc ex) {
78             logger.severe("Method invocation failed on com.sun.enterprise.util.i18n.StringManager");
79             return null;
80         }
81     }
82     
83     public String JavaDoc getString(String JavaDoc key, Object JavaDoc arg) {
84         try {
85             return (String JavaDoc) getStrDef.invoke(asStringManager, new Object JavaDoc[] { key, arg });
86         } catch(Exception JavaDoc ex) {
87             logger.severe("Method invocation failed on com.sun.enterprise.util.i18n.StringManager");
88             return null;
89         }
90     }
91     
92     public String JavaDoc getString(String JavaDoc key, Object JavaDoc[] args) {
93         try {
94             return (String JavaDoc) getStrGeneric.invoke(asStringManager, new Object JavaDoc[] { key, args });
95         } catch(Exception JavaDoc ex) {
96             logger.severe("Method invocation failed on com.sun.enterprise.util.i18n.StringManager");
97             return null;
98         }
99     }
100 }
101
Popular Tags