org.apache.commons.logging_1.1.1.v201101211721

16:41:03.628 INFO  jd.cli.Main - Decompiling org.apache.commons.logging_1.1.1.v201101211721.jar
package org.apache.commons.logging;

public abstract interface Log
{
  public abstract boolean isDebugEnabled();
  
  public abstract boolean isErrorEnabled();
  
  public abstract boolean isFatalEnabled();
  
  public abstract boolean isInfoEnabled();
  
  public abstract boolean isTraceEnabled();
  
  public abstract boolean isWarnEnabled();
  
  public abstract void trace(Object paramObject);
  
  public abstract void trace(Object paramObject, Throwable paramThrowable);
  
  public abstract void debug(Object paramObject);
  
  public abstract void debug(Object paramObject, Throwable paramThrowable);
  
  public abstract void info(Object paramObject);
  
  public abstract void info(Object paramObject, Throwable paramThrowable);
  
  public abstract void warn(Object paramObject);
  
  public abstract void warn(Object paramObject, Throwable paramThrowable);
  
  public abstract void error(Object paramObject);
  
  public abstract void error(Object paramObject, Throwable paramThrowable);
  
  public abstract void fatal(Object paramObject);
  
  public abstract void fatal(Object paramObject, Throwable paramThrowable);
}

/* Location:
 * Qualified Name:     org.apache.commons.logging.Log
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.logging;

public class LogConfigurationException
  extends RuntimeException
{
  public LogConfigurationException() {}
  
  public LogConfigurationException(String message)
  {
    super(message);
  }
  
  public LogConfigurationException(Throwable cause)
  {
    this(cause == null ? null : cause.toString(), cause);
  }
  
  public LogConfigurationException(String message, Throwable cause)
  {
    super(message + " (Caused by " + cause + ")");
    this.cause = cause;
  }
  
  protected Throwable cause = null;
  
  public Throwable getCause()
  {
    return cause;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.logging.LogConfigurationException
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.logging;

import java.security.PrivilegedAction;

class LogFactory$1
  implements PrivilegedAction
{
  public Object run()
  {
    return LogFactory.directGetContextClassLoader();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.logging.LogFactory.1
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.logging;

import java.security.PrivilegedAction;

class LogFactory$2
  implements PrivilegedAction
{
  private final String val$factoryClass;
  private final ClassLoader val$classLoader;
  
  LogFactory$2(String val$factoryClass, ClassLoader val$classLoader)
  {
    this.val$factoryClass = val$factoryClass;this.val$classLoader = val$classLoader;
  }
  
  public Object run()
  {
    return LogFactory.createFactory(val$factoryClass, val$classLoader);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.logging.LogFactory.2
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.logging;

import java.security.PrivilegedAction;

class LogFactory$3
  implements PrivilegedAction
{
  private final ClassLoader val$loader;
  private final String val$name;
  
  LogFactory$3(ClassLoader val$loader, String val$name)
  {
    this.val$loader = val$loader;this.val$name = val$name;
  }
  
  public Object run()
  {
    if (val$loader != null) {
      return val$loader.getResourceAsStream(val$name);
    }
    return ClassLoader.getSystemResourceAsStream(val$name);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.logging.LogFactory.3
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.logging;

import java.io.IOException;
import java.security.PrivilegedAction;

class LogFactory$4
  implements PrivilegedAction
{
  private final ClassLoader val$loader;
  private final String val$name;
  
  LogFactory$4(ClassLoader val$loader, String val$name)
  {
    this.val$loader = val$loader;this.val$name = val$name;
  }
  
  public Object run()
  {
    try
    {
      if (val$loader != null) {
        return val$loader.getResources(val$name);
      }
      return ClassLoader.getSystemResources(val$name);
    }
    catch (IOException e)
    {
      if (LogFactory.isDiagnosticsEnabled()) {
        LogFactory.access$000("Exception while trying to find configuration file " + val$name + ":" + e.getMessage());
      }
      return null;
    }
    catch (NoSuchMethodError e) {}
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.logging.LogFactory.4
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.logging;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.security.PrivilegedAction;
import java.util.Properties;

class LogFactory$5
  implements PrivilegedAction
{
  private final URL val$url;
  
  LogFactory$5(URL val$url)
  {
    this.val$url = val$url;
  }
  
  public Object run()
  {
    try
    {
      InputStream stream = val$url.openStream();
      if (stream != null)
      {
        Properties props = new Properties();
        props.load(stream);
        stream.close();
        return props;
      }
    }
    catch (IOException e)
    {
      if (LogFactory.isDiagnosticsEnabled()) {
        LogFactory.access$000("Unable to read URL " + val$url);
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.logging.LogFactory.5
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.logging;

import java.security.PrivilegedAction;

class LogFactory$6
  implements PrivilegedAction
{
  private final String val$key;
  private final String val$def;
  
  LogFactory$6(String val$key, String val$def)
  {
    this.val$key = val$key;this.val$def = val$def;
  }
  
  public Object run()
  {
    return System.getProperty(val$key, val$def);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.logging.LogFactory.6
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.logging;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;

public abstract class LogFactory
{
  public static final String PRIORITY_KEY = "priority";
  public static final String TCCL_KEY = "use_tccl";
  public static final String FACTORY_PROPERTY = "org.apache.commons.logging.LogFactory";
  public static final String FACTORY_DEFAULT = "org.apache.commons.logging.impl.LogFactoryImpl";
  public static final String FACTORY_PROPERTIES = "commons-logging.properties";
  protected static final String SERVICE_ID = "META-INF/services/org.apache.commons.logging.LogFactory";
  public static final String DIAGNOSTICS_DEST_PROPERTY = "org.apache.commons.logging.diagnostics.dest";
  private static PrintStream diagnosticsStream = null;
  private static String diagnosticPrefix;
  public static final String HASHTABLE_IMPLEMENTATION_PROPERTY = "org.apache.commons.logging.LogFactory.HashtableImpl";
  private static final String WEAK_HASHTABLE_CLASSNAME = "org.apache.commons.logging.impl.WeakHashtable";
  private static ClassLoader thisClassLoader;
  protected static Hashtable factories = null;
  protected static LogFactory nullClassLoaderFactory = null;
  
  public abstract Object getAttribute(String paramString);
  
  public abstract String[] getAttributeNames();
  
  public abstract Log getInstance(Class paramClass)
    throws LogConfigurationException;
  
  public abstract Log getInstance(String paramString)
    throws LogConfigurationException;
  
  public abstract void release();
  
  public abstract void removeAttribute(String paramString);
  
  public abstract void setAttribute(String paramString, Object paramObject);
  
  private static final Hashtable createFactoryStore()
  {
    Hashtable result = null;
    String storeImplementationClass;
    try
    {
      storeImplementationClass = getSystemProperty("org.apache.commons.logging.LogFactory.HashtableImpl", null);
    }
    catch (SecurityException ex)
    {
      String storeImplementationClass;
      storeImplementationClass = null;
    }
    if (storeImplementationClass == null) {
      storeImplementationClass = "org.apache.commons.logging.impl.WeakHashtable";
    }
    try
    {
      Class implementationClass = Class.forName(storeImplementationClass);
      result = (Hashtable)implementationClass.newInstance();
    }
    catch (Throwable t)
    {
      if (!"org.apache.commons.logging.impl.WeakHashtable".equals(storeImplementationClass)) {
        if (isDiagnosticsEnabled()) {
          logDiagnostic("[ERROR] LogFactory: Load of custom hashtable failed");
        } else {
          System.err.println("[ERROR] LogFactory: Load of custom hashtable failed");
        }
      }
    }
    if (result == null) {
      result = new Hashtable();
    }
    return result;
  }
  
  private static String trim(String src)
  {
    if (src == null) {
      return null;
    }
    return src.trim();
  }
  
  public static LogFactory getFactory()
    throws LogConfigurationException
  {
    ClassLoader contextClassLoader = getContextClassLoaderInternal();
    if (contextClassLoader == null) {
      if (isDiagnosticsEnabled()) {
        logDiagnostic("Context classloader is null.");
      }
    }
    LogFactory factory = getCachedFactory(contextClassLoader);
    if (factory != null) {
      return factory;
    }
    if (isDiagnosticsEnabled())
    {
      logDiagnostic("[LOOKUP] LogFactory implementation requested for the first time for context classloader " + objectId(contextClassLoader));
      
      logHierarchy("[LOOKUP] ", contextClassLoader);
    }
    Properties props = getConfigurationFile(contextClassLoader, "commons-logging.properties");
    
    ClassLoader baseClassLoader = contextClassLoader;
    if (props != null)
    {
      String useTCCLStr = props.getProperty("use_tccl");
      if (useTCCLStr != null) {
        if (!Boolean.valueOf(useTCCLStr).booleanValue()) {
          baseClassLoader = thisClassLoader;
        }
      }
    }
    if (isDiagnosticsEnabled()) {
      logDiagnostic("[LOOKUP] Looking for system property [org.apache.commons.logging.LogFactory] to define the LogFactory subclass to use...");
    }
    try
    {
      String factoryClass = getSystemProperty("org.apache.commons.logging.LogFactory", null);
      if (factoryClass != null)
      {
        if (isDiagnosticsEnabled()) {
          logDiagnostic("[LOOKUP] Creating an instance of LogFactory class '" + factoryClass + "' as specified by system property " + "org.apache.commons.logging.LogFactory");
        }
        factory = newFactory(factoryClass, baseClassLoader, contextClassLoader);
      }
      else if (isDiagnosticsEnabled())
      {
        logDiagnostic("[LOOKUP] No system property [org.apache.commons.logging.LogFactory] defined.");
      }
    }
    catch (SecurityException e)
    {
      if (isDiagnosticsEnabled()) {
        logDiagnostic("[LOOKUP] A security exception occurred while trying to create an instance of the custom factory class: [" + trim(e.getMessage()) + "]. Trying alternative implementations...");
      }
    }
    catch (RuntimeException e)
    {
      if (isDiagnosticsEnabled()) {
        logDiagnostic("[LOOKUP] An exception occurred while trying to create an instance of the custom factory class: [" + trim(e.getMessage()) + "] as specified by a system property.");
      }
      throw e;
    }
    if (factory == null)
    {
      if (isDiagnosticsEnabled()) {
        logDiagnostic("[LOOKUP] Looking for a resource file of name [META-INF/services/org.apache.commons.logging.LogFactory] to define the LogFactory subclass to use...");
      }
      try
      {
        InputStream is = getResourceAsStream(contextClassLoader, "META-INF/services/org.apache.commons.logging.LogFactory");
        if (is != null)
        {
          BufferedReader rd;
          try
          {
            rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
          }
          catch (UnsupportedEncodingException e)
          {
            BufferedReader rd;
            rd = new BufferedReader(new InputStreamReader(is));
          }
          String factoryClassName = rd.readLine();
          rd.close();
          if ((factoryClassName != null) && (!"".equals(factoryClassName)))
          {
            if (isDiagnosticsEnabled()) {
              logDiagnostic("[LOOKUP]  Creating an instance of LogFactory class " + factoryClassName + " as specified by file '" + "META-INF/services/org.apache.commons.logging.LogFactory" + "' which was present in the path of the context" + " classloader.");
            }
            factory = newFactory(factoryClassName, baseClassLoader, contextClassLoader);
          }
        }
        else if (isDiagnosticsEnabled())
        {
          logDiagnostic("[LOOKUP] No resource file with name 'META-INF/services/org.apache.commons.logging.LogFactory' found.");
        }
      }
      catch (Exception ex)
      {
        if (isDiagnosticsEnabled()) {
          logDiagnostic("[LOOKUP] A security exception occurred while trying to create an instance of the custom factory class: [" + trim(ex.getMessage()) + "]. Trying alternative implementations...");
        }
      }
    }
    if (factory == null) {
      if (props != null)
      {
        if (isDiagnosticsEnabled()) {
          logDiagnostic("[LOOKUP] Looking in properties file for entry with key 'org.apache.commons.logging.LogFactory' to define the LogFactory subclass to use...");
        }
        String factoryClass = props.getProperty("org.apache.commons.logging.LogFactory");
        if (factoryClass != null)
        {
          if (isDiagnosticsEnabled()) {
            logDiagnostic("[LOOKUP] Properties file specifies LogFactory subclass '" + factoryClass + "'");
          }
          factory = newFactory(factoryClass, baseClassLoader, contextClassLoader);
        }
        else if (isDiagnosticsEnabled())
        {
          logDiagnostic("[LOOKUP] Properties file has no entry specifying LogFactory subclass.");
        }
      }
      else if (isDiagnosticsEnabled())
      {
        logDiagnostic("[LOOKUP] No properties file available to determine LogFactory subclass from..");
      }
    }
    if (factory == null)
    {
      if (isDiagnosticsEnabled()) {
        logDiagnostic("[LOOKUP] Loading the default LogFactory implementation 'org.apache.commons.logging.impl.LogFactoryImpl' via the same classloader that loaded this LogFactory class (ie not looking in the context classloader).");
      }
      factory = newFactory("org.apache.commons.logging.impl.LogFactoryImpl", thisClassLoader, contextClassLoader);
    }
    if (factory != null)
    {
      cacheFactory(contextClassLoader, factory);
      if (props != null)
      {
        Enumeration names = props.propertyNames();
        while (names.hasMoreElements())
        {
          String name = (String)names.nextElement();
          String value = props.getProperty(name);
          factory.setAttribute(name, value);
        }
      }
    }
    return factory;
  }
  
  public static Log getLog(Class clazz)
    throws LogConfigurationException
  {
    return getFactory().getInstance(clazz);
  }
  
  public static Log getLog(String name)
    throws LogConfigurationException
  {
    return getFactory().getInstance(name);
  }
  
  public static void release(ClassLoader classLoader)
  {
    if (isDiagnosticsEnabled()) {
      logDiagnostic("Releasing factory for classloader " + objectId(classLoader));
    }
    synchronized (factories)
    {
      if (classLoader == null)
      {
        if (nullClassLoaderFactory != null)
        {
          nullClassLoaderFactory.release();
          nullClassLoaderFactory = null;
        }
      }
      else
      {
        LogFactory factory = (LogFactory)factories.get(classLoader);
        if (factory != null)
        {
          factory.release();
          factories.remove(classLoader);
        }
      }
    }
  }
  
  public static void releaseAll()
  {
    if (isDiagnosticsEnabled()) {
      logDiagnostic("Releasing factory for all classloaders.");
    }
    synchronized (factories)
    {
      Enumeration elements = factories.elements();
      while (elements.hasMoreElements())
      {
        LogFactory element = (LogFactory)elements.nextElement();
        element.release();
      }
      factories.clear();
      if (nullClassLoaderFactory != null)
      {
        nullClassLoaderFactory.release();
        nullClassLoaderFactory = null;
      }
    }
  }
  
  protected static ClassLoader getClassLoader(Class clazz)
  {
    try
    {
      return clazz.getClassLoader();
    }
    catch (SecurityException ex)
    {
      if (isDiagnosticsEnabled()) {
        logDiagnostic("Unable to get classloader for class '" + clazz + "' due to security restrictions - " + ex.getMessage());
      }
      throw ex;
    }
  }
  
  protected static ClassLoader getContextClassLoader()
    throws LogConfigurationException
  {
    return directGetContextClassLoader();
  }
  
  private static ClassLoader getContextClassLoaderInternal()
    throws LogConfigurationException
  {
    (ClassLoader)AccessController.doPrivileged(new PrivilegedAction()
    {
      public Object run()
      {
        return LogFactory.directGetContextClassLoader();
      }
    });
  }
  
  protected static ClassLoader directGetContextClassLoader()
    throws LogConfigurationException
  {
    ClassLoader classLoader = null;
    try
    {
      Method method = Thread.class.getMethod("getContextClassLoader", (Class[])null);
      try
      {
        classLoader = (ClassLoader)method.invoke(Thread.currentThread(), (Object[])null);
      }
      catch (IllegalAccessException e)
      {
        throw new LogConfigurationException("Unexpected IllegalAccessException", e);
      }
      catch (InvocationTargetException e)
      {
        if (!(e.getTargetException() instanceof SecurityException)) {
          throw new LogConfigurationException("Unexpected InvocationTargetException", e.getTargetException());
        }
      }
    }
    catch (NoSuchMethodException e)
    {
      classLoader = getClassLoader(LogFactory.class);
    }
    return classLoader;
  }
  
  private static LogFactory getCachedFactory(ClassLoader contextClassLoader)
  {
    LogFactory factory = null;
    if (contextClassLoader == null) {
      factory = nullClassLoaderFactory;
    } else {
      factory = (LogFactory)factories.get(contextClassLoader);
    }
    return factory;
  }
  
  private static void cacheFactory(ClassLoader classLoader, LogFactory factory)
  {
    if (factory != null) {
      if (classLoader == null) {
        nullClassLoaderFactory = factory;
      } else {
        factories.put(classLoader, factory);
      }
    }
  }
  
  protected static LogFactory newFactory(String factoryClass, ClassLoader classLoader, ClassLoader contextClassLoader)
    throws LogConfigurationException
  {
    Object result = AccessController.doPrivileged(new PrivilegedAction()
    {
      private final String val$factoryClass;
      private final ClassLoader val$classLoader;
      
      public Object run()
      {
        return LogFactory.createFactory(val$factoryClass, val$classLoader);
      }
    });
    if ((result instanceof LogConfigurationException))
    {
      LogConfigurationException ex = (LogConfigurationException)result;
      if (isDiagnosticsEnabled()) {
        logDiagnostic("An error occurred while loading the factory class:" + ex.getMessage());
      }
      throw ex;
    }
    if (isDiagnosticsEnabled()) {
      logDiagnostic("Created object " + objectId(result) + " to manage classloader " + objectId(contextClassLoader));
    }
    return (LogFactory)result;
  }
  
  protected static LogFactory newFactory(String factoryClass, ClassLoader classLoader)
  {
    return newFactory(factoryClass, classLoader, null);
  }
  
  protected static Object createFactory(String factoryClass, ClassLoader classLoader)
  {
    Class logFactoryClass = null;
    try
    {
      if (classLoader != null) {
        try
        {
          logFactoryClass = classLoader.loadClass(factoryClass);
          if (LogFactory.class.isAssignableFrom(logFactoryClass))
          {
            if (isDiagnosticsEnabled()) {
              logDiagnostic("Loaded class " + logFactoryClass.getName() + " from classloader " + objectId(classLoader));
            }
          }
          else if (isDiagnosticsEnabled())
          {
            logDiagnostic("Factory class " + logFactoryClass.getName() + " loaded from classloader " + objectId(logFactoryClass.getClassLoader()) + " does not extend '" + LogFactory.class.getName() + "' as loaded by this classloader.");
            
            logHierarchy("[BAD CL TREE] ", classLoader);
          }
          return (LogFactory)logFactoryClass.newInstance();
        }
        catch (ClassNotFoundException ex)
        {
          if (classLoader == thisClassLoader)
          {
            if (isDiagnosticsEnabled()) {
              logDiagnostic("Unable to locate any class called '" + factoryClass + "' via classloader " + objectId(classLoader));
            }
            throw ex;
          }
        }
        catch (NoClassDefFoundError e)
        {
          if (classLoader == thisClassLoader)
          {
            if (isDiagnosticsEnabled()) {
              logDiagnostic("Class '" + factoryClass + "' cannot be loaded" + " via classloader " + objectId(classLoader) + " - it depends on some other class that cannot" + " be found.");
            }
            throw e;
          }
        }
        catch (ClassCastException e)
        {
          if (classLoader == thisClassLoader)
          {
            boolean implementsLogFactory = implementsLogFactory(logFactoryClass);
            
            String msg = "The application has specified that a custom LogFactory implementation should be used but Class '" + factoryClass + "' cannot be converted to '" + LogFactory.class.getName() + "'. ";
            if (implementsLogFactory) {
              msg = msg + "The conflict is caused by the presence of multiple LogFactory classes in incompatible classloaders. " + "Background can be found in http://commons.apache.org/logging/tech.html. " + "If you have not explicitly specified a custom LogFactory then it is likely that " + "the container has set one without your knowledge. " + "In this case, consider using the commons-logging-adapters.jar file or " + "specifying the standard LogFactory from the command line. ";
            } else {
              msg = msg + "Please check the custom implementation. ";
            }
            msg = msg + "Help can be found @http://commons.apache.org/logging/troubleshooting.html.";
            if (isDiagnosticsEnabled()) {
              logDiagnostic(msg);
            }
            ClassCastException ex = new ClassCastException(msg);
            throw ex;
          }
        }
      }
      if (isDiagnosticsEnabled()) {
        logDiagnostic("Unable to load factory class via classloader " + objectId(classLoader) + " - trying the classloader associated with this LogFactory.");
      }
      logFactoryClass = Class.forName(factoryClass);
      return (LogFactory)logFactoryClass.newInstance();
    }
    catch (Exception e)
    {
      if (isDiagnosticsEnabled()) {
        logDiagnostic("Unable to create LogFactory instance.");
      }
      if ((logFactoryClass != null) && (!LogFactory.class.isAssignableFrom(logFactoryClass))) {
        return new LogConfigurationException("The chosen LogFactory implementation does not extend LogFactory. Please check your configuration.", e);
      }
      return new LogConfigurationException(e);
    }
  }
  
  private static boolean implementsLogFactory(Class logFactoryClass)
  {
    boolean implementsLogFactory = false;
    if (logFactoryClass != null) {
      try
      {
        ClassLoader logFactoryClassLoader = logFactoryClass.getClassLoader();
        if (logFactoryClassLoader == null)
        {
          logDiagnostic("[CUSTOM LOG FACTORY] was loaded by the boot classloader");
        }
        else
        {
          logHierarchy("[CUSTOM LOG FACTORY] ", logFactoryClassLoader);
          Class factoryFromCustomLoader = Class.forName("org.apache.commons.logging.LogFactory", false, logFactoryClassLoader);
          
          implementsLogFactory = factoryFromCustomLoader.isAssignableFrom(logFactoryClass);
          if (implementsLogFactory) {
            logDiagnostic("[CUSTOM LOG FACTORY] " + logFactoryClass.getName() + " implements LogFactory but was loaded by an incompatible classloader.");
          } else {
            logDiagnostic("[CUSTOM LOG FACTORY] " + logFactoryClass.getName() + " does not implement LogFactory.");
          }
        }
      }
      catch (SecurityException e)
      {
        logDiagnostic("[CUSTOM LOG FACTORY] SecurityException thrown whilst trying to determine whether the compatibility was caused by a classloader conflict: " + e.getMessage());
      }
      catch (LinkageError e)
      {
        logDiagnostic("[CUSTOM LOG FACTORY] LinkageError thrown whilst trying to determine whether the compatibility was caused by a classloader conflict: " + e.getMessage());
      }
      catch (ClassNotFoundException e)
      {
        logDiagnostic("[CUSTOM LOG FACTORY] LogFactory class cannot be loaded by classloader which loaded the custom LogFactory implementation. Is the custom factory in the right classloader?");
      }
    }
    return implementsLogFactory;
  }
  
  private static InputStream getResourceAsStream(ClassLoader loader, String name)
  {
    (InputStream)AccessController.doPrivileged(new PrivilegedAction()
    {
      private final ClassLoader val$loader;
      private final String val$name;
      
      public Object run()
      {
        if (val$loader != null) {
          return val$loader.getResourceAsStream(val$name);
        }
        return ClassLoader.getSystemResourceAsStream(val$name);
      }
    });
  }
  
  private static Enumeration getResources(ClassLoader loader, String name)
  {
    PrivilegedAction action = new PrivilegedAction()
    {
      private final ClassLoader val$loader;
      private final String val$name;
      
      public Object run()
      {
        try
        {
          if (val$loader != null) {
            return val$loader.getResources(val$name);
          }
          return ClassLoader.getSystemResources(val$name);
        }
        catch (IOException e)
        {
          if (LogFactory.isDiagnosticsEnabled()) {
            LogFactory.logDiagnostic("Exception while trying to find configuration file " + val$name + ":" + e.getMessage());
          }
          return null;
        }
        catch (NoSuchMethodError e) {}
        return null;
      }
    };
    Object result = AccessController.doPrivileged(action);
    return (Enumeration)result;
  }
  
  private static Properties getProperties(URL url)
  {
    PrivilegedAction action = new PrivilegedAction()
    {
      private final URL val$url;
      
      public Object run()
      {
        try
        {
          InputStream stream = val$url.openStream();
          if (stream != null)
          {
            Properties props = new Properties();
            props.load(stream);
            stream.close();
            return props;
          }
        }
        catch (IOException e)
        {
          if (LogFactory.isDiagnosticsEnabled()) {
            LogFactory.logDiagnostic("Unable to read URL " + val$url);
          }
        }
        return null;
      }
    };
    return (Properties)AccessController.doPrivileged(action);
  }
  
  private static final Properties getConfigurationFile(ClassLoader classLoader, String fileName)
  {
    Properties props = null;
    double priority = 0.0D;
    URL propsUrl = null;
    try
    {
      Enumeration urls = getResources(classLoader, fileName);
      if (urls == null) {
        return null;
      }
      while (urls.hasMoreElements())
      {
        URL url = (URL)urls.nextElement();
        
        Properties newProps = getProperties(url);
        if (newProps != null) {
          if (props == null)
          {
            propsUrl = url;
            props = newProps;
            String priorityStr = props.getProperty("priority");
            priority = 0.0D;
            if (priorityStr != null) {
              priority = Double.parseDouble(priorityStr);
            }
            if (isDiagnosticsEnabled()) {
              logDiagnostic("[LOOKUP] Properties file found at '" + url + "'" + " with priority " + priority);
            }
          }
          else
          {
            String newPriorityStr = newProps.getProperty("priority");
            double newPriority = 0.0D;
            if (newPriorityStr != null) {
              newPriority = Double.parseDouble(newPriorityStr);
            }
            if (newPriority > priority)
            {
              if (isDiagnosticsEnabled()) {
                logDiagnostic("[LOOKUP] Properties file at '" + url + "'" + " with priority " + newPriority + " overrides file at '" + propsUrl + "'" + " with priority " + priority);
              }
              propsUrl = url;
              props = newProps;
              priority = newPriority;
            }
            else if (isDiagnosticsEnabled())
            {
              logDiagnostic("[LOOKUP] Properties file at '" + url + "'" + " with priority " + newPriority + " does not override file at '" + propsUrl + "'" + " with priority " + priority);
            }
          }
        }
      }
    }
    catch (SecurityException e)
    {
      if (isDiagnosticsEnabled()) {
        logDiagnostic("SecurityException thrown while trying to find/read config files.");
      }
    }
    if (isDiagnosticsEnabled()) {
      if (props == null) {
        logDiagnostic("[LOOKUP] No properties file of name '" + fileName + "' found.");
      } else {
        logDiagnostic("[LOOKUP] Properties file of name '" + fileName + "' found at '" + propsUrl + '"');
      }
    }
    return props;
  }
  
  private static String getSystemProperty(String key, String def)
    throws SecurityException
  {
    (String)AccessController.doPrivileged(new PrivilegedAction()
    {
      private final String val$key;
      private final String val$def;
      
      public Object run()
      {
        return System.getProperty(val$key, val$def);
      }
    });
  }
  
  private static void initDiagnostics()
  {
    try
    {
      String dest = getSystemProperty("org.apache.commons.logging.diagnostics.dest", null);
      if (dest == null) {
        return;
      }
    }
    catch (SecurityException ex)
    {
      return;
    }
    String dest;
    if (dest.equals("STDOUT")) {
      diagnosticsStream = System.out;
    } else if (dest.equals("STDERR")) {
      diagnosticsStream = System.err;
    } else {
      try
      {
        FileOutputStream fos = new FileOutputStream(dest, true);
        diagnosticsStream = new PrintStream(fos);
      }
      catch (IOException ex)
      {
        return;
      }
    }
    String classLoaderName;
    try
    {
      ClassLoader classLoader = thisClassLoader;
      String classLoaderName;
      if (thisClassLoader == null) {
        classLoaderName = "BOOTLOADER";
      } else {
        classLoaderName = objectId(classLoader);
      }
    }
    catch (SecurityException e)
    {
      String classLoaderName;
      classLoaderName = "UNKNOWN";
    }
    diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
  }
  
  protected static boolean isDiagnosticsEnabled()
  {
    return diagnosticsStream != null;
  }
  
  private static final void logDiagnostic(String msg)
  {
    if (diagnosticsStream != null)
    {
      diagnosticsStream.print(diagnosticPrefix);
      diagnosticsStream.println(msg);
      diagnosticsStream.flush();
    }
  }
  
  protected static final void logRawDiagnostic(String msg)
  {
    if (diagnosticsStream != null)
    {
      diagnosticsStream.println(msg);
      diagnosticsStream.flush();
    }
  }
  
  private static void logClassLoaderEnvironment(Class clazz)
  {
    if (!isDiagnosticsEnabled()) {
      return;
    }
    try
    {
      logDiagnostic("[ENV] Extension directories (java.ext.dir): " + System.getProperty("java.ext.dir"));
      logDiagnostic("[ENV] Application classpath (java.class.path): " + System.getProperty("java.class.path"));
    }
    catch (SecurityException ex)
    {
      logDiagnostic("[ENV] Security setting prevent interrogation of system classpaths.");
    }
    String className = clazz.getName();
    try
    {
      classLoader = getClassLoader(clazz);
    }
    catch (SecurityException ex)
    {
      ClassLoader classLoader;
      logDiagnostic("[ENV] Security forbids determining the classloader for " + className); return;
    }
    ClassLoader classLoader;
    logDiagnostic("[ENV] Class " + className + " was loaded via classloader " + objectId(classLoader));
    
    logHierarchy("[ENV] Ancestry of classloader which loaded " + className + " is ", classLoader);
  }
  
  private static void logHierarchy(String prefix, ClassLoader classLoader)
  {
    if (!isDiagnosticsEnabled()) {
      return;
    }
    if (classLoader != null)
    {
      String classLoaderString = classLoader.toString();
      logDiagnostic(prefix + objectId(classLoader) + " == '" + classLoaderString + "'");
    }
    try
    {
      systemClassLoader = ClassLoader.getSystemClassLoader();
    }
    catch (SecurityException ex)
    {
      ClassLoader systemClassLoader;
      logDiagnostic(prefix + "Security forbids determining the system classloader."); return;
    }
    ClassLoader systemClassLoader;
    if (classLoader != null)
    {
      StringBuffer buf = new StringBuffer(prefix + "ClassLoader tree:");
      do
      {
        buf.append(objectId(classLoader));
        if (classLoader == systemClassLoader) {
          buf.append(" (SYSTEM) ");
        }
        try
        {
          classLoader = classLoader.getParent();
        }
        catch (SecurityException ex)
        {
          buf.append(" --> SECRET");
          break;
        }
        buf.append(" --> ");
      } while (classLoader != null);
      buf.append("BOOT");
      
      logDiagnostic(buf.toString());
    }
  }
  
  public static String objectId(Object o)
  {
    if (o == null) {
      return "null";
    }
    return o.getClass().getName() + "@" + System.identityHashCode(o);
  }
  
  static
  {
    thisClassLoader = getClassLoader(LogFactory.class);
    initDiagnostics();
    logClassLoaderEnvironment(LogFactory.class);
    factories = createFactoryStore();
    if (isDiagnosticsEnabled()) {
      logDiagnostic("BOOTSTRAP COMPLETED");
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.logging.LogFactory
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.logging;

import java.lang.reflect.Constructor;
import java.util.Hashtable;
import java.util.Set;
import org.apache.commons.logging.impl.NoOpLog;

/**
 * @deprecated
 */
