01: /**
02: * Copyright 2004 Sun Microsystems, Inc. All
03: * rights reserved. Use of this product is subject
04: * to license terms. Federal Acquisitions:
05: * Commercial Software -- Government Users
06: * Subject to Standard License Terms and
07: * Conditions.
08: *
09: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
10: * are trademarks or registered trademarks of Sun Microsystems,
11: * Inc. in the United States and other countries.
12: */package com.sun.addressbook;
13:
14: import java.util.logging.Logger;
15: import java.lang.reflect.Method;
16:
17: public class ABLogger {
18:
19: public static String LOGGER_CLASS = "com.sun.portal.log.common.PortalLogger";
20: public static String METHOD_NAME = "getLogger";
21:
22: /**
23: * Returns the Logger for the specified name.
24: * This checks whether PortalLogger is in the same JVM.
25: * If its present, invokes getLogger method of the PortalLogger to get the Logger.
26: * If its not present, invokes the getLogger method of the JDK Logger to get the Logger
27: * by passing jabapiLogMessages resource bundle.
28: * jabapiLogMessages.properties is the concatenation of all logmsg.properties
29: * in the jabapi module.
30: *
31: * @param name the name of the logger
32: * @return the Logger
33: */
34: public static Logger getLogger(String name) {
35: try {
36: Class cls = ABLogger.class.getClassLoader().loadClass(
37: LOGGER_CLASS);
38: Method[] methodlist = cls.getDeclaredMethods();
39: for (int i = 0; i < methodlist.length; i++) {
40: Method method = methodlist[i];
41: if (method.getName().equals(METHOD_NAME)) {
42: if (method.getParameterTypes().length == 1
43: && ((Class[]) method.getParameterTypes())[0]
44: .getName().equals(
45: "java.lang.String")) {
46: return (Logger) (method.invoke(cls
47: .newInstance(), new Object[] { name }));
48: }
49: }
50: }
51: } catch (Exception e) {
52: System.err.println(e);
53: }
54: // The jabapiLogMessages.properties is the ResourceBundle built by the ant target "mergelogmsg"
55: // and it is the concatenation of all logmsg.properties in the jabapi module
56: return Logger.getLogger(name, "jabapiLogMessages");
57: }
58: }
|