org.eclipse.osgi_3.7.2.v20120110-1415

class });
  }
  
  public void logged(LogEntry entry)
  {
    try
    {
      Object convertedEvent = convertEvent(entry);
      postEvent.invoke(eventAdmin, new Object[] { convertedEvent });
    }
    catch (InvocationTargetException e)
    {
      Throwable t = e.getTargetException();
      if ((t instanceof RuntimeException)) {
        throw ((RuntimeException)t);
      }
      if ((t instanceof Error)) {
        throw ((Error)t);
      }
      throw new RuntimeException(e);
    }
    catch (IllegalAccessException e)
    {
      throw new RuntimeException(e);
    }
    catch (InstantiationException e)
    {
      throw new RuntimeException(e);
    }
  }
  
  private Object convertEvent(LogEntry entry)
    throws InstantiationException, IllegalAccessException, InvocationTargetException
  {
    String topic = "org/osgi/service/log/LogEntry";
    int level = entry.getLevel();
    switch (level)
    {
    case 1: 
      topic = topic + "/LOG_ERROR";
      break;
    case 2: 
      topic = topic + "/LOG_WARNING";
      break;
    case 3: 
      topic = topic + "/LOG_INFO";
      break;
    case 4: 
      topic = topic + "/LOG_DEBUG";
      break;
    default: 
      topic = topic + "/LOG_OTHER";
    }
    Hashtable<String, Object> properties = new Hashtable();
    Bundle bundle = entry.getBundle();
    if (bundle == null) {
      throw new RuntimeException("LogEntry.getBundle() returns null");
    }
    putBundleProperties(properties, bundle);
    Throwable t = entry.getException();
    if (t != null) {
      putExceptionProperties(properties, t);
    }
    ServiceReference<?> ref = entry.getServiceReference();
    if (ref != null) {
      putServiceReferenceProperties(properties, ref);
    }
    properties.put("log.entry", entry);
    properties.put("log.level", new Integer(entry.getLevel()));
    if (entry.getMessage() != null) {
      properties.put("message", entry.getMessage());
    }
    properties.put("timestamp", new Long(entry.getTime()));
    return event.newInstance(new Object[] { topic, properties });
  }
  
  public static void putServiceReferenceProperties(Hashtable<String, Object> properties, ServiceReference<?> ref)
  {
    properties.put("service", ref);
    properties.put("service.id", ref.getProperty("service.id"));
    Object o = ref.getProperty("service.pid");
    if ((o != null) && ((o instanceof String))) {
      properties.put("service.pid", o);
    }
    Object o2 = ref.getProperty("objectClass");
    if ((o2 != null) && ((o2 instanceof String[]))) {
      properties.put("service.objectClass", o2);
    }
  }
  
  public static void putBundleProperties(Hashtable<String, Object> properties, Bundle bundle)
  {
    properties.put("bundle.id", new Long(bundle.getBundleId()));
    String symbolicName = bundle.getSymbolicName();
    if (symbolicName != null) {
      properties.put("bundle.symbolicName", symbolicName);
    }
    properties.put("bundle", bundle);
  }
  
  public static void putExceptionProperties(Hashtable<String, Object> properties, Throwable t)
  {
    properties.put("exception", t);
    properties.put("exception.class", t.getClass().getName());
    String message = t.getMessage();
    if (message != null) {
      properties.put("exception.message", t.getMessage());
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.log.internal.EventAdminLogListener
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.log.internal;

import java.util.Map;
import java.util.WeakHashMap;
import org.eclipse.equinox.log.ExtendedLogEntry;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogEntry;

public class ExtendedLogEntryImpl
  implements ExtendedLogEntry, LogEntry
{
  private static long nextSequenceNumber = 1L;
  private static long nextThreadId = 1L;
  private static final Map<Thread, Long> threadIds = createThreadIdMap();
  private final String loggerName;
  private final Bundle bundle;
  private final int level;
  private final String message;
  private final Throwable throwable;
  private final Object contextObject;
  private final long time;
  private final long threadId;
  private final String threadName;
  private final long sequenceNumber;
  
  private static Map<Thread, Long> createThreadIdMap()
  {
    try
    {
      Thread.class.getMethod("getId", null);
    }
    catch (NoSuchMethodException localNoSuchMethodException)
    {
      return new WeakHashMap();
    }
    return null;
  }
  
  private static long getId(Thread thread)
  {
    if (threadIds == null) {
      return thread.getId();
    }
    Long threadId = (Long)threadIds.get(thread);
    if (threadId == null)
    {
      threadId = new Long(nextThreadId++);
      threadIds.put(thread, threadId);
    }
    return threadId.longValue();
  }
  
  public ExtendedLogEntryImpl(Bundle bundle, String loggerName, Object contextObject, int level, String message, Throwable throwable)
  {
    time = System.currentTimeMillis();
    this.loggerName = loggerName;
    this.bundle = bundle;
    this.level = level;
    this.message = message;
    this.throwable = throwable;
    this.contextObject = contextObject;
    
    Thread currentThread = Thread.currentThread();
    threadName = currentThread.getName();
    synchronized (ExtendedLogEntryImpl.class)
    {
      threadId = getId(currentThread);
      sequenceNumber = (nextSequenceNumber++);
    }
  }
  
  public String getLoggerName()
  {
    return loggerName;
  }
  
  public long getSequenceNumber()
  {
    return sequenceNumber;
  }
  
  public long getThreadId()
  {
    return threadId;
  }
  
  public String getThreadName()
  {
    return threadName;
  }
  
  public Bundle getBundle()
  {
    return bundle;
  }
  
  public Throwable getException()
  {
    return throwable;
  }
  
  public int getLevel()
  {
    return level;
  }
  
  public String getMessage()
  {
    return message;
  }
  
  public ServiceReference getServiceReference()
  {
    if ((contextObject != null) && ((contextObject instanceof ServiceReference))) {
      return (ServiceReference)contextObject;
    }
    return null;
  }
  
  public long getTime()
  {
    return time;
  }
  
  public Object getContext()
  {
    return contextObject;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.log.internal.ExtendedLogEntryImpl
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.log.internal;

import org.eclipse.equinox.log.LogFilter;
import org.osgi.framework.Bundle;

class ExtendedLogReaderServiceFactory$1
  implements LogFilter
{
  public boolean isLoggable(Bundle b, String loggerName, int logLevel)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.log.internal;

import java.security.PrivilegedAction;
import org.osgi.framework.Bundle;

class ExtendedLogReaderServiceFactory$2
  implements PrivilegedAction<Boolean>
{
  final ExtendedLogReaderServiceFactory this$0;
  
  ExtendedLogReaderServiceFactory$2(ExtendedLogReaderServiceFactory paramExtendedLogReaderServiceFactory, Bundle paramBundle, String paramString, int paramInt) {}
  
  public Boolean run()
  {
    return new Boolean(this$0.isLoggablePrivileged(val$bundle, val$name, val$level));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory.2
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.log.internal;

import java.security.PrivilegedAction;
import org.osgi.framework.Bundle;

class ExtendedLogReaderServiceFactory$3
  implements PrivilegedAction<Object>
{
  final ExtendedLogReaderServiceFactory this$0;
  
  ExtendedLogReaderServiceFactory$3(ExtendedLogReaderServiceFactory paramExtendedLogReaderServiceFactory, Bundle paramBundle, String paramString1, Object paramObject, int paramInt, String paramString2, Throwable paramThrowable) {}
  
  public Object run()
  {
    this$0.logPrivileged(val$bundle, val$name, val$context, val$level, val$message, val$exception);
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory.3
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.log.internal;

import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogListener;

final class ExtendedLogReaderServiceFactory$LogTask
  implements Runnable
{
  private final LogEntry logEntry;
  private final LogListener listener;
  
  ExtendedLogReaderServiceFactory$LogTask(LogEntry logEntry, LogListener listener)
  {
    this.logEntry = logEntry;
    this.listener = listener;
  }
  
  public void run()
  {
    ExtendedLogReaderServiceFactory.safeLogged(listener, logEntry);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory.LogTask
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.log.internal;

import java.io.PrintStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import org.eclipse.equinox.log.LogFilter;
import org.eclipse.osgi.internal.baseadaptor.ArrayMap;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogListener;

public class ExtendedLogReaderServiceFactory
  implements ServiceFactory<ExtendedLogReaderServiceImpl>
{
  static final int MAX_RECURSIONS = 50;
  
  static final class LogTask
    implements Runnable
  {
    private final LogEntry logEntry;
    private final LogListener listener;
    
    LogTask(LogEntry logEntry, LogListener listener)
    {
      this.logEntry = logEntry;
      this.listener = listener;
    }
    
    public void run()
    {
      ExtendedLogReaderServiceFactory.safeLogged(listener, logEntry);
    }
  }
  
  private static final Enumeration<?> EMPTY_ENUMERATION = Collections.enumeration(Collections.EMPTY_LIST);
  static final LogFilter NULL_LOGGER_FILTER = new LogFilter()
  {
    public boolean isLoggable(Bundle b, String loggerName, int logLevel)
    {
      return true;
    }
  };
  private static final LogFilter[] ALWAYS_LOG = new LogFilter[0];
  private static PrintStream errorStream;
  private ArrayMap<LogListener, Object[]> listeners = new ArrayMap(5);
  private LogFilter[] filters = null;
  private BasicReadWriteLock listenersLock = new BasicReadWriteLock();
  
  static boolean safeIsLoggable(LogFilter filter, Bundle bundle, String name, int level)
  {
    try
    {
      return filter.isLoggable(bundle, name, level);
    }
    catch (RuntimeException e)
    {
      getErrorStream().println("LogFilter.isLoggable threw a non-fatal unchecked exception as follows:");
      e.printStackTrace(getErrorStream());
    }
    catch (LinkageError e)
    {
      getErrorStream().println("LogFilter.isLoggable threw a non-fatal unchecked exception as follows:");
      e.printStackTrace(getErrorStream());
    }
    return false;
  }
  
  private static synchronized PrintStream getErrorStream()
  {
    if (errorStream == null) {
      return System.err;
    }
    return errorStream;
  }
  
  public static synchronized void setErrorStream(PrintStream ps)
  {
    errorStream = ps;
  }
  
  static void safeLogged(LogListener listener, LogEntry logEntry)
  {
    try
    {
      listener.logged(logEntry);
    }
    catch (RuntimeException e)
    {
      getErrorStream().println("LogListener.logged threw a non-fatal unchecked exception as follows:");
      e.printStackTrace(getErrorStream());
    }
    catch (LinkageError e)
    {
      getErrorStream().println("LogListener.logged threw a non-fatal unchecked exception as follows:");
      e.printStackTrace(getErrorStream());
    }
  }
  
  public ExtendedLogReaderServiceImpl getService(Bundle bundle, ServiceRegistration<ExtendedLogReaderServiceImpl> registration)
  {
    return new ExtendedLogReaderServiceImpl(this);
  }
  
  public void ungetService(Bundle bundle, ServiceRegistration<ExtendedLogReaderServiceImpl> registration, ExtendedLogReaderServiceImpl service)
  {
    service.shutdown();
  }
  
  boolean isLoggable(final Bundle bundle, final String name, final int level)
  {
    if (System.getSecurityManager() != null) {
      ((Boolean)AccessController.doPrivileged(new PrivilegedAction()
      {
        public Boolean run()
        {
          return new Boolean(isLoggablePrivileged(bundle, name, level));
        }
      })).booleanValue();
    }
    return isLoggablePrivileged(bundle, name, level);
  }
  
  boolean isLoggablePrivileged(Bundle bundle, String name, int level)
  {
    int numNested = listenersLock.readLock();
    try
    {
      if (numNested == 50) {}
      while (filters == null) {
        return false;
      }
      if (filters == ALWAYS_LOG) {
        return true;
      }
      int filtersLength = filters.length;
      for (int i = 0; i < filtersLength; i++)
      {
        LogFilter filter = filters[i];
        if (safeIsLoggable(filter, bundle, name, level)) {
          return true;
        }
      }
    }
    finally
    {
      listenersLock.readUnlock();
    }
    listenersLock.readUnlock();
    
    return false;
  }
  
  void log(final Bundle bundle, final String name, final Object context, final int level, final String message, final Throwable exception)
  {
    if (System.getSecurityManager() != null) {
      AccessController.doPrivileged(new PrivilegedAction()
      {
        public Object run()
        {
          logPrivileged(bundle, name, context, level, message, exception);
          return null;
        }
      });
    } else {
      logPrivileged(bundle, name, context, level, message, exception);
    }
  }
  
  void logPrivileged(Bundle bundle, String name, Object context, int level, String message, Throwable exception)
  {
    LogEntry logEntry = new ExtendedLogEntryImpl(bundle, name, context, level, message, exception);
    int numNested = listenersLock.readLock();
    try
    {
      if (numNested >= 50) {
        return;
      }
      int size = listeners.size();
      for (int i = 0; i < size; i++)
      {
        Object[] listenerObjects = (Object[])listeners.getValue(i);
        LogFilter filter = (LogFilter)listenerObjects[0];
        if (safeIsLoggable(filter, bundle, name, level))
        {
          LogListener listener = (LogListener)listeners.getKey(i);
          SerializedTaskQueue taskQueue = (SerializedTaskQueue)listenerObjects[1];
          if (taskQueue != null) {
            taskQueue.put(new LogTask(logEntry, listener));
          } else {
            safeLogged(listener, logEntry);
          }
        }
      }
    }
    finally
    {
      listenersLock.readUnlock();
    }
    listenersLock.readUnlock();
  }
  
  /* Error */
  void addLogListener(LogListener listener, LogFilter filter)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 245	org/eclipse/equinox/log/internal/ExtendedLogReaderServiceFactory:listenersLock	Lorg/eclipse/equinox/log/internal/BasicReadWriteLock;
    //   4: invokevirtual 260	org/eclipse/equinox/log/internal/BasicReadWriteLock:writeLock	()V
    //   7: aload_0
    //   8: getfield 246	org/eclipse/equinox/log/internal/ExtendedLogReaderServiceFactory:listeners	Lorg/eclipse/osgi/internal/baseadaptor/ArrayMap;
    //   11: aload_1
    //   12: invokevirtual 284	org/eclipse/osgi/internal/baseadaptor/ArrayMap:get	(Ljava/lang/Object;)Ljava/lang/Object;
    //   15: checkcast 107	[Ljava/lang/Object;
    //   18: astore_3
    //   19: aload_3
    //   20: ifnonnull +44 -> 64
    //   23: aload_1
    //   24: instanceof 120
    //   27: ifeq +7 -> 34
    //   30: aconst_null
    //   31: goto +14 -> 45
    //   34: new 129	org/eclipse/equinox/log/internal/SerializedTaskQueue
    //   37: dup
    //   38: aload_1
    //   39: invokevirtual 251	java/lang/Object:toString	()Ljava/lang/String;
    //   42: invokespecial 278	org/eclipse/equinox/log/internal/SerializedTaskQueue:<init>	(Ljava/lang/String;)V
    //   45: astore 4
    //   47: iconst_2
    //   48: anewarray 112	java/lang/Object
    //   51: dup
    //   52: iconst_0
    //   53: aload_2
    //   54: aastore
    //   55: dup
    //   56: iconst_1
    //   57: aload 4
    //   59: aastore
    //   60: astore_3
    //   61: goto +14 -> 75
    //   64: aload_2
    //   65: aload_3
    //   66: iconst_0
    //   67: aaload
    //   68: if_acmpeq +7 -> 75
    //   71: aload_3
    //   72: iconst_0
    //   73: aload_2
    //   74: aastore
    //   75: aload_0
    //   76: getfield 246	org/eclipse/equinox/log/internal/ExtendedLogReaderServiceFactory:listeners	Lorg/eclipse/osgi/internal/baseadaptor/ArrayMap;
    //   79: aload_1
    //   80: aload_3
    //   81: invokevirtual 285	org/eclipse/osgi/internal/baseadaptor/ArrayMap:put	(Ljava/lang/Object;Ljava/lang/Object;)V
    //   84: aload_0
    //   85: invokespecial 263	org/eclipse/equinox/log/internal/ExtendedLogReaderServiceFactory:recalculateFilters	()V
    //   88: goto +15 -> 103
    //   91: astore 5
    //   93: aload_0
    //   94: getfield 245	org/eclipse/equinox/log/internal/ExtendedLogReaderServiceFactory:listenersLock	Lorg/eclipse/equinox/log/internal/BasicReadWriteLock;
    //   97: invokevirtual 261	org/eclipse/equinox/log/internal/BasicReadWriteLock:writeUnlock	()V
    //   100: aload 5
    //   102: athrow
    //   103: aload_0
    //   104: getfield 245	org/eclipse/equinox/log/internal/ExtendedLogReaderServiceFactory:listenersLock	Lorg/eclipse/equinox/log/internal/BasicReadWriteLock;
    //   107: invokevirtual 261	org/eclipse/equinox/log/internal/BasicReadWriteLock:writeUnlock	()V
    //   110: return
    // Line number table:
    //   Java source line #181	-> byte code offset #0
    //   Java source line #183	-> byte code offset #7
    //   Java source line #184	-> byte code offset #19
    //   Java source line #186	-> byte code offset #23
    //   Java source line #187	-> byte code offset #47
    //   Java source line #188	-> byte code offset #64
    //   Java source line #190	-> byte code offset #71
    //   Java source line #192	-> byte code offset #75
    //   Java source line #193	-> byte code offset #84
    //   Java source line #194	-> byte code offset #91
    //   Java source line #195	-> byte code offset #93
    //   Java source line #196	-> byte code offset #100
    //   Java source line #195	-> byte code offset #103
    //   Java source line #197	-> byte code offset #110
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	111	0	this	ExtendedLogReaderServiceFactory
    //   0	111	1	listener	LogListener
    //   0	111	2	filter	LogFilter
    //   18	63	3	listenerObjects	Object[]
    //   45	13	4	taskQueue	SerializedTaskQueue
    //   91	10	5	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   7	91	91	finally
  }
  
  private void recalculateFilters()
  {
    List<LogFilter> filtersList = new ArrayList();
    int size = listeners.size();
    for (int i = 0; i < size; i++)
    {
      Object[] listenerObjects = (Object[])listeners.getValue(i);
      LogFilter filter = (LogFilter)listenerObjects[0];
      if (filter == NULL_LOGGER_FILTER)
      {
        filters = ALWAYS_LOG;
        return;
      }
      filtersList.add(filter);
    }
    if (filtersList.isEmpty()) {
      filters = null;
    }
    filters = ((LogFilter[])filtersList.toArray(new LogFilter[filtersList.size()]));
  }
  
  /* Error */
  void removeLogListener(LogListener listener)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 245	org/eclipse/equinox/log/internal/ExtendedLogReaderServiceFactory:listenersLock	Lorg/eclipse/equinox/log/internal/BasicReadWriteLock;
    //   4: invokevirtual 260	org/eclipse/equinox/log/internal/BasicReadWriteLock:writeLock	()V
    //   7: aload_0
    //   8: getfield 246	org/eclipse/equinox/log/internal/ExtendedLogReaderServiceFactory:listeners	Lorg/eclipse/osgi/internal/baseadaptor/ArrayMap;
    //   11: aload_1
    //   12: invokevirtual 283	org/eclipse/osgi/internal/baseadaptor/ArrayMap:remove	(Ljava/lang/Object;)Z
    //   15: pop
    //   16: aload_0
    //   17: invokespecial 263	org/eclipse/equinox/log/internal/ExtendedLogReaderServiceFactory:recalculateFilters	()V
    //   20: goto +13 -> 33
    //   23: astore_2
    //   24: aload_0
    //   25: getfield 245	org/eclipse/equinox/log/internal/ExtendedLogReaderServiceFactory:listenersLock	Lorg/eclipse/equinox/log/internal/BasicReadWriteLock;
    //   28: invokevirtual 261	org/eclipse/equinox/log/internal/BasicReadWriteLock:writeUnlock	()V
    //   31: aload_2
    //   32: athrow
    //   33: aload_0
    //   34: getfield 245	org/eclipse/equinox/log/internal/ExtendedLogReaderServiceFactory:listenersLock	Lorg/eclipse/equinox/log/internal/BasicReadWriteLock;
    //   37: invokevirtual 261	org/eclipse/equinox/log/internal/BasicReadWriteLock:writeUnlock	()V
    //   40: return
    // Line number table:
    //   Java source line #219	-> byte code offset #0
    //   Java source line #221	-> byte code offset #7
    //   Java source line #222	-> byte code offset #16
    //   Java source line #223	-> byte code offset #23
    //   Java source line #224	-> byte code offset #24
    //   Java source line #225	-> byte code offset #31
    //   Java source line #224	-> byte code offset #33
    //   Java source line #226	-> byte code offset #40
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	41	0	this	ExtendedLogReaderServiceFactory
    //   0	41	1	listener	LogListener
    //   23	9	2	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   7	23	23	finally
  }
  
  Enumeration<?> getLog()
  {
    return EMPTY_ENUMERATION;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.log.internal;

import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.equinox.log.ExtendedLogReaderService;
import org.eclipse.equinox.log.LogFilter;
import org.osgi.service.log.LogListener;

public class ExtendedLogReaderServiceImpl
  implements ExtendedLogReaderService
{
  private final ExtendedLogReaderServiceFactory factory;
  private Set<LogListener> listeners = new HashSet();
  
  ExtendedLogReaderServiceImpl(ExtendedLogReaderServiceFactory factory)
  {
    this.factory = factory;
  }
  
  public synchronized void addLogListener(LogListener listener, LogFilter filter)
  {
    checkShutdown();
    if (listener == null) {
      throw new IllegalArgumentException("LogListener must not be null");
    }
    if (filter == null) {
      throw new IllegalArgumentException("LogFilter must not be null");
    }
    listeners.add(listener);
    factory.addLogListener(listener, filter);
  }
  
  public void addLogListener(LogListener listener)
  {
    addLogListener(listener, ExtendedLogReaderServiceFactory.NULL_LOGGER_FILTER);
  }
  
  public Enumeration getLog()
  {
    checkShutdown();
    return factory.getLog();
  }
  
  public synchronized void removeLogListener(LogListener listener)
  {
    checkShutdown();
    if (listener == null) {
      throw new IllegalArgumentException("LogListener must not be null");
    }
    factory.removeLogListener(listener);
    listeners.remove(listener);
  }
  
  private synchronized void checkShutdown()
  {
    if (listeners == null) {
      throw new IllegalStateException("LogReaderService is shutdown.");
    }
  }
  
  synchronized void shutdown()
  {
    for (Iterator localIterator = listeners.iterator(); localIterator.hasNext();)
    {
      LogListener listener = (LogListener)localIterator.next();
      factory.removeLogListener(listener);
    }
    listeners = null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.log.internal.ExtendedLogReaderServiceImpl
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.log.internal;

import java.security.Permission;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.equinox.log.ExtendedLogService;
import org.eclipse.equinox.log.LogPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;

public class ExtendedLogServiceFactory
  implements ServiceFactory<ExtendedLogService>, BundleListener
{
  private final Permission logPermission = new LogPermission("*", "log");
  private final ExtendedLogReaderServiceFactory logReaderServiceFactory;
  private final Map<Bundle, ExtendedLogService> logServices = new HashMap();
  
  public ExtendedLogServiceFactory(ExtendedLogReaderServiceFactory logReaderServiceFactory)
  {
    this.logReaderServiceFactory = logReaderServiceFactory;
  }
  
  public ExtendedLogServiceImpl getService(Bundle bundle, ServiceRegistration<ExtendedLogService> registration)
  {
    return getLogService(bundle);
  }
  
  public void ungetService(Bundle bundle, ServiceRegistration<ExtendedLogService> registration, ExtendedLogService service) {}
  
  public void bundleChanged(BundleEvent event)
  {
    if (event.getType() == 16) {
      removeLogService(event.getBundle());
    }
  }
  
  synchronized ExtendedLogServiceImpl getLogService(Bundle bundle)
  {
    ExtendedLogServiceImpl logService = (ExtendedLogServiceImpl)logServices.get(bundle);
    if (logService == null)
    {
      logService = new ExtendedLogServiceImpl(this, bundle);
      if ((bundle != null) && (bundle.getState() != 1)) {
        logServices.put(bundle, logService);
      }
    }
    return logService;
  }
  
  synchronized void shutdown()
  {
    logServices.clear();
  }
  
  synchronized void removeLogService(Bundle bundle)
  {
    logServices.remove(bundle);
  }
  
  boolean isLoggable(Bundle bundle, String name, int level)
  {
    return logReaderServiceFactory.isLoggable(bundle, name, level);
  }
  
  void log(Bundle bundle, String name, Object context, int level, String message, Throwable exception)
  {
    logReaderServiceFactory.log(bundle, name, context, level, message, exception);
  }
  
  void checkLogPermission()
    throws SecurityException
  {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
      sm.checkPermission(logPermission);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.log.internal.ExtendedLogServiceFactory
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.log.internal;

import java.util.HashMap;
import org.eclipse.equinox.log.ExtendedLogService;
import org.eclipse.equinox.log.Logger;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;

public class ExtendedLogServiceImpl
  implements ExtendedLogService, LogService
{
  private final ExtendedLogServiceFactory factory;
  private volatile Bundle bundle;
  private final HashMap<String, Logger> loggerCache = new HashMap();
  
  public ExtendedLogServiceImpl(ExtendedLogServiceFactory factory, Bundle bundle)
  {
    this.factory = factory;
    this.bundle = bundle;
  }
  
  public void log(int level, String message)
  {
    log(null, level, message, null);
  }
  
  public void log(int level, String message, Throwable exception)
  {
    log(null, level, message, exception);
  }
  
  public void log(ServiceReference sr, int level, String message)
  {
    log(sr, level, message, null);
  }
  
  public void log(ServiceReference sr, int level, String message, Throwable exception)
  {
    getLogger(null).log(sr, level, message, exception);
  }
  
  public void log(Object context, int level, String message)
  {
    log(context, level, message, null);
  }
  
  public void log(Object context, int level, String message, Throwable exception)
  {
    getLogger(null).log(context, level, message, exception);
  }
  
  public synchronized Logger getLogger(String name)
  {
    Logger logger = (Logger)loggerCache.get(name);
    if (logger == null)
    {
      logger = new LoggerImpl(this, name);
      loggerCache.put(name, logger);
    }
    return logger;
  }
  
  public Logger getLogger(Bundle logBundle, String name)
  {
    if ((logBundle == null) || (logBundle == bundle)) {
      return getLogger(name);
    }
    factory.checkLogPermission();
    ExtendedLogService bundleLogService = factory.getLogService(logBundle);
    return bundleLogService.getLogger(name);
  }
  
  public String getName()
  {
    return getLogger(null).getName();
  }
  
  public boolean isLoggable(int level)
  {
    return getLogger(null).isLoggable(level);
  }
  
  boolean isLoggable(String name, int level)
  {
    return factory.isLoggable(bundle, name, level);
  }
  
  void log(String name, Object context, int level, String message, Throwable exception)
  {
    factory.log(bundle, name, context, level, message, exception);
  }
  
  void setBundle(Bundle bundle)
  {
    this.bundle = bundle;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.log.internal.ExtendedLogServiceImpl
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.log.internal;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.security.cert.X509Certificate;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;

class LogServiceManager$MockSystemBundle
  implements Bundle
{
  public int compareTo(Bundle o)
  {
    long idcomp = getBundleId() - o.getBundleId();
    return idcomp > 0L ? 1 : idcomp < 0L ? -1 : 0;
  }
  
  public int getState()
  {
    return 4;
  }
  
  public void start(int options) {}
  
  public void start() {}
  
  public void stop(int options) {}
  
  public void stop() {}
  
  public void update(InputStream input) {}
  
  public void update() {}
  
  public void uninstall() {}
  
  public Dictionary<String, String> getHeaders()
  {
    return new Hashtable();
  }
  
  public long getBundleId()
  {
    return 0L;
  }
  
  public String getLocation()
  {
    return "System Bundle";
  }
  
  public ServiceReference<?>[] getRegisteredServices()
  {
    return null;
  }
  
  public ServiceReference<?>[] getServicesInUse()
  {
    return null;
  }
  
  public boolean hasPermission(Object permission)
  {
    return true;
  }
  
  public URL getResource(String name)
  {
    return null;
  }
  
  public Dictionary<String, String> getHeaders(String locale)
  {
    return null;
  }
  
  public String getSymbolicName()
  {
    return "org.eclipse.osgi";
  }
  
  public Class<?> loadClass(String name)
    throws ClassNotFoundException
  {
    throw new ClassNotFoundException();
  }
  
  public Enumeration<URL> getResources(String name)
  {
    return null;
  }
  
  public Enumeration<String> getEntryPaths(String path)
  {
    return null;
  }
  
  public URL getEntry(String path)
  {
    return null;
  }
  
  public long getLastModified()
  {
    return System.currentTimeMillis();
  }
  
  public Enumeration<URL> findEntries(String path, String filePattern, boolean recurse)
  {
    return null;
  }
  
  public BundleContext getBundleContext()
  {
    return null;
  }
  
  public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType)
  {
    return new HashMap();
  }
  
  public Version getVersion()
  {
    return new Version(0, 0, 0);
  }
  
  public <A> A adapt(Class<A> type)
  {
    return null;
  }
  
  public File getDataFile(String filename)
  {
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.log.internal.LogServiceManager.MockSystemBundle
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.log.internal;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.security.cert.X509Certificate;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import org.eclipse.equinox.log.ExtendedLogReaderService;
import org.eclipse.equinox.log.ExtendedLogService;
import org.eclipse.equinox.log.LogFilter;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.Version;
import org.osgi.service.log.LogListener;
import org.osgi.service.log.LogReaderService;
import org.osgi.service.log.LogService;

public class LogServiceManager
  implements BundleListener, FrameworkListener, ServiceListener
{
  private static final String[] LOGSERVICE_CLASSES = { LogService.class.getName(), ExtendedLogService.class.getName() };
  private static final String[] LOGREADERSERVICE_CLASSES = { LogReaderService.class.getName(), ExtendedLogReaderService.class.getName() };
  private ServiceRegistration<?> logReaderServiceRegistration;
  private ServiceRegistration<?> logServiceRegistration;
  private final ExtendedLogReaderServiceFactory logReaderServiceFactory = new ExtendedLogReaderServiceFactory();
  private final ExtendedLogServiceFactory logServiceFactory = new ExtendedLogServiceFactory(logReaderServiceFactory);
  private final ExtendedLogServiceImpl systemBundleLog = logServiceFactory.getLogService(new MockSystemBundle());
  private EventAdminAdapter eventAdminAdapter;
  
  public LogServiceManager(LogListener[] systemListeners)
  {
    LogListener[] arrayOfLogListener;
    int j = (arrayOfLogListener = systemListeners).length;
    for (int i = 0; i < j; i++)
    {
      LogListener logListener = arrayOfLogListener[i];
      if ((logListener instanceof LogFilter)) {
        logReaderServiceFactory.addLogListener(logListener, (LogFilter)logListener);
      } else {
        logReaderServiceFactory.addLogListener(logListener, ExtendedLogReaderServiceFactory.NULL_LOGGER_FILTER);
      }
    }
  }
  
  public void start(BundleContext context)
  {
    systemBundleLog.setBundle(context.getBundle());
    context.addBundleListener(this);
    context.addServiceListener(this);
    context.addFrameworkListener(this);
    
    context.addBundleListener(logServiceFactory);
    logReaderServiceRegistration = context.registerService(LOGREADERSERVICE_CLASSES, logReaderServiceFactory, null);
    logServiceRegistration = context.registerService(LOGSERVICE_CLASSES, logServiceFactory, null);
    
    eventAdminAdapter = new EventAdminAdapter(context, logReaderServiceFactory);
    eventAdminAdapter.start();
  }
  
  public void stop(BundleContext context)
  {
    eventAdminAdapter.stop();
    eventAdminAdapter = null;
    logServiceRegistration.unregister();
    logServiceRegistration = null;
    logReaderServiceRegistration.unregister();
    logReaderServiceRegistration = null;
    logServiceFactory.shutdown();
    context.removeFrameworkListener(this);
    context.removeServiceListener(this);
    context.removeBundleListener(this);
  }
  
  public ExtendedLogService getSystemBundleLog()
  {
    return systemBundleLog;
  }
  
  public void bundleChanged(BundleEvent event)
  {
    Bundle bundle = event.getBundle();
    if (logReaderServiceFactory.isLoggable(bundle, null, 3)) {
      logReaderServiceFactory.log(bundle, null, null, 3, getBundleEventTypeName(event.getType()), null);
    }
  }
  
  public void serviceChanged(ServiceEvent event)
  {
    ServiceReference<?> reference = event.getServiceReference();
    Bundle bundle = reference.getBundle();
    int eventType = event.getType();
    int logType = eventType == 2 ? 4 : 3;
    if (logReaderServiceFactory.isLoggable(bundle, null, logType)) {
      logReaderServiceFactory.log(bundle, null, reference, logType, getServiceEventTypeName(eventType), null);
    }
  }
  
  public void frameworkEvent(FrameworkEvent event)
  {
    Bundle bundle = event.getBundle();
    int eventType = event.getType();
    int logType = eventType == 2 ? 1 : 3;
    Throwable throwable = eventType == 2 ? event.getThrowable() : null;
    if (logReaderServiceFactory.isLoggable(bundle, null, logType)) {
      logReaderServiceFactory.log(bundle, null, null, logType, getFrameworkEventTypeName(eventType), throwable);
    }
  }
  
  private static String getBundleEventTypeName(int type)
  {
    switch (type)
    {
    case 1: 
      return "BundleEvent INSTALLED";
    case 32: 
      return "BundleEvent RESOLVED";
    case 2: 
      return "BundleEvent STARTED";
    case 128: 
      return "BundleEvent STARTING";
    case 4: 
      return "BundleEvent STOPPED";
    case 256: 
      return "BundleEvent STOPPING";
    case 16: 
      return "BundleEvent UNINSTALLED";
    case 64: 
      return "BundleEvent UNRESOLVED";
    case 8: 
      return "BundleEvent UPDATED";
    }
    return "BundleEvent " + Integer.toHexString(type);
  }
  
  private static String getServiceEventTypeName(int type)
  {
    switch (type)
    {
    case 1: 
      return "ServiceEvent REGISTERED";
    case 2: 
      return "ServiceEvent MODIFIED";
    case 4: 
      return "ServiceEvent UNREGISTERING";
    }
    return "ServiceEvent " + Integer.toHexString(type);
  }
  
  private static String getFrameworkEventTypeName(int type)
  {
    switch (type)
    {
    case 2: 
      return "FrameworkEvent ERROR";
    case 32: 
      return "FrameworkEvent INFO";
    case 4: 
      return "FrameworkEvent PACKAGES REFRESHED";
    case 1: 
      return "FrameworkEvent STARTED";
    case 8: 
      return "FrameworkEvent STARTLEVEL CHANGED";
    case 16: 
      return "FrameworkEvent WARNING";
    }
    return "FrameworkEvent " + Integer.toHexString(type);
  }
  
  static class MockSystemBundle
    implements Bundle
  {
    public int compareTo(Bundle o)
    {
      long idcomp = getBundleId() - o.getBundleId();
      return idcomp > 0L ? 1 : idcomp < 0L ? -1 : 0;
    }
    
    public int getState()
    {
      return 4;
    }
    
    public void start(int options) {}
    
    public void start() {}
    
    public void stop(int options) {}
    
    public void stop() {}
    
    public void update(InputStream input) {}
    
    public void update() {}
    
    public void uninstall() {}
    
    public Dictionary<String, String> getHeaders()
    {
      return new Hashtable();
    }
    
    public long getBundleId()
    {
      return 0L;
    }
    
    public String getLocation()
    {
      return "System Bundle";
    }
    
    public ServiceReference<?>[] getRegisteredServices()
    {
      return null;
    }
    
    public ServiceReference<?>[] getServicesInUse()
    {
      return null;
    }
    
    public boolean hasPermission(Object permission)
    {
      return true;
    }
    
    public URL getResource(String name)
    {
      return null;
    }
    
    public Dictionary<String, String> getHeaders(String locale)
    {
      return null;
    }
    
    public String getSymbolicName()
    {
      return "org.eclipse.osgi";
    }
    
    public Class<?> loadClass(String name)
      throws ClassNotFoundException
    {
      throw new ClassNotFoundException();
    }
    
    public Enumeration<URL> getResources(St
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

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