KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > corba > ee > internal > util > LogWrap


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.corba.ee.internal.util;
25
26 import java.util.logging.Logger JavaDoc;
27
28 import java.lang.reflect.Method JavaDoc;
29 import java.lang.reflect.Field JavaDoc;
30
31 //QQ. remove unnecessary import
32
//import com.sun.corba.ee.internal.orbutil.ORBConstants;
33

34 import java.util.MissingResourceException JavaDoc;
35
36 public class LogWrap {
37     
38     public static Logger JavaDoc logger;
39     
40     private static final String JavaDoc LOGDOMAINS_CLASS_NAME =
41             "com.sun.logging.LogDomains";
42     private static final String JavaDoc GET_LOGGER_METHOD_NAME = "getLogger";
43
44     private static final String JavaDoc ORB_LOGGER_FIELD_NAME = "CORBA_LOGGER";
45     private static final String JavaDoc ORB_LOGGER_NAME =
46             "javax.enterprise.resource.corba";
47     private static final String JavaDoc ORB_LOGGER_RESOURCE_BUNDLE =
48             "com.sun.logging.enterprise.resource.corba.LogStrings";
49     
50     static {
51         try {
52             logger = getLoggerUsingLogDomainsAPI();
53             if (logger == null) {
54                 System.out.println("Could not initialize LogDomains logger");
55             }
56         } catch (Exception JavaDoc ex) {
57             System.out.println("Could not initialize LogDomains logger");
58         }
59
60         if (logger == null) {
61             try {
62                 logger = getLoggerUsingJavaLoggingAPI();
63                 if (logger == null) {
64                     System.out.println("Could not initialize JDK logger");
65                 }
66             } catch (Exception JavaDoc ex) {
67                 System.out.println("Could not initialize JDK logger");
68                 ex.printStackTrace();
69             }
70         }
71     }
72     
73     private static Logger JavaDoc getLoggerUsingLogDomainsAPI() throws Exception JavaDoc {
74         Class JavaDoc logDomainsClass = Class.forName(LOGDOMAINS_CLASS_NAME);
75
76         Class JavaDoc [] parameterClasses = new Class JavaDoc[1];
77         parameterClasses[0] = String JavaDoc.class;
78         Method JavaDoc getLoggerMethod = logDomainsClass.getDeclaredMethod(
79                 GET_LOGGER_METHOD_NAME, parameterClasses);
80
81         Field JavaDoc orbLoggerNameField = logDomainsClass.getDeclaredField(
82                 ORB_LOGGER_FIELD_NAME);
83         String JavaDoc orbLoggerName = (String JavaDoc)orbLoggerNameField.get(null);
84
85         Object JavaDoc [] parameters = new Object JavaDoc[1];
86         parameters[0] = orbLoggerName;
87         Logger JavaDoc lgr = (Logger JavaDoc)getLoggerMethod.invoke(null, parameters);
88
89         return lgr;
90     }
91     
92     private static Logger JavaDoc getLoggerUsingJavaLoggingAPI() throws Exception JavaDoc {
93         Logger JavaDoc lgr = Logger.getLogger(ORB_LOGGER_NAME, ORB_LOGGER_RESOURCE_BUNDLE);
94         
95         return lgr;
96     }
97     
98 }
99
Popular Tags