org.eclipse.osgi_3.8.2.v20130124-134944

k;
        }
        if (Debug.DEBUG_STARTLEVEL) {
          Debug.println("SLL: Active sl = " + currentSL + "; Bundle " + launch[i].getBundleId() + " sl = " + bsl);
        }
        boolean isLazyStart = launch[i].isLazyStart();
        if (lazyOnly ? isLazyStart : !isLazyStart) {
          framework.resumeBundle(launch[i]);
        }
      }
    }
  }
  
  protected void decFWSL(int decToSL, AbstractBundle[] shutdown)
  {
    if (Debug.DEBUG_STARTLEVEL) {
      Debug.println("SLL: decFWSL: saving activeSL of " + decToSL);
    }
    saveActiveStartLevel(decToSL);
    for (int i = shutdown.length - 1; i >= 0; i--)
    {
      int bsl = shutdown[i].getInternalStartLevel();
      if (bsl <= decToSL + 1)
      {
        if (bsl <= decToSL) {
          break;
        }
        if (shutdown[i].isActive())
        {
          if (Debug.DEBUG_STARTLEVEL) {
            Debug.println("SLL: stopping bundle " + shutdown[i].getBundleId());
          }
          framework.suspendBundle(shutdown[i], false);
        }
      }
    }
  }
  
  private void stopSystemBundle()
  {
    try
    {
      framework.systemBundle.context.stop();
    }
    catch (BundleException sbe)
    {
      if (Debug.DEBUG_STARTLEVEL)
      {
        Debug.println("SLL: Bundle suspend exception: " + sbe.getMessage());
        Debug.printStackTrace(sbe.getNestedException() == null ? sbe : sbe.getNestedException());
      }
      framework.publishFrameworkEvent(2, framework.systemBundle, sbe);
    }
    framework.systemBundle.state = 4;
    framework.publishBundleEvent(4, framework.systemBundle);
  }
  
  private void unloadAllBundles(BundleRepository bundles)
  {
    synchronized (bundles)
    {
      List<AbstractBundle> allBundles = bundles.getBundles();
      int size = allBundles.size();
      for (int i = 0; i < size; i++)
      {
        AbstractBundle bundle = (AbstractBundle)allBundles.get(i);
        if (Debug.DEBUG_STARTLEVEL) {
          Debug.println("SLL: Trying to unload bundle " + bundle);
        }
        bundle.refresh();
        try
        {
          bundle.getBundleData().close();
        }
        catch (IOException localIOException) {}
      }
    }
  }
  
  protected void setBundleSL(StartLevelEvent startLevelEvent)
  {
    synchronized (lock)
    {
      int currentSL = getStartLevel();
      int newSL = startLevelEvent.getNewSL();
      AbstractBundle bundle = startLevelEvent.getBundle();
      if (Debug.DEBUG_STARTLEVEL)
      {
        Debug.print("SLL: bundle active=" + bundle.isActive());
        Debug.print("; newSL = " + newSL);
        Debug.println("; activeSL = " + currentSL);
      }
      if ((bundle.isActive()) && (newSL > currentSL))
      {
        if (Debug.DEBUG_STARTLEVEL) {
          Debug.println("SLL: stopping bundle " + bundle.getBundleId());
        }
        framework.suspendBundle(bundle, false);
      }
      else if ((!bundle.isActive()) && (newSL <= currentSL))
      {
        if (Debug.DEBUG_STARTLEVEL) {
          Debug.println("SLL: starting bundle " + bundle.getBundleId());
        }
        framework.resumeBundle(bundle);
      }
      if (Debug.DEBUG_STARTLEVEL) {
        Debug.println("SLL: Bundle Startlevel set to " + newSL);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.StartLevelManager
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import java.util.Dictionary;
import java.util.Hashtable;
import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.eclipse.osgi.framework.debug.FrameworkDebugOptions;
import org.eclipse.osgi.internal.resolver.StateImpl;
import org.eclipse.osgi.service.debug.DebugOptions;
import org.eclipse.osgi.service.resolver.State;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;

public class SystemBundleActivator
  implements BundleActivator
{
  private BundleContext context;
  private InternalSystemBundle bundle;
  private Framework framework;
  private ServiceRegistration<?> packageAdmin;
  private ServiceRegistration<?> securityAdmin;
  private ServiceRegistration<?> startLevel;
  private ServiceRegistration<?> debugOptions;
  private ServiceRegistration<?> contextFinder;
  
  public void start(BundleContext bc)
    throws Exception
  {
    context = bc;
    bundle = ((InternalSystemBundle)bc.getBundle());
    framework = bundle.framework;
    if (framework.packageAdmin != null) {
      packageAdmin = register(new String[] { "org.osgi.service.packageadmin.PackageAdmin" }, framework.packageAdmin, null);
    }
    if (framework.securityAdmin != null) {
      securityAdmin = register(new String[] { "org.osgi.service.permissionadmin.PermissionAdmin", ConditionalPermissionAdmin.class.getName() }, framework.securityAdmin, null);
    }
    if (framework.startLevelManager != null) {
      startLevel = register(new String[] { "org.osgi.service.startlevel.StartLevel" }, framework.startLevelManager, null);
    }
    FrameworkDebugOptions dbgOptions = null;
    if ((dbgOptions = FrameworkDebugOptions.getDefault()) != null)
    {
      dbgOptions.start(bc);
      debugOptions = register(new String[] { DebugOptions.class.getName() }, dbgOptions, null);
    }
    ClassLoader tccl = framework.getContextFinder();
    if (tccl != null)
    {
      Dictionary<String, Object> props = new Hashtable(7);
      props.put("equinox.classloader.type", "contextClassLoader");
      contextFinder = register(new String[] { ClassLoader.class.getName() }, tccl, props);
    }
    framework.adaptor.frameworkStart(bc);
    State state = framework.adaptor.getState();
    if ((state instanceof StateImpl)) {
      ((StateImpl)state).setResolverHookFactory(new CoreResolverHookFactory((BundleContextImpl)context, framework.getServiceRegistry()));
    }
    framework.packageAdmin.setResolvedBundles(bundle);
    
    framework.systemBundle.manifestLocalization = null;
  }
  
  public void stop(BundleContext bc)
    throws Exception
  {
    framework.adaptor.frameworkStop(bc);
    if (packageAdmin != null) {
      packageAdmin.unregister();
    }
    if (securityAdmin != null) {
      securityAdmin.unregister();
    }
    if (startLevel != null) {
      startLevel.unregister();
    }
    if (debugOptions != null)
    {
      FrameworkDebugOptions dbgOptions = FrameworkDebugOptions.getDefault();
      if (dbgOptions != null) {
        dbgOptions.stop(bc);
      }
      debugOptions.unregister();
    }
    if (contextFinder != null) {
      contextFinder.unregister();
    }
    framework = null;
    bundle = null;
    context = null;
  }
  
  private ServiceRegistration<?> register(String[] names, Object service, Dictionary<String, Object> properties)
  {
    if (properties == null) {
      properties = new Hashtable(7);
    }
    Dictionary<String, String> headers = bundle.getHeaders();
    properties.put("service.vendor", headers.get("Bundle-Vendor"));
    properties.put("service.ranking", new Integer(Integer.MAX_VALUE));
    properties.put("service.pid", bundle.getBundleId() + "." + service.getClass().getName());
    return context.registerService(names, service, properties);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.SystemBundleActivator
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import java.util.ArrayList;
import java.util.List;

public class Tokenizer
{
  protected char[] value;
  protected int max;
  protected int cursor;
  
  public Tokenizer(String value)
  {
    this.value = value.toCharArray();
    max = this.value.length;
    cursor = 0;
  }
  
  private void skipWhiteSpace()
  {
    char[] val = value;
    for (int cur = cursor; cur < max; cur++)
    {
      char c = val[cur];
      if ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\r')) {
        break;
      }
    }
    cursor = cur;
  }
  
  public String getToken(String terminals)
  {
    skipWhiteSpace();
    char[] val = value;
    int cur = cursor;
    
    int begin = cur;
    for (; cur < max; cur++)
    {
      char c = val[cur];
      if (terminals.indexOf(c) != -1) {
        break;
      }
    }
    cursor = cur;
    int count = cur - begin;
    if (count > 0)
    {
      skipWhiteSpace();
      while ((count > 0) && ((val[(begin + count - 1)] == ' ') || (val[(begin + count - 1)] == '\t'))) {
        count--;
      }
      return new String(val, begin, count);
    }
    return null;
  }
  
  public String getEscapedToken(String terminals)
  {
    char[] val = value;
    int cur = cursor;
    if (cur >= max) {
      return null;
    }
    StringBuffer sb = new StringBuffer();
    for (; cur < max; cur++)
    {
      char c = val[cur];
      if (c == '\\')
      {
        cur++;
        if (cur == max) {
          break;
        }
        c = val[cur];
      }
      else
      {
        if (terminals.indexOf(c) != -1) {
          break;
        }
      }
      sb.append(c);
    }
    cursor = cur;
    return sb.toString();
  }
  
  public List<String> getEscapedTokens(String terminals)
  {
    List<String> result = new ArrayList();
    for (String token = getEscapedToken(terminals); token != null; token = getEscapedToken(terminals))
    {
      result.add(token);
      getChar();
    }
    return result;
  }
  
  public String getString(String terminals, String preserveEscapes)
  {
    skipWhiteSpace();
    char[] val = value;
    int cur = cursor;
    if (cur < max) {
      if (val[cur] == '"')
      {
        StringBuffer sb = new StringBuffer();
        cur++;
        char c = '\000';
        int begin = cur;
        for (; cur < max; cur++)
        {
          c = val[cur];
          if (c == '\\')
          {
            cur++;
            if (cur == max) {
              break;
            }
            c = val[cur];
            if ((preserveEscapes != null) && (preserveEscapes.indexOf(c) != -1)) {
              sb.append('\\');
            }
          }
          else
          {
            if (c == '"') {
              break;
            }
          }
          sb.append(c);
        }
        int count = cur - begin;
        if (c == '"') {
          cur++;
        }
        cursor = cur;
        if (count > 0)
        {
          skipWhiteSpace();
          return sb.toString();
        }
      }
      else
      {
        return getToken(terminals);
      }
    }
    return null;
  }
  
  public String getString(String terminals)
  {
    return getString(terminals, null);
  }
  
  public char getChar()
  {
    int cur = cursor;
    if (cur < max)
    {
      cursor = (cur + 1);
      return value[cur];
    }
    return '\000';
  }
  
  public boolean hasMoreTokens()
  {
    if (cursor < max) {
      return true;
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Tokenizer
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.SecureRandom;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;

public class UniversalUniqueIdentifier
{
  private byte[] fBits = new byte[16];
  private static volatile BigInteger fgPreviousClockValue;
  private static volatile int fgClockAdjustment = 0;
  private static volatile int fgClockSequence = -1;
  private static final byte[] nodeAddress = computeNodeAddress();
  private static final Random fgRandomNumberGenerator = new Random();
  public static final int BYTES_SIZE = 16;
  public static final byte[] UNDEFINED_UUID_BYTES = new byte[16];
  public static final int MAX_CLOCK_SEQUENCE = 16384;
  public static final int MAX_CLOCK_ADJUSTMENT = 32767;
  public static final int TIME_FIELD_START = 0;
  public static final int TIME_FIELD_STOP = 6;
  public static final int TIME_HIGH_AND_VERSION = 7;
  public static final int CLOCK_SEQUENCE_HIGH_AND_RESERVED = 8;
  public static final int CLOCK_SEQUENCE_LOW = 9;
  public static final int NODE_ADDRESS_START = 10;
  public static final int NODE_ADDRESS_BYTE_SIZE = 6;
  public static final int BYTE_MASK = 255;
  public static final int HIGH_NIBBLE_MASK = 240;
  public static final int LOW_NIBBLE_MASK = 15;
  public static final int SHIFT_NIBBLE = 4;
  public static final int ShiftByte = 8;
  
  public UniversalUniqueIdentifier()
  {
    setVersion(1);
    setVariant(1);
    setTimeValues();
    setNode(getNodeAddress());
  }
  
  private void appendByteString(StringBuffer buffer, byte value)
  {
    String hexString;
    String hexString;
    if (value < 0) {
      hexString = Integer.toHexString(256 + value);
    } else {
      hexString = Integer.toHexString(value);
    }
    if (hexString.length() == 1) {
      buffer.append("0");
    }
    buffer.append(hexString);
  }
  
  private static BigInteger clockValueNow()
  {
    GregorianCalendar now = new GregorianCalendar();
    BigInteger nowMillis = BigInteger.valueOf(now.getTime().getTime());
    BigInteger baseMillis = BigInteger.valueOf(now.getGregorianChange().getTime());
    
    return nowMillis.subtract(baseMillis).multiply(BigInteger.valueOf(10000L));
  }
  
  private static byte[] computeNodeAddress()
  {
    byte[] address = new byte[6];
    
    int thread = Thread.currentThread().hashCode();
    long time = System.currentTimeMillis();
    int objectId = System.identityHashCode(new String());
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(byteOut);
    byte[] ipAddress = getIPAddress();
    try
    {
      if (ipAddress != null) {
        out.write(ipAddress);
      }
      out.write(thread);
      out.writeLong(time);
      out.write(objectId);
      out.close();
    }
    catch (IOException localIOException) {}
    byte[] rand = byteOut.toByteArray();
    
    SecureRandom randomizer = new SecureRandom(rand);
    randomizer.nextBytes(address);
    
    address[0] = ((byte)(address[0] | 0xFFFFFF80));
    
    return address;
  }
  
  private static byte[] getIPAddress()
  {
    try
    {
      return InetAddress.getLocalHost().getAddress();
    }
    catch (UnknownHostException localUnknownHostException)
    {
      return null;
    }
    catch (ArrayIndexOutOfBoundsException localArrayIndexOutOfBoundsException) {}
    return null;
  }
  
  private static byte[] getNodeAddress()
  {
    return nodeAddress;
  }
  
  private static int nextClockSequence()
  {
    if (fgClockSequence == -1) {
      fgClockSequence = (int)(fgRandomNumberGenerator.nextDouble() * 16384.0D);
    }
    fgClockSequence = (fgClockSequence + 1) % 16384;
    
    return fgClockSequence;
  }
  
  private static BigInteger nextTimestamp()
  {
    BigInteger timestamp = clockValueNow();
    
    int timestampComparison = timestamp.compareTo(fgPreviousClockValue);
    if (timestampComparison == 0)
    {
      if (fgClockAdjustment == 32767)
      {
        while (timestamp.compareTo(fgPreviousClockValue) == 0) {
          timestamp = clockValueNow();
        }
        timestamp = nextTimestamp();
      }
      else
      {
        fgClockAdjustment += 1;
      }
    }
    else
    {
      fgClockAdjustment = 0;
      if (timestampComparison < 0) {
        nextClockSequence();
      }
    }
    return timestamp;
  }
  
  private void setClockSequence(int clockSeq)
  {
    int clockSeqHigh = clockSeq >>> 8 & 0xF;
    int reserved = fBits[8] & 0xF0;
    
    fBits[8] = ((byte)(reserved | clockSeqHigh));
    fBits[9] = ((byte)(clockSeq & 0xFF));
  }
  
  private void setNode(byte[] bytes)
  {
    for (int index = 0; index < 6; index++) {
      fBits[(index + 10)] = bytes[index];
    }
  }
  
  private void setTimestamp(BigInteger timestamp)
  {
    BigInteger value = timestamp;
    BigInteger bigByte = BigInteger.valueOf(256L);
    for (int index = 0; index < 6; index++)
    {
      BigInteger[] results = value.divideAndRemainder(bigByte);
      value = results[0];
      fBits[index] = ((byte)results[1].intValue());
    }
    int version = fBits[7] & 0xF0;
    int timeHigh = value.intValue() & 0xF;
    fBits[7] = ((byte)(timeHigh | version));
  }
  
  private synchronized void setTimeValues()
  {
    setTimestamp(timestamp());
    setClockSequence(fgClockSequence);
  }
  
  private int setVariant(int variantIdentifier)
  {
    int clockSeqHigh = fBits[8] & 0xF;
    int variant = variantIdentifier & 0xF;
    
    fBits[8] = ((byte)(variant << 4 | clockSeqHigh));
    return variant;
  }
  
  private void setVersion(int versionIdentifier)
  {
    int timeHigh = fBits[7] & 0xF;
    int version = versionIdentifier & 0xF;
    
    fBits[7] = ((byte)(timeHigh | version << 4));
  }
  
  private static BigInteger timestamp()
  {
    BigInteger timestamp;
    BigInteger timestamp;
    if (fgPreviousClockValue == null)
    {
      fgClockAdjustment = 0;
      nextClockSequence();
      timestamp = clockValueNow();
    }
    else
    {
      timestamp = nextTimestamp();
    }
    fgPreviousClockValue = timestamp;
    return fgClockAdjustment == 0 ? timestamp : timestamp.add(BigInteger.valueOf(fgClockAdjustment));
  }
  
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < fBits.length; i++)
    {
      if ((i == 4) || (i == 6) || (i == 8) || (i == 10)) {
        buffer.append('-');
      }
      appendByteString(buffer, fBits[i]);
    }
    return buffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.UniversalUniqueIdentifier
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

public class Util
{
  public static void sortByString(Object[] array)
  {
    qSortByString(array, 0, array.length - 1);
  }
  
  public static void qSortByString(Object[] array, int start, int stop)
  {
    if (start >= stop) {
      return;
    }
    int left = start;
    int right = stop;
    
    String mid = String.valueOf(array[((start + stop) / 2)]);
    for (goto 105; left <= right;)
    {
      do
      {
        if (left >= stop) {
          break;
        }
      } while (String.valueOf(array[left]).compareTo(mid) < 0);
      while ((right > start) && (mid.compareTo(String.valueOf(array[right])) < 0)) {
        right--;
      }
      if (left <= right)
      {
        Object temp = array[left];
        array[left] = array[right];
        array[right] = temp;
        left++;
        right--;
      }
    }
    if (start < right) {
      qSortByString(array, start, right);
    }
    if (left < stop) {
      qSortByString(array, left, stop);
    }
  }
  
  public static void sort(Object[] array, int start, int end)
  {
    int middle = (start + end) / 2;
    if (start + 1 < middle) {
      sort(array, start, middle);
    }
    if (middle + 1 < end) {
      sort(array, middle, end);
    }
    if (start + 1 >= end) {
      return;
    }
    if (((Comparable)array[(middle - 1)]).compareTo(array[middle]) <= 0) {
      return;
    }
    if (start + 2 == end)
    {
      Object temp = array[start];
      array[start] = array[middle];
      array[middle] = temp;
      return;
    }
    int i1 = start;int i2 = middle;int i3 = 0;
    Object[] merge = new Object[end - start];
    while ((i1 < middle) && (i2 < end)) {
      merge[(i3++)] = (((Comparable)array[i1]).compareTo(array[i2]) <= 0 ? array[(i1++)] : array[(i2++)]);
    }
    if (i1 < middle) {
      System.arraycopy(array, i1, merge, i3, middle - i1);
    }
    System.arraycopy(merge, 0, array, start, i2 - start);
  }
  
  public static void dsort(Object[] array, int start, int end)
  {
    sort(array, start, end);
    
    swap(array);
  }
  
  public static void swap(Object[] array)
  {
    int start = 0;
    int end = array.length - 1;
    while (start < end)
    {
      Object temp = array[start];
      array[(start++)] = array[end];
      array[(end--)] = temp;
    }
  }
  
  public static String toString(Object object, int length)
  {
    boolean onLeft = object instanceof Number;
    return toString(object, length, ' ', onLeft);
  }
  
  public static String toString(Object object, int length, char pad, boolean onLeft)
  {
    String input = String.valueOf(object);
    int size = input.length();
    if (size >= length)
    {
      int start = onLeft ? size - length : 0;
      return input.substring(start, length);
    }
    StringBuffer padding = new StringBuffer(length - size);
    for (int i = size; i < length; i++) {
      padding.append(pad);
    }
    StringBuffer stringBuffer = new StringBuffer(length);
    if (onLeft) {
      stringBuffer.append(padding.toString());
    }
    stringBuffer.append(input);
    if (!onLeft) {
      stringBuffer.append(padding.toString());
    }
    return stringBuffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Util
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.protocol;

import java.lang.reflect.Method;
import java.net.ContentHandler;
import java.net.URLConnection;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.eclipse.osgi.framework.internal.core.Msg;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;

public class ContentHandlerFactory
  extends MultiplexingFactory
  implements java.net.ContentHandlerFactory
{
  private ServiceTracker<ContentHandler, ContentHandler> contentHandlerTracker;
  private static final String contentHandlerClazz = "java.net.ContentHandler";
  private static final String CONTENT_HANDLER_PKGS = "java.content.handler.pkgs";
  private static final String DEFAULT_VM_CONTENT_HANDLERS = "sun.net.www.content";
  private static final List<Class<?>> ignoredClasses = Arrays.asList(new Class[] { MultiplexingContentHandler.class, ContentHandlerFactory.class, URLConnection.class });
  private Map<String, ContentHandlerProxy> proxies;
  private java.net.ContentHandlerFactory parentFactory;
  
  public ContentHandlerFactory(BundleContext context, FrameworkAdaptor adaptor)
  {
    super(context, adaptor);
    
    proxies = new Hashtable(5);
    
    contentHandlerTracker = new ServiceTracker(context, "java.net.ContentHandler", null);
    contentHandlerTracker.open();
  }
  
  public ContentHandler createContentHandler(String contentType)
  {
    String builtInHandlers = StreamHandlerFactory.secureAction.getProperty("java.content.handler.pkgs");
    builtInHandlers = "sun.net.www.content|" + builtInHandlers;
    Class<?> clazz = null;
    if (builtInHandlers != null)
    {
      String convertedContentType = contentType.replace('.', '_');
      convertedContentType = convertedContentType.replace('/', '.');
      convertedContentType = convertedContentType.replace('-', '_');
      StringTokenizer tok = new StringTokenizer(builtInHandlers, "|");
      while (tok.hasMoreElements())
      {
        StringBuffer name = new StringBuffer();
        name.append(tok.nextToken());
        name.append(".");
        name.append(convertedContentType);
        try
        {
          clazz = StreamHandlerFactory.secureAction.loadSystemClass(name.toString());
          if (clazz != null) {
            return null;
          }
        }
        catch (ClassNotFoundException localClassNotFoundException) {}
      }
    }
    if (isMultiplexing()) {
      return new MultiplexingContentHandler(contentType, this);
    }
    return createInternalContentHandler(contentType);
  }
  
  public ContentHandler createInternalContentHandler(String contentType)
  {
    ContentHandlerProxy proxy = (ContentHandlerProxy)proxies.get(contentType);
    if (proxy != null) {
      return proxy;
    }
    ServiceReference[] serviceReferences = contentHandlerTracker.getServiceReferences();
    if (serviceReferences != null) {
      for (int i = 0; i < serviceReferences.length; i++)
      {
        Object prop = serviceReferences[i].getProperty("url.content.mimetype");
        if ((prop instanceof String)) {
          prop = new String[] { (String)prop };
        }
        if (!(prop instanceof String[]))
        {
          String message = NLS.bind(Msg.URL_HANDLER_INCORRECT_TYPE, new Object[] { "url.content.mimetype", "java.net.ContentHandler", serviceReferences[i].getBundle() });
          adaptor.getFrameworkLog().log(new FrameworkLogEntry("org.eclipse.osgi", 2, 0, message, 0, null, null));
        }
        else
        {
          String[] contentHandler = (String[])prop;
          for (int j = 0; j < contentHandler.length; j++) {
            if (contentHandler[j].equals(contentType))
            {
              proxy = new ContentHandlerProxy(contentType, serviceReferences[i], context);
              proxies.put(contentType, proxy);
              return proxy;
            }
          }
        }
      }
    }
    if (parentFactory != null)
    {
      ContentHandler parentHandler = parentFactory.createContentHandler(contentType);
      if (parentHandler != null) {
        return parentHandler;
      }
    }
    proxy = new ContentHandlerProxy(contentType, null, context);
    proxies.put(contentType, proxy);
    return proxy;
  }
  
  public synchronized ContentHandler findAuthorizedContentHandler(String contentType)
  {
    Object factory = findAuthorizedFactory(ignoredClasses);
    if (factory == null) {
      return null;
    }
    if (factory == this) {
      return createInternalContentHandler(contentType);
    }
    try
    {
      Method createInternalContentHandlerMethod = factory.getClass().getMethod("createInternalContentHandler", new Class[] { String.class });
      return (ContentHandler)createInternalContentHandlerMethod.invoke(factory, new Object[] { contentType });
    }
    catch (Exception e)
    {
      adaptor.getFrameworkLog().log(new FrameworkLogEntry(ContentHandlerFactory.class.getName(), 4, 0, "findAuthorizedContentHandler-loop", 0, e, null));
      throw new RuntimeException(e.getMessage(), e);
    }
  }
  
  public Object getParentFactory()
  {
    return parentFactory;
  }
  
  public void setParentFactory(Object parentFactory)
  {
    if (this.parentFactory == null) {
      this.parentFactory = ((java.net.ContentHandlerFactory)parentFactory);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.protocol.ContentHandlerFactory
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.protocol;

import java.io.IOException;
import java.net.ContentHandler;
import java.net.URLConnection;

class ContentHandlerProxy$DefaultContentHandler
  extends ContentHandler
{
  final ContentHandlerProxy this$0;
  
  ContentHandlerProxy$DefaultContentHandler(ContentHandlerProxy paramContentHandlerProxy) {}
  
  public Object getContent(URLConnection uConn)
    throws IOException
  {
    return uConn.getInputStream();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.protocol.ContentHandlerProxy.DefaultContentHandler
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.protocol;

import java.io.IOException;
import java.net.ContentHandler;
import java.net.URLConnection;
import org.eclipse.osgi.framework.util.SecureAction;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

public class ContentHandlerProxy
  extends ContentHandler
  implements ServiceTrackerCustomizer<ContentHandler, ServiceReference<ContentHandler>>
{
  protected ContentHandler realHandler;
  protected ServiceTracker<ContentHandler, ServiceReference<ContentHandler>> contentHandlerServiceTracker;
  protected BundleContext context;
  protected ServiceReference<ContentHandler> contentHandlerServiceReference;
  protected String contentType;
  protected int ranking = Integer.MIN_VALUE;
  
  public ContentHandlerProxy(String contentType, ServiceReference<ContentHandler> reference, BundleContext context)
  {
    this.context = context;
    this.contentType = contentType;
    
    setNewHandler(reference, getRank(reference));
    
    contentHandlerServiceTracker = new ServiceTracker(context, ContentHandler.class.getName(), this);
    StreamHandlerFactory.secureAction.open(contentHandlerServiceTracker);
  }
  
  private void setNewHandler(ServiceReference<ContentHandler> reference, int rank)
  {
    if (contentHandlerServiceReference != null) {
      context.ungetService(contentHandlerServiceReference);
    }
    contentHandlerServiceReference = reference;
    ranking = rank;
    if (reference == null) {
      realHandler = new DefaultContentHandler();
    } else {
      realHandler = ((ContentHandler)StreamHandlerFactory.secureAction.getService(reference, context));
    }
  }
  
  public ServiceReference<ContentHandler> addingService(ServiceReference<ContentHandler> reference)
  {
    Object prop = reference.getProperty("url.content.mimetype");
    if (!(prop instanceof String[])) {
      return null;
    }
    String[] contentTypes = (String[])prop;
    for (int i = 0; i < contentTypes.length; i++) {
      if (contentTypes[i].equals(contentType))
      {
        int newServiceRanking = getRank(reference);
        if ((newServiceRanking > ranking) || (contentHandlerServiceReference == null)) {
          setNewHandler(reference, newServiceRanking);
        }
        return reference;
      }
    }
    return null;
  }
  
  public void modifiedService(ServiceReference<ContentHandler> reference, ServiceReference<ContentHandler> service)
  {
    int newrank = getRank(reference);
    if (reference == contentHandlerServiceReference)
    {
      if (newrank < ranking)
      {
        ServiceReference<ContentHandler> newReference = contentHandlerServiceTracker.getServiceReference();
        if ((newReference != contentHandlerServiceReference) && (newReference != null)) {
          setNewHandler(newReference, ((Integer)newReference.getProperty("service.ranking")).intValue());
        }
      }
    }
    else if (newrank > ranking) {
      setNewHandler(reference, newrank);
    }
  }
  
  public void removedService(ServiceReference<ContentHandler> reference, ServiceReference<ContentHandler> service)
  {
    if (reference != contentHandlerServiceReference) {
      return;
    }
    ServiceReference<ContentHandler> newReference = contentHandlerServiceTracker.getServiceReference();
    
    setNewHandler(newReference, getRank(newReference));
  }
  
  public Object getContent(URLConnection uConn)
    throws IOException
  {
    return realHandler.getContent(uConn);
  }
  
  private int getRank(ServiceReference<?> reference)
  {
    if (reference == null) {
      return Integer.MIN_VALUE;
    }
    Object property = reference.getProperty("service.ranking");
    return (property instanceof Integer) ? ((Integer)property).intValue() : 0;
  }
  
  class DefaultContentHandler
    extends ContentHandler
  {
    DefaultContentHandler() {}
    
    public Object getContent(URLConnection uConn)
      throws IOException
    {
      return uConn.getInputStream();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.protocol.ContentHandlerProxy
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.protocol;

import java.io.IOException;
import java.net.ContentHandler;
import java.net.URLConnection;

public class MultiplexingContentHandler
  extends ContentHandler
{
  private String contentType;
  private ContentHandlerFactory factory;
  
  public MultiplexingContentHandler(String contentType, ContentHandlerFactory factory)
  {
    this.contentType = contentType;
    this.factory = factory;
  }
  
  public Object getContent(URLConnection uConn)
    throws IOException
  {
    ContentHandler handler = factory.findAuthorizedContentHandler(contentType);
    if (handler != null) {
      return handler.getContent(uConn);
    }
    return uConn.getInputStream();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.protocol.MultiplexingContentHandler
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.protocol;

class MultiplexingFactory$InternalSecurityManager
  extends SecurityManager
{
  public Class<?>[] getClassContext()
  {
    return super.getClassContext();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.protocol.MultiplexingFactory.InternalSecurityManager
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.protocol;

import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.util.tracker.ServiceTracker;

public abstract class MultiplexingFactory
{
  protected static final String PACKAGEADMINCLASS = "org.osgi.service.packageadmin.PackageAdmin";
  protected BundleContext context;
  protected FrameworkAdaptor adaptor;
  private List<Object> factories;
  private ServiceTracker<ServiceReference<?>, PackageAdmin> packageAdminTracker;
  
  static class InternalSecurityManager
    extends SecurityManager
  {
    public Class<?>[] getClassContext()
    {
      return super.getClassContext();
    }
  }
  
  private static InternalSecurityManager internalSecurityManager = new InternalSecurityManager();
  
  MultiplexingFactory(BundleContext context, FrameworkAdaptor adaptor)
  {
    this.context = context;
    this.adaptor = adaptor;
    packageAdminTracker = new ServiceTracker(context, "org.osgi.service.packageadmin.PackageAdmin", null);
    packageAdminTracker.open();
  }
  
  public abstract void setParentFactory(Object paramObject);
  
  public abstract Object getParentFactory();
  
  public boolean isMultiplexing()
  {
    return getFactories() != null;
  }
  
  public void register(Object factory)
  {
    try
    {
      Class<?> clazz = factory.getClass();
      Method setParentFactory = clazz.getMethod("setParentFactory", new Class[] { Object.class });
      setParentFactory.invoke(factory, new Object[] { getParentFactory() });
    }
    catch (Exception e)
    {
      adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingFactory.class.getName(), 4, 0, "register", 4, e, null));
      throw new RuntimeException(e.getMessage(), e);
    }
    addFactory(factory);
  }
  
  public void unregister(Object factory)
  {
    removeFactory(factory);
    try
    {
      Method closeTracker = factory.getClass().getSuperclass().getDeclaredMethod("closePackageAdminTracker", null);
      closeTracker.setAccessible(true);
      closeTracker.invoke(factory, null);
    }
    catch (Exception e)
    {
      adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingFactory.class.getName(), 4, 0, "unregister", 4, e, null));
      throw new RuntimeException(e.getMessage(), e);
    }
  }
  
  public Object designateSuccessor()
  {
    List<Object> released = releaseFactories();
    if ((released == null) || (released.isEmpty())) {
      return getParentFactory();
    }
    Object successor = released.remove(0);
    try
    {
      Class<?> clazz = successor.getClass();
      Method register = clazz.getMethod("register", new Class[] { Object.class });
      for (Iterator localIterator = released.iterator(); localIterator.hasNext();)
      {
        Object r = localIterator.next();
        register.invoke(successor, new Object[] { r });
      }
    }
    catch (Exception e)
    {
      adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingFactory.class.getName(), 4, 0, "designateSuccessor", 4, e, null));
      throw new RuntimeException(e.getMessage(), e);
    }
    closePackageAdminTracker();
    return successor;
  }
  
  private void closePackageAdminTracker()
  {
    packageAdminTracker.close();
  }
  
  public Object findAuthorizedFactory(List<Class<?>> ignoredClasses)
  {
    List<Object> current = getFactories();
    Class[] classStack = internalSecurityManager.getClassContext();
    for (int i = 0; i < classStack.length; i++)
    {
      Class<?> clazz = classStack[i];
      if ((clazz != InternalSecurityManager.class) && (clazz != MultiplexingFactory.class) && (!ignoredClasses.contains(clazz)))
      {
        if (hasAuthority(clazz)) {
          return this;
        }
        if (current != null) {
          for (Iterator localIterator = current.iterator(); localIterator.hasNext();)
          {
            Object factory = localIterator.next();
            try
            {
              Method hasAuthorityMethod = factory.getClass().getMethod("hasAuthority", new Class[] { Class.class });
              if (((Boolean)hasAuthorityMethod.invoke(factory, new Object[] { clazz })).booleanValue()) {
                return factory;
              }
            }
            catch (Exception e)
            {
              adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingFactory.class.getName(), 4, 0, "findAuthorizedURLStreamHandler-loop", 4, e, null));
              throw new RuntimeException(e.getMessage(), e);
            }
          }
        }
      }
    }
    return this;
  }
  
  public boolean hasAuthority(Class<?> clazz)
  {
    PackageAdmin packageAdminService = (PackageAdmin)packageAdminTracker.getService();
    if (packageAdminService != null) {
      return packageAdminService.getBundle(clazz) != null;
    }
    return false;
  }
  
  private synchronized List<Object> getFactories()
  {
    return factories;
  }
  
  private synchronized List<Object> releaseFactories()
  {
    if (factories == null) {
      return null;
    }
    List<Object> released = new LinkedList(factories);
    factories = null;
    return released;
  }
  
  private synchronized void addFactory(Object factory)
  {
    List<Object> updated = factories == null ? new LinkedList() : new LinkedList(factories);
    updated.add(factory);
    factories = updated;
  }
  
  private synchronized void removeFactory(Object factory)
  {
    List<Object> updated = new LinkedList(factories);
    updated.remove(factory);
    factories = (updated.isEmpty() ? null : updated);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.protocol.MultiplexingFactory
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.protocol;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.eclipse.osgi.framework.internal.core.Framework;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;

public class Multip
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

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