com.crashlytics.tools.android_2.1.0

ssException e)
      {
        cat.error("FIXME", e);
      }
      catch (RuntimeException e)
      {
        cat.error("FIXME", e);
      }
    }
    else if (!name.endsWith(".layout"))
    {
      throw new AttributeNotFoundException("Attribute " + name + " not found in " + getClass().getName());
    }
  }
  
  public ObjectName preRegister(MBeanServer server, ObjectName name)
  {
    cat.debug("preRegister called. Server=" + server + ", name=" + name);
    this.server = server;
    registerLayoutMBean(appender.getLayout());
    
    return name;
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.jmx.AppenderDynamicMBean
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.jmx;

import java.lang.reflect.Constructor;
import java.util.Vector;
import javax.management.Attribute;
import javax.management.AttributeNotFoundException;
import javax.management.InvalidAttributeValueException;
import javax.management.JMException;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.MBeanServer;
import javax.management.Notification;
import javax.management.NotificationBroadcaster;
import javax.management.NotificationBroadcasterSupport;
import javax.management.NotificationFilter;
import javax.management.NotificationFilterSupport;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.RuntimeOperationsException;
import org.apache.log4j.Appender;
import org.apache.log4j.Category;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.spi.HierarchyEventListener;
import org.apache.log4j.spi.LoggerRepository;

public class HierarchyDynamicMBean
  extends AbstractDynamicMBean
  implements HierarchyEventListener, NotificationBroadcaster
{
  static final String ADD_APPENDER = "addAppender.";
  static final String THRESHOLD = "threshold";
  private MBeanConstructorInfo[] dConstructors = new MBeanConstructorInfo[1];
  private MBeanOperationInfo[] dOperations = new MBeanOperationInfo[1];
  private Vector vAttributes = new Vector();
  private String dClassName = getClass().getName();
  private String dDescription = "This MBean acts as a management facade for org.apache.log4j.Hierarchy.";
  private NotificationBroadcasterSupport nbs = new NotificationBroadcasterSupport();
  private LoggerRepository hierarchy;
  private static Logger log = Logger.getLogger(HierarchyDynamicMBean.class);
  
  public HierarchyDynamicMBean()
  {
    hierarchy = LogManager.getLoggerRepository();
    buildDynamicMBeanInfo();
  }
  
  private void buildDynamicMBeanInfo()
  {
    Constructor[] constructors = getClass().getConstructors();
    dConstructors[0] = new MBeanConstructorInfo("HierarchyDynamicMBean(): Constructs a HierarchyDynamicMBean instance", constructors[0]);
    
    vAttributes.add(new MBeanAttributeInfo("threshold", "java.lang.String", "The \"threshold\" state of the hiearchy.", true, true, false));
    
    MBeanParameterInfo[] params = new MBeanParameterInfo[1];
    params[0] = new MBeanParameterInfo("name", "java.lang.String", "Create a logger MBean");
    
    dOperations[0] = new MBeanOperationInfo("addLoggerMBean", "addLoggerMBean(): add a loggerMBean", params, "javax.management.ObjectName", 1);
  }
  
  public ObjectName addLoggerMBean(String name)
  {
    Logger cat = LogManager.exists(name);
    if (cat != null) {
      return addLoggerMBean(cat);
    }
    return null;
  }
  
  ObjectName addLoggerMBean(Logger logger)
  {
    String name = logger.getName();
    ObjectName objectName = null;
    try
    {
      LoggerDynamicMBean loggerMBean = new LoggerDynamicMBean(logger);
      objectName = new ObjectName("log4j", "logger", name);
      if (!server.isRegistered(objectName))
      {
        registerMBean(loggerMBean, objectName);
        NotificationFilterSupport nfs = new NotificationFilterSupport();
        nfs.enableType("addAppender." + logger.getName());
        log.debug("---Adding logger [" + name + "] as listener.");
        nbs.addNotificationListener(loggerMBean, nfs, null);
        vAttributes.add(new MBeanAttributeInfo("logger=" + name, "javax.management.ObjectName", "The " + name + " logger.", true, true, false));
      }
    }
    catch (JMException e)
    {
      log.error("Could not add loggerMBean for [" + name + "].", e);
    }
    catch (RuntimeException e)
    {
      log.error("Could not add loggerMBean for [" + name + "].", e);
    }
    return objectName;
  }
  
  public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
  {
    nbs.addNotificationListener(listener, filter, handback);
  }
  
  protected Logger getLogger()
  {
    return log;
  }
  
  public MBeanInfo getMBeanInfo()
  {
    MBeanAttributeInfo[] attribs = new MBeanAttributeInfo[vAttributes.size()];
    vAttributes.toArray(attribs);
    
    return new MBeanInfo(dClassName, dDescription, attribs, dConstructors, dOperations, new MBeanNotificationInfo[0]);
  }
  
  public MBeanNotificationInfo[] getNotificationInfo()
  {
    return nbs.getNotificationInfo();
  }
  
  public Object invoke(String operationName, Object[] params, String[] signature)
    throws MBeanException, ReflectionException
  {
    if (operationName == null) {
      throw new RuntimeOperationsException(new IllegalArgumentException("Operation name cannot be null"), "Cannot invoke a null operation in " + dClassName);
    }
    if (operationName.equals("addLoggerMBean")) {
      return addLoggerMBean((String)params[0]);
    }
    throw new ReflectionException(new NoSuchMethodException(operationName), "Cannot find the operation " + operationName + " in " + dClassName);
  }
  
  public Object getAttribute(String attributeName)
    throws AttributeNotFoundException, MBeanException, ReflectionException
  {
    if (attributeName == null) {
      throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot invoke a getter of " + dClassName + " with null attribute name");
    }
    log.debug("Called getAttribute with [" + attributeName + "].");
    if (attributeName.equals("threshold")) {
      return hierarchy.getThreshold();
    }
    if (attributeName.startsWith("logger"))
    {
      int k = attributeName.indexOf("%3D");
      String val = attributeName;
      if (k > 0) {
        val = attributeName.substring(0, k) + '=' + attributeName.substring(k + 3);
      }
      try
      {
        return new ObjectName("log4j:" + val);
      }
      catch (JMException e)
      {
        log.error("Could not create ObjectName" + val);
      }
      catch (RuntimeException e)
      {
        log.error("Could not create ObjectName" + val);
      }
    }
    throw new AttributeNotFoundException("Cannot find " + attributeName + " attribute in " + dClassName);
  }
  
  public void addAppenderEvent(Category logger, Appender appender)
  {
    log.debug("addAppenderEvent called: logger=" + logger.getName() + ", appender=" + appender.getName());
    
    Notification n = new Notification("addAppender." + logger.getName(), this, 0L);
    n.setUserData(appender);
    log.debug("sending notification.");
    nbs.sendNotification(n);
  }
  
  public void removeAppenderEvent(Category cat, Appender appender)
  {
    log.debug("removeAppenderCalled: logger=" + cat.getName() + ", appender=" + appender.getName());
  }
  
  public void postRegister(Boolean registrationDone)
  {
    log.debug("postRegister is called.");
    hierarchy.addHierarchyEventListener(this);
    Logger root = hierarchy.getRootLogger();
    addLoggerMBean(root);
  }
  
  public void removeNotificationListener(NotificationListener listener)
    throws ListenerNotFoundException
  {
    nbs.removeNotificationListener(listener);
  }
  
  public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
  {
    if (attribute == null) {
      throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Cannot invoke a setter of " + dClassName + " with null attribute");
    }
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null) {
      throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot invoke the setter of " + dClassName + " with null attribute name");
    }
    if (name.equals("threshold"))
    {
      Level l = OptionConverter.toLevel((String)value, hierarchy.getThreshold());
      
      hierarchy.setThreshold(l);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.jmx.HierarchyDynamicMBean
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.jmx;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.InterruptedIOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Hashtable;
import java.util.Vector;
import javax.management.Attribute;
import javax.management.AttributeNotFoundException;
import javax.management.InvalidAttributeValueException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.ReflectionException;
import javax.management.RuntimeOperationsException;
import org.apache.log4j.Layout;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.spi.OptionHandler;

public class LayoutDynamicMBean
  extends AbstractDynamicMBean
{
  private MBeanConstructorInfo[] dConstructors = new MBeanConstructorInfo[1];
  private Vector dAttributes = new Vector();
  private String dClassName = getClass().getName();
  private Hashtable dynamicProps = new Hashtable(5);
  private MBeanOperationInfo[] dOperations = new MBeanOperationInfo[1];
  private String dDescription = "This MBean acts as a management facade for log4j layouts.";
  private static Logger cat = Logger.getLogger(LayoutDynamicMBean.class);
  private Layout layout;
  
  public LayoutDynamicMBean(Layout layout)
    throws IntrospectionException
  {
    this.layout = layout;
    buildDynamicMBeanInfo();
  }
  
  private void buildDynamicMBeanInfo()
    throws IntrospectionException
  {
    Constructor[] constructors = getClass().getConstructors();
    dConstructors[0] = new MBeanConstructorInfo("LayoutDynamicMBean(): Constructs a LayoutDynamicMBean instance", constructors[0]);
    
    BeanInfo bi = Introspector.getBeanInfo(layout.getClass());
    PropertyDescriptor[] pd = bi.getPropertyDescriptors();
    
    int size = pd.length;
    for (int i = 0; i < size; i++)
    {
      String name = pd[i].getName();
      Method readMethod = pd[i].getReadMethod();
      Method writeMethod = pd[i].getWriteMethod();
      if (readMethod != null)
      {
        Class returnClass = readMethod.getReturnType();
        if (isSupportedType(returnClass))
        {
          String returnClassName;
          String returnClassName;
          if (returnClass.isAssignableFrom(Level.class)) {
            returnClassName = "java.lang.String";
          } else {
            returnClassName = returnClass.getName();
          }
          dAttributes.add(new MBeanAttributeInfo(name, returnClassName, "Dynamic", true, writeMethod != null, false));
          
          dynamicProps.put(name, new MethodUnion(readMethod, writeMethod));
        }
      }
    }
    MBeanParameterInfo[] params = new MBeanParameterInfo[0];
    
    dOperations[0] = new MBeanOperationInfo("activateOptions", "activateOptions(): add an layout", params, "void", 1);
  }
  
  private boolean isSupportedType(Class clazz)
  {
    if (clazz.isPrimitive()) {
      return true;
    }
    if (clazz == String.class) {
      return true;
    }
    if (clazz.isAssignableFrom(Level.class)) {
      return true;
    }
    return false;
  }
  
  public MBeanInfo getMBeanInfo()
  {
    cat.debug("getMBeanInfo called.");
    
    MBeanAttributeInfo[] attribs = new MBeanAttributeInfo[dAttributes.size()];
    dAttributes.toArray(attribs);
    
    return new MBeanInfo(dClassName, dDescription, attribs, dConstructors, dOperations, new MBeanNotificationInfo[0]);
  }
  
  public Object invoke(String operationName, Object[] params, String[] signature)
    throws MBeanException, ReflectionException
  {
    if ((operationName.equals("activateOptions")) && ((layout instanceof OptionHandler)))
    {
      OptionHandler oh = layout;
      oh.activateOptions();
      return "Options activated.";
    }
    return null;
  }
  
  protected Logger getLogger()
  {
    return cat;
  }
  
  public Object getAttribute(String attributeName)
    throws AttributeNotFoundException, MBeanException, ReflectionException
  {
    if (attributeName == null) {
      throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot invoke a getter of " + dClassName + " with null attribute name");
    }
    MethodUnion mu = (MethodUnion)dynamicProps.get(attributeName);
    
    cat.debug("----name=" + attributeName + ", mu=" + mu);
    if ((mu != null) && (readMethod != null)) {
      try
      {
        return readMethod.invoke(layout, null);
      }
      catch (InvocationTargetException e)
      {
        if (((e.getTargetException() instanceof InterruptedException)) || ((e.getTargetException() instanceof InterruptedIOException))) {
          Thread.currentThread().interrupt();
        }
        return null;
      }
      catch (IllegalAccessException e)
      {
        return null;
      }
      catch (RuntimeException e)
      {
        return null;
      }
    }
    throw new AttributeNotFoundException("Cannot find " + attributeName + " attribute in " + dClassName);
  }
  
  public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
  {
    if (attribute == null) {
      throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Cannot invoke a setter of " + dClassName + " with null attribute");
    }
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null) {
      throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot invoke the setter of " + dClassName + " with null attribute name");
    }
    MethodUnion mu = (MethodUnion)dynamicProps.get(name);
    if ((mu != null) && (writeMethod != null))
    {
      Object[] o = new Object[1];
      
      Class[] params = writeMethod.getParameterTypes();
      if (params[0] == Priority.class) {
        value = OptionConverter.toLevel((String)value, (Level)getAttribute(name));
      }
      o[0] = value;
      try
      {
        writeMethod.invoke(layout, o);
      }
      catch (InvocationTargetException e)
      {
        if (((e.getTargetException() instanceof InterruptedException)) || ((e.getTargetException() instanceof InterruptedIOException))) {
          Thread.currentThread().interrupt();
        }
        cat.error("FIXME", e);
      }
      catch (IllegalAccessException e)
      {
        cat.error("FIXME", e);
      }
      catch (RuntimeException e)
      {
        cat.error("FIXME", e);
      }
    }
    else
    {
      throw new AttributeNotFoundException("Attribute " + name + " not found in " + getClass().getName());
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.jmx.LayoutDynamicMBean
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.jmx;

import java.beans.IntrospectionException;
import java.lang.reflect.Constructor;
import java.util.Enumeration;
import java.util.Vector;
import javax.management.Attribute;
import javax.management.AttributeNotFoundException;
import javax.management.InvalidAttributeValueException;
import javax.management.JMException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.RuntimeOperationsException;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.helpers.OptionConverter;

public class LoggerDynamicMBean
  extends AbstractDynamicMBean
  implements NotificationListener
{
  private MBeanConstructorInfo[] dConstructors = new MBeanConstructorInfo[1];
  private MBeanOperationInfo[] dOperations = new MBeanOperationInfo[1];
  private Vector dAttributes = new Vector();
  private String dClassName = getClass().getName();
  private String dDescription = "This MBean acts as a management facade for a org.apache.log4j.Logger instance.";
  private static Logger cat = Logger.getLogger(LoggerDynamicMBean.class);
  private Logger logger;
  
  public LoggerDynamicMBean(Logger logger)
  {
    this.logger = logger;
    buildDynamicMBeanInfo();
  }
  
  public void handleNotification(Notification notification, Object handback)
  {
    cat.debug("Received notification: " + notification.getType());
    registerAppenderMBean((Appender)notification.getUserData());
  }
  
  private void buildDynamicMBeanInfo()
  {
    Constructor[] constructors = getClass().getConstructors();
    dConstructors[0] = new MBeanConstructorInfo("HierarchyDynamicMBean(): Constructs a HierarchyDynamicMBean instance", constructors[0]);
    
    dAttributes.add(new MBeanAttributeInfo("name", "java.lang.String", "The name of this Logger.", true, false, false));
    
    dAttributes.add(new MBeanAttributeInfo("priority", "java.lang.String", "The priority of this logger.", true, true, false));
    
    MBeanParameterInfo[] params = new MBeanParameterInfo[2];
    params[0] = new MBeanParameterInfo("class name", "java.lang.String", "add an appender to this logger");
    
    params[1] = new MBeanParameterInfo("appender name", "java.lang.String", "name of the appender");
    
    dOperations[0] = new MBeanOperationInfo("addAppender", "addAppender(): add an appender", params, "void", 1);
  }
  
  protected Logger getLogger()
  {
    return logger;
  }
  
  public MBeanInfo getMBeanInfo()
  {
    MBeanAttributeInfo[] attribs = new MBeanAttributeInfo[dAttributes.size()];
    dAttributes.toArray(attribs);
    
    MBeanInfo mb = new MBeanInfo(dClassName, dDescription, attribs, dConstructors, dOperations, new MBeanNotificationInfo[0]);
    
    return mb;
  }
  
  public Object invoke(String operationName, Object[] params, String[] signature)
    throws MBeanException, ReflectionException
  {
    if (operationName.equals("addAppender"))
    {
      addAppender((String)params[0], (String)params[1]);
      return "Hello world.";
    }
    return null;
  }
  
  public Object getAttribute(String attributeName)
    throws AttributeNotFoundException, MBeanException, ReflectionException
  {
    if (attributeName == null) {
      throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot invoke a getter of " + dClassName + " with null attribute name");
    }
    if (attributeName.equals("name")) {
      return logger.getName();
    }
    if (attributeName.equals("priority"))
    {
      Level l = logger.getLevel();
      if (l == null) {
        return null;
      }
      return l.toString();
    }
    if (attributeName.startsWith("appender=")) {
      try
      {
        return new ObjectName("log4j:" + attributeName);
      }
      catch (MalformedObjectNameException e)
      {
        cat.error("Could not create ObjectName" + attributeName);
      }
      catch (RuntimeException e)
      {
        cat.error("Could not create ObjectName" + attributeName);
      }
    }
    throw new AttributeNotFoundException("Cannot find " + attributeName + " attribute in " + dClassName);
  }
  
  void addAppender(String appenderClass, String appenderName)
  {
    cat.debug("addAppender called with " + appenderClass + ", " + appenderName);
    Appender appender = (Appender)OptionConverter.instantiateByClassName(appenderClass, Appender.class, null);
    
    appender.setName(appenderName);
    logger.addAppender(appender);
  }
  
  public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
  {
    if (attribute == null) {
      throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Cannot invoke a setter of " + dClassName + " with null attribute");
    }
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null) {
      throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot invoke the setter of " + dClassName + " with null attribute name");
    }
    if (name.equals("priority"))
    {
      if ((value instanceof String))
      {
        String s = (String)value;
        Level p = logger.getLevel();
        if (s.equalsIgnoreCase("NULL")) {
          p = null;
        } else {
          p = OptionConverter.toLevel(s, p);
        }
        logger.setLevel(p);
      }
    }
    else {
      throw new AttributeNotFoundException("Attribute " + name + " not found in " + getClass().getName());
    }
  }
  
  void appenderMBeanRegistration()
  {
    Enumeration enumeration = logger.getAllAppenders();
    while (enumeration.hasMoreElements())
    {
      Appender appender = (Appender)enumeration.nextElement();
      registerAppenderMBean(appender);
    }
  }
  
  void registerAppenderMBean(Appender appender)
  {
    String name = getAppenderName(appender);
    cat.debug("Adding AppenderMBean for appender named " + name);
    ObjectName objectName = null;
    try
    {
      AppenderDynamicMBean appenderMBean = new AppenderDynamicMBean(appender);
      objectName = new ObjectName("log4j", "appender", name);
      if (!server.isRegistered(objectName))
      {
        registerMBean(appenderMBean, objectName);
        dAttributes.add(new MBeanAttributeInfo("appender=" + name, "javax.management.ObjectName", "The " + name + " appender.", true, true, false));
      }
    }
    catch (JMException e)
    {
      cat.error("Could not add appenderMBean for [" + name + "].", e);
    }
    catch (IntrospectionException e)
    {
      cat.error("Could not add appenderMBean for [" + name + "].", e);
    }
    catch (RuntimeException e)
    {
      cat.error("Could not add appenderMBean for [" + name + "].", e);
    }
  }
  
  public void postRegister(Boolean registrationDone)
  {
    appenderMBeanRegistration();
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.jmx.LoggerDynamicMBean
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.jmx;

import java.lang.reflect.Method;

class MethodUnion
{
  Method readMethod;
  Method writeMethod;
  
  MethodUnion(Method readMethod, Method writeMethod)
  {
    this.readMethod = readMethod;
    this.writeMethod = writeMethod;
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.jmx.MethodUnion
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5;

import java.io.PrintStream;
import org.apache.log4j.lf5.viewer.LogBrokerMonitor;

public class AppenderFinalizer
{
  protected LogBrokerMonitor _defaultMonitor = null;
  
  public AppenderFinalizer(LogBrokerMonitor defaultMonitor)
  {
    _defaultMonitor = defaultMonitor;
  }
  
  protected void finalize()
    throws Throwable
  {
    System.out.println("Disposing of the default LogBrokerMonitor instance");
    _defaultMonitor.dispose();
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.AppenderFinalizer
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.spi.Configurator;
import org.apache.log4j.spi.LoggerRepository;

public class DefaultLF5Configurator
  implements Configurator
{
  public static void configure()
    throws IOException
  {
    String resource = "/org/apache/log4j/lf5/config/defaultconfig.properties";
    
    URL configFileResource = DefaultLF5Configurator.class.getResource(resource);
    if (configFileResource != null) {
      PropertyConfigurator.configure(configFileResource);
    } else {
      throw new IOException("Error: Unable to open the resource" + resource);
    }
  }
  
  public void doConfigure(InputStream inputStream, LoggerRepository repository)
  {
    throw new IllegalStateException("This class should NOT be instantiated!");
  }
  
  public void doConfigure(URL configURL, LoggerRepository repository)
  {
    throw new IllegalStateException("This class should NOT be instantiated!");
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.DefaultLF5Configurator
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5;

import java.awt.Dimension;
import java.awt.Toolkit;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Level;
import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;

public class LF5Appender
  extends AppenderSkeleton
{
  protected LogBrokerMonitor _logMonitor;
  protected static LogBrokerMonitor _defaultLogMonitor;
  protected static AppenderFinalizer _finalizer;
  
  public LF5Appender()
  {
    this(getDefaultInstance());
  }
  
  public LF5Appender(LogBrokerMonitor monitor)
  {
    if (monitor != null) {
      _logMonitor = monitor;
    }
  }
  
  public void append(LoggingEvent event)
  {
    String category = event.getLoggerName();
    String logMessage = event.getRenderedMessage();
    String nestedDiagnosticContext = event.getNDC();
    String threadDescription = event.getThreadName();
    String level = event.getLevel().toString();
    long time = timeStamp;
    LocationInfo locationInfo = event.getLocationInformation();
    
    Log4JLogRecord record = new Log4JLogRecord();
    
    record.setCategory(category);
    record.setMessage(logMessage);
    record.setLocation(fullInfo);
    record.setMillis(time);
    record.setThreadDescription(threadDescription);
    if (nestedDiagnosticContext != null) {
      record.setNDC(nestedDiagnosticContext);
    } else {
      record.setNDC("");
    }
    if (event.getThrowableInformation() != null) {
      record.setThrownStackTrace(event.getThrowableInformation());
    }
    try
    {
      record.setLevel(LogLevel.valueOf(level));
    }
    catch (LogLevelFormatException e)
    {
      record.setLevel(LogLevel.WARN);
    }
    if (_logMonitor != null) {
      _logMonitor.addMessage(record);
    }
  }
  
  public void close() {}
  
  public boolean requiresLayout()
  {
    return false;
  }
  
  public void setCallSystemExitOnClose(boolean callSystemExitOnClose)
  {
    _logMonitor.setCallSystemExitOnClose(callSystemExitOnClose);
  }
  
  public boolean equals(LF5Appender compareTo)
  {
    return _logMonitor == compareTo.getLogBrokerMonitor();
  }
  
  public LogBrokerMonitor getLogBrokerMonitor()
  {
    return _logMonitor;
  }
  
  public static void main(String[] args)
  {
    new LF5Appender();
  }
  
  public void setMaxNumberOfRecords(int maxNumberOfRecords)
  {
    _defaultLogMonitor.setMaxNumberOfLogRecords(maxNumberOfRecords);
  }
  
  protected static synchronized LogBrokerMonitor getDefaultInstance()
  {
    if (_defaultLogMonitor == null) {
      try
      {
        _defaultLogMonitor = new LogBrokerMonitor(LogLevel.getLog4JLevels());
        
        _finalizer = new AppenderFinalizer(_defaultLogMonitor);
        
        _defaultLogMonitor.setFrameSize(getDefaultMonitorWidth(), getDefaultMonitorHeight());
        
        _defaultLogMonitor.setFontSize(12);
        _defaultLogMonitor.show();
      }
      catch (SecurityException e)
      {
        _defaultLogMonitor = null;
      }
    }
    return _defaultLogMonitor;
  }
  
  protected static int getScreenWidth()
  {
    try
    {
      return getDefaultToolkitgetScreenSizewidth;
    }
    catch (Throwable t) {}
    return 800;
  }
  
  protected static int getScreenHeight()
  {
    try
    {
      return getDefaultToolkitgetScreenSizeheight;
    }
    catch (Throwable t) {}
    return 600;
  }
  
  protected static int getDefaultMonitorWidth()
  {
    return 3 * getScreenWidth() / 4;
  }
  
  protected static int getDefaultMonitorHeight()
  {
    return 3 * getScreenHeight() / 4;
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.LF5Appender
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5;

import org.apache.log4j.spi.ThrowableInformation;

public class Log4JLogRecord
  extends LogRecord
{
  public boolean isSevereLevel()
  {
    boolean isSevere = false;
    if ((LogLevel.ERROR.equals(getLevel())) || (LogLevel.FATAL.equals(getLevel()))) {
      isSevere = true;
    }
    return isSevere;
  }
  
  public void setThrownStackTrace(ThrowableInformation throwableInfo)
  {
    String[] stackTraceArray = throwableInfo.getThrowableStrRep();
    
    StringBuffer stackTrace = new StringBuffer();
    for (int i = 0; i < stackTraceArray.length; i++)
    {
      String nextLine = stackTraceArray[i] + "\n";
      stackTrace.append(nextLine);
    }
    _thrownStackTrace = stackTrace.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.Log4JLogRecord
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5;

import java.awt.Color;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class LogLevel
  implements Serializable
{
  public static final LogLevel FATAL = new LogLevel("FATAL", 0);
  public static final LogLevel ERROR = new LogLevel("ERROR", 1);
  public static final LogLevel WARN = new LogLevel("WARN", 2);
  public static final LogLevel INFO = new LogLevel("INFO", 3);
  public static final LogLevel DEBUG = new LogLevel("DEBUG", 4);
  public static final LogLevel SEVERE = new LogLevel("SEVERE", 1);
  public static final LogLevel WARNING = new LogLevel("WARNING", 2);
  public static final LogLevel CONFIG = new LogLevel("CONFIG", 4);
  public static final LogLevel FINE = new LogLevel("FINE", 5);
  public static final LogLevel FINER = new LogLevel("FINER", 6);
  public static final LogLevel FINEST = new LogLevel("FINEST", 7);
  protected String _label;
  protected int _precedence;
  private static LogLevel[] _log4JLevels;
  private static LogLevel[] _jdk14Levels;
  private static LogLevel[] _allDefaultLevels;
  private static Map _logLevelMap;
  private static Map _logLevelColorMap;
  private static Map _registeredLogLevelMap = new HashMap();
  
  static
  {
    _log4JLevels = new LogLevel[] { FATAL, ERROR, WARN, INFO, DEBUG };
    _jdk14Levels = new LogLevel[] { SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST };
    
    _allDefaultLevels = new LogLevel[] { FATAL, ERROR, WARN, INFO, DEBUG, SEVERE, WARNING, CONFIG, FINE, FINER, FINEST };
    
    _logLevelMap = new HashMap();
    for (int i = 0; i < _allDefaultLevels.length; i++) {
      _logLevelMap.put(_allDefaultLevels[i].getLabel(), _allDefaultLevels[i]);
    }
    _logLevelColorMap = new HashMap();
    for (int i = 0; i < _allDefaultLevels.length; i++) {
      _logLevelColorMap.put(_allDefaultLevels[i], Color.black);
    }
  }
  
  public LogLevel(String label, int precedence)
  {
    _label = label;
    _precedence = precedence;
  }
  
  public String getLabel()
  {
    return _label;
  }
  
  public boolean encompasses(LogLevel level)
  {
    if (level.getPrecedence() <= getPrecedence()) {
      return true;
    }
    return false;
  }
  
  public static LogLevel valueOf(String level)
    throws LogLevelFormatException
  {
    LogLevel logLevel = null;
    if (level != null)
    {
      level = level.trim().toUpperCase();
      logLevel = (LogLevel)_logLevelMap.get(level);
    }
    if ((logLevel == null) && (_registeredLogLevelMap.size() > 0)) {
      logLevel = (LogLevel)_registeredLogLevelMap.get(level);
    }
    if (logLevel == null)
    {
      StringBuffer buf = new StringBuffer();
      buf.append("Error while trying to parse (" + level + ") into");
      buf.append(" a LogLevel.");
      throw new LogLevelFormatException(buf.toString());
    }
    return logLevel;
  }
  
  public static LogLevel register(LogLevel logLevel)
  {
    if (logLevel == null) {
      return null;
    }
    if (_logLevelMap.get(logLevel.getLabel()) == null) {
      return (LogLevel)_registeredLogLevelMap.put(logLevel.getLabel(), logLevel);
    }
    return null;
  }
  
  public static void register(LogLevel[] logLevels)
  {
    if (logLevels != null) {
      for (int i = 0; i < logLevels.length; i++) {
        register(logLevels[i]);
      }
    }
  }
  
  public static void register(List logLevels)
  {
    if (logLevels != null)
    {
      Iterator it = logLevels.iterator();
      while (it.hasNext()) {
        register((LogLevel)it.next());
      }
    }
  }
  
  public boolean equals(Object o)
  {
    boolean equals = false;
    if (((o instanceof LogLevel)) && 
      (getPrecedence() == ((LogLevel)o).getPrecedence())) {
      equals = true;
    }
    return equals;
  }
  
  public int hashCode()
  {
    return _label.hashCode();
  }
  
  public String toString()
  {
    return _label;
  }
  
  public void setLogLevelColorMap(LogLevel level, Color color)
  {
    _logLevelColorMap.remove(level);
    if (color == null) {
      color = Color.black;
    }
    _logLevelColorMap.put(level, color);
  }
  
  public static void resetLogLevelColorMap()
  {
    _logLevelColorMap.clear();
    for (int i = 0; i < _allDefaultLevels.length; i++) {
      _logLevelColorMap.put(_allDefaultLevels[i], Color.black);
    }
  }
  
  public static List getLog4JLevels()
  {
    return Arrays.asList(_log4JLevels);
  }
  
  public static List getJdk14Levels()
  {
    return Arrays.asList(_jdk14Levels);
  }
  
  public static List getAllDefaultLevels()
  {
    return Arrays.asList(_allDefaultLevels);
  }
  
  public static Map getLogLevelColorMap()
  {
    return _logLevelColorMap;
  }
  
  protected int getPrecedence()
  {
    return _precedence;
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.LogLevel
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5;

public class LogLevelFormatException
  extends Exception
{
  public LogLevelFormatException(String message)
  {
    super(message);
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.LogLevelFormatException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;

public abstract class LogRecord
  implements Serializable
{
  protected static long _seqCount = 0L;
  protected LogLevel _level;
  protected String _message;
  protected long _sequenceNumber;
  protected long _millis;
  protected String _category;
  protected String _thread;
  protected String _thrownStackTrace;
  protected Throwable _thrown;
  protected String _ndc;
  protected String _location;
  
  public LogRecord()
  {
    _millis = System.currentTimeMillis();
    _category = "Debug";
    _message = "";
    _level = LogLevel.INFO;
    _sequenceNumber = getNextId();
    _thread = Thread.currentThread().toString();
    _ndc = "";
    _location = "";
  }
  
  public LogLevel getLevel()
  {
    return _level;
  }
  
  public void setLevel(LogLevel level)
  {
    _level = level;
  }
  
  public abstract boolean isSevereLevel();
  
  public boolean hasThrown()
  {
    Throwable thrown = getThrown();
    if (thrown == null) {
      return false;
    }
    String thrownString = thrown.toString();
    return (thrownString != null) && (thrownString.trim().length() != 0);
  }
  
  public boolean isFatal()
  {
    return (isSevereLevel()) || (hasThrown());
  }
  
  public String getCategory()
  {
    return _category;
  }
  
  public void setCategory(String category)
  {
    _category = category;
  }
  
  public String getMessage()
  {
    return _message;
  }
  
  public void setMessage(String message)
  {
    _message = message;
  }
  
  public long getSequenceNumber()
  {
    return _sequenceNumber;
  }
  
  public void setSequenceNumber(long number)
  {
    _sequenceNumber = number;
  }
  
  public long getMillis()
  {
    return _millis;
  }
  
  public void setMillis(long millis)
  {
    _millis = millis;
  }
  
  public String getThreadDescription()
  {
    return _thread;
  }
  
  public void setThreadDescription(String threadDescription)
  {
    _thread = threadDescription;
  }
  
  public String getThrownStackTrace()
  {
    return _thrownStackTrace;
  }
  
  public void setThrownStackTrace(String trace)
  {
    _thrownStackTrace = trace;
  }
  
  public Throwable getThrown()
  {
    return _thrown;
  }
  
  public void setThrown(Throwable thrown)
  {
    if (thrown == null) {
      return;
    }
    _thrown = thrown;
    StringWriter sw = new StringWriter();
    PrintWriter out = new PrintWriter(sw);
    thrown.printStackTrace(out);
    out.flush();
    _thrownStackTrace = sw.toString();
    try
    {
      out.close();
      sw.close();
    }
    catch (IOException e) {}
    out = null;
    sw = null;
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer();
    buf.append("LogRecord: [" + _level + ", " + _message + "]");
    return buf.toString();
  }
  
  public String getNDC()
  {
    return _ndc;
  }
  
  public void setNDC(String ndc)
  {
    _ndc = ndc;
  }
  
  public String getLocation()
  {
    return _location;
  }
  
  public void setLocation(String location)
  {
    _location = location;
  }
  
  public static synchronized void resetSequenceNumber()
  {
    _seqCount = 0L;
  }
  
  protected static synchronized long getNextId()
  {
    _seqCount += 1L;
    return _seqCount;
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.LogRecord
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5;

public abstract interface LogRecordFilter
{
  public abstract boolean passes(LogRecord paramLogRecord);
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.LogRecordFilter
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5;

public class PassingLogRecordFilter
  implements LogRecordFilter
{
  public boolean passes(LogReco
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

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-2019. Infinite Loop Ltd