public class LogSource
{
  protected static Hashtable logs = new Hashtable();
  protected static boolean log4jIsAvailable = false;
  protected static boolean jdk14IsAvailable = false;
  protected static Constructor logImplctor = null;
  
  static
  {
    try
    {
      if (null != Class.forName("org.apache.log4j.Logger")) {
        log4jIsAvailable = true;
      } else {
        log4jIsAvailable = false;
      }
    }
    catch (Throwable t)
    {
      log4jIsAvailable = false;
    }
    try
    {
      if ((null != Class.forName("java.util.logging.Logger")) && (null != Class.forName("org.apache.commons.logging.impl.Jdk14Logger"))) {
        jdk14IsAvailable = true;
      } else {
        jdk14IsAvailable = false;
      }
    }
    catch (Throwable t)
    {
      jdk14IsAvailable = false;
    }
    String name = null;
    try
    {
      name = System.getProperty("org.apache.commons.logging.log");
      if (name == null) {
        name = System.getProperty("org.apache.commons.logging.Log");
      }
    }
    catch (Throwable t) {}
    if (name != null) {
      try
      {
        setLogImplementation(name);
      }
      catch (Throwable t)
      {
        try
        {
          setLogImplementation("org.apache.commons.logging.impl.NoOpLog");
        }
        catch (Throwable u) {}
      }
    } else {
      try
      {
        if (log4jIsAvailable) {
          setLogImplementation("org.apache.commons.logging.impl.Log4JLogger");
        } else if (jdk14IsAvailable) {
          setLogImplementation("org.apache.commons.logging.impl.Jdk14Logger");
        } else {
          setLogImplementation("org.apache.commons.logging.impl.NoOpLog");
        }
      }
      catch (Throwable t)
      {
        try
        {
          setLogImplementation("org.apache.commons.logging.impl.NoOpLog");
        }
        catch (Throwable u) {}
      }
    }
  }
  
