/**
* Copyright 2004 Sun Microsystems, Inc. All
* rights reserved. Use of this product is subject
* to license terms. Federal Acquisitions:
* Commercial Software -- Government Users
* Subject to Standard License Terms and
* Conditions.
*
* Sun, Sun Microsystems, the Sun logo, and Sun ONE
* are trademarks or registered trademarks of Sun Microsystems,
* Inc. in the United States and other countries.
*/
package com.sun.ssoadapter;
import java.util.logging.Logger;
import java.lang.reflect.Method;
/**
* It uses Portal Logger if available else Java Logger
*/
public class SSOAdapterLogger {
public static String LOGGER_CLASS = "com.sun.portal.log.common.PortalLogger";
public static String METHOD_NAME = "getLogger";
/**
* Returns the Logger for the specified name.
* This checks whether PortalLogger is in the same JVM.
* If its present, invokes getLogger method of the PortalLogger to get the Logger.
* If its not present, invokes the getLogger method of the JDK Logger to get the Logger
* by passing SSOAdapterLogMessages resource bundle.
* SSOAdapterLogMessages.properties is the concatenation of all logmsg.properties
* in the ssoadapter module.
*
* @param name the name of the logger
* @return the Logger
*/
public static Logger getLogger(String name){
try {
Class cls = SSOAdapterLogger.class.getClassLoader().loadClass(LOGGER_CLASS);
Method[] methodlist
= cls.getDeclaredMethods();
for (int i = 0; i < methodlist.length; i++) {
Method method = methodlist[i];
if (method.getName().equals(METHOD_NAME)){
if(method.getParameterTypes().length==1 &&
((Class[])method.getParameterTypes())[0].getName().equals("java.lang.String")) {
return (Logger) (method.invoke(cls.newInstance(),new Object[]{name}));
}
}
}
} catch (Exception e) {
System.err.println(e);
}
// The SSOAdapterLogMessages.properties is the ResourceBundle built by the ant target "mergelogmsg"
// and it is the concatenation of all logmsg.properties in the ssoadapter module
return Logger.getLogger(name, "SSOAdapterLogMessages");
}
/**
* Returns the Logger for the class object.
* Derives the package name from the class object and uses it
* to create the Logger.
*
* @param cls a class object
* @return the Logger
*/
public static Logger getLogger(Class cls) {
Package pkg = cls.getPackage();
String packageName = (pkg == null) ? "debug" : pkg.getName();
return getLogger(packageName);
}
}
|