  public static void setLogImplementation(String classname)
    throws LinkageError, ExceptionInInitializerError, NoSuchMethodException, SecurityException, ClassNotFoundException
  {
    try
    {
      Class logclass = Class.forName(classname);
      Class[] argtypes = new Class[1];
      argtypes[0] = "".getClass();
      logImplctor = logclass.getConstructor(argtypes);
    }
    catch (Throwable t)
    {
      logImplctor = null;
    }
  }
  
  public static void setLogImplementation(Class logclass)
    throws LinkageError, ExceptionInInitializerError, NoSuchMethodException, SecurityException
  {
    Class[] argtypes = new Class[1];
    argtypes[0] = "".getClass();
    logImplctor = logclass.getConstructor(argtypes);
  }
  
  public static Log getInstance(String name)
  {
    Log log = (Log)logs.get(name);
    if (null == log)
    {
      log = makeNewLogInstance(name);
      logs.put(name, log);
    }
    return log;
  }
  
  public static Log getInstance(Class clazz)
  {
    return getInstance(clazz.getName());
  }
  
  public static Log makeNewLogInstance(String name)
  {
    Log log = null;
    try
    {
      Object[] args = new Object[1];
      args[0] = name;
      log = (Log)logImplctor.newInstance(args);
    }
    catch (Throwable t)
    {
      log = null;
    }
    if (null == log) {
      log = new NoOpLog(name);
    }
    return log;
  }
  
  public static String[] getLogNames()
  {
    return (String[])logs.keySet().toArray(new String[logs.size()]);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.logging.LogSource
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.logging.impl;

import org.apache.avalon.framework.logger.Logger;
import org.apache.commons.logging.Log;

public class AvalonLogger
  implements Log
{
  private static Logger defaultLogger = null;
  private transient Logger logger = null;
  
  public AvalonLogger(Logger logger)
  {
    this.logger = logger;
  }
  
  public AvalonLogger(String name)
  {
    if (defaultLogger == null) {
      throw new NullPointerException("default logger has to be specified if this constructor is used!");
    }
    logger = defaultLogger.getChildLogger(name);
  }
  
  public Logger getLogger()
  {
    return logger;
  }
  
  public static void setDefaultLogger(Logger logger)
  {
    defaultLogger = logger;
  }
  
  public void debug(Object message, Throwable t)
  {
    if (getLogger().isDebugE
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd