org.eclipse.osgi_3.7.2.v20120110-1415

ontext 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 null;
  }
  
  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 MultiplexingURLStreamHandler
  extends URLStreamHandler
{
  private static Method openConnectionMethod;
  private static Method equalsMethod;
  private static Method getDefaultPortMethod;
  private static Method getHostAddressMethod;
  private static Method hashCodeMethod;
  private static Method hostsEqualMethod;
  private static Method parseURLMethod;
  private static Method sameFileMethod;
  private static Method setURLMethod;
  private static Method toExternalFormMethod;
  private static Field handlerField;
  private static boolean methodsInitialized = false;
  private String protocol;
  private StreamHandlerFactory factory;
  
  private static synchronized void initializeMethods(StreamHandlerFactory factory)
  {
    if (methodsInitialized) {
      return;
    }
    try
    {
      openConnectionMethod = tmp10_7.getDeclaredMethod("openConnection", new Class[] { URL.class });
      openConnectionMethod.setAccessible(true);
      
      equalsMethod = tmp96_93.getDeclaredMethod("equals", new Class[] { URL.class, URL.class });
      equalsMethod.setAccessible(true);
      
      getDefaultPortMethod = URLStreamHandler.class.getDeclaredMethod("getDefaultPort", null);
      getDefaultPortMethod.setAccessible(true);
      
      getHostAddressMethod = tmp265_262.getDeclaredMethod("getHostAddress", new Class[] { URL.class });
      getHostAddressMethod.setAccessible(true);
      
      hashCodeMethod = tmp351_348.getDeclaredMethod("hashCode", new Class[] { URL.class });
      hashCodeMethod.setAccessible(true);
      
      hostsEqualMethod = tmp437_434.getDeclaredMethod("hostsEqual", new Class[] { URL.class, URL.class });
      hostsEqualMethod.setAccessible(true);
      
      parseURLMethod = tmp558_555.getDeclaredMethod("parseURL", new Class[] { URL.class, String.class, Integer.TYPE, Integer.TYPE });
      parseURLMethod.setAccessible(true);
      
      sameFileMethod = tmp691_688.getDeclaredMethod("sameFile", new Class[] { URL.class, URL.class });
      sameFileMethod.setAccessible(true);
      
      setURLMethod = tmp812_809.getDeclaredMethod("setURL", new Class[] { URL.class, String.class, String.class, Integer.TYPE, String.class, String.class, String.class, String.class, String.class });
      setURLMethod.setAccessible(true);
      
      toExternalFormMethod = tmp1153_1150.getDeclaredMethod("toExternalForm", new Class[] { URL.class });
      toExternalFormMethod.setAccessible(true);
      try
      {
        handlerField = URL.class.getDeclaredField("handler");
      }
      catch (NoSuchFieldException e)
      {
        handlerField = Framework.getField(URL.class, URLStreamHandler.class, true);
        if (handlerField == null) {
          throw e;
        }
      }
      handlerField.setAccessible(true);
    }
    catch (Exception e)
    {
      adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingURLStreamHandler.class.getName(), 4, 0, "initializeMethods", 0, e, null));
      throw new RuntimeException(e.getMessage(), e);
    }
    methodsInitialized = true;
  }
  
  public MultiplexingURLStreamHandler(String protocol, StreamHandlerFactory factory)
  {
    this.protocol = protocol;
    this.factory = factory;
    initializeMethods(factory);
  }
  
  protected URLConnection openConnection(URL url)
    throws IOException
  {
    URLStreamHandler handler = factory.findAuthorizedURLStreamHandler(protocol);
    if (handler != null) {
      try
      {
        return (URLConnection)openConnectionMethod.invoke(handler, new Object[] { url });
      }
      catch (InvocationTargetException e)
      {
        if ((e.getTargetException() instanceof IOException)) {
          throw ((IOException)e.getTargetException());
        }
        throw ((RuntimeException)e.getTargetException());
      }
      catch (Exception e)
      {
        factory.adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingURLStreamHandler.class.getName(), 4, 0, "openConnection", 0, e, null));
        throw new RuntimeException(e.getMessage(), e);
      }
    }
    throw new MalformedURLException();
  }
  
  protected boolean equals(URL url1, URL url2)
  {
    URLStreamHandler handler = factory.findAuthorizedURLStreamHandler(protocol);
    if (handler != null) {
      try
      {
        return ((Boolean)equalsMethod.invoke(handler, new Object[] { url1, url2 })).booleanValue();
      }
      catch (InvocationTargetException e)
      {
        throw ((RuntimeException)e.getTargetException());
      }
      catch (Exception e)
      {
        factory.adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingURLStreamHandler.class.getName(), 4, 0, "equals", 0, e, null));
        throw new RuntimeException(e.getMessage(), e);
      }
    }
    throw new IllegalStateException();
  }
  
  protected int getDefaultPort()
  {
    URLStreamHandler handler = factory.findAuthorizedURLStreamHandler(protocol);
    if (handler != null) {
      try
      {
        return ((Integer)getDefaultPortMethod.invoke(handler, null)).intValue();
      }
      catch (InvocationTargetException e)
      {
        throw ((RuntimeException)e.getTargetException());
      }
      catch (Exception e)
      {
        factory.adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingURLStreamHandler.class.getName(), 4, 0, "getDefaultPort", 0, e, null));
        throw new RuntimeException(e.getMessage(), e);
      }
    }
    throw new IllegalStateException();
  }
  
  protected InetAddress getHostAddress(URL url)
  {
    URLStreamHandler handler = factory.findAuthorizedURLStreamHandler(protocol);
    if (handler != null) {
      try
      {
        return (InetAddress)getHostAddressMethod.invoke(handler, new Object[] { url });
      }
      catch (InvocationTargetException e)
      {
        throw ((RuntimeException)e.getTargetException());
      }
      catch (Exception e)
      {
        factory.adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingURLStreamHandler.class.getName(), 4, 0, "hashCode", 0, e, null));
        throw new RuntimeException(e.getMessage(), e);
      }
    }
    throw new IllegalStateException();
  }
  
  protected int hashCode(URL url)
  {
    URLStreamHandler handler = factory.findAuthorizedURLStreamHandler(protocol);
    if (handler != null) {
      try
      {
        return ((Integer)hashCodeMethod.invoke(handler, new Object[] { url })).intValue();
      }
      catch (InvocationTargetException e)
      {
        throw ((RuntimeException)e.getTargetException());
      }
      catch (Exception e)
      {
        factory.adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingURLStreamHandler.class.getName(), 4, 0, "hashCode", 0, e, null));
        throw new RuntimeException(e.getMessage(), e);
      }
    }
    throw new IllegalStateException();
  }
  
  protected boolean hostsEqual(URL url1, URL url2)
  {
    URLStreamHandler handler = factory.findAuthorizedURLStreamHandler(protocol);
    if (handler != null) {
      try
      {
        return ((Boolean)hostsEqualMethod.invoke(handler, new Object[] { url1, url2 })).booleanValue();
      }
      catch (InvocationTargetException e)
      {
        throw ((RuntimeException)e.getTargetException());
      }
      catch (Exception e)
      {
        factory.adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingURLStreamHandler.class.getName(), 4, 0, "hostsEqual", 0, e, null));
        throw new RuntimeException(e.getMessage(), e);
      }
    }
    throw new IllegalStateException();
  }
  
  protected void parseURL(URL arg0, String arg1, int arg2, int arg3)
  {
    URLStreamHandler handler = factory.findAuthorizedURLStreamHandler(protocol);
    if (handler != null) {
      try
      {
        handlerField.set(arg0, handler);
        parseURLMethod.invoke(handler, new Object[] { arg0, arg1, new Integer(arg2), new Integer(arg3) });
        return;
      }
      catch (InvocationTargetException e)
      {
        throw ((RuntimeException)e.getTargetException());
      }
      catch (Exception e)
      {
        factory.adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingURLStreamHandler.class.getName(), 4, 0, "parseURL", 0, e, null));
        throw new RuntimeException(e.getMessage(), e);
      }
    }
    throw new IllegalStateException();
  }
  
  protected boolean sameFile(URL url1, URL url2)
  {
    URLStreamHandler handler = factory.findAuthorizedURLStreamHandler(protocol);
    if (handler != null) {
      try
      {
        return ((Boolean)sameFileMethod.invoke(handler, new Object[] { url1, url2 })).booleanValue();
      }
      catch (InvocationTargetException e)
      {
        throw ((RuntimeException)e.getTargetException());
      }
      catch (Exception e)
      {
        factory.adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingURLStreamHandler.class.getName(), 4, 0, "sameFile", 0, e, null));
        throw new RuntimeException(e.getMessage(), e);
      }
    }
    throw new IllegalStateException();
  }
  
  protected void setURL(URL arg0, String arg1, String arg2, int arg3, String arg4, String arg5, String arg6, String arg7, String arg8)
  {
    URLStreamHandler handler = factory.findAuthorizedURLStreamHandler(protocol);
    if (handler != null) {
      try
      {
        handlerField.set(arg0, handler);
        setURLMethod.invoke(handler, new Object[] { arg0, arg1, arg2, new Integer(arg3), arg4, arg5, arg6, arg7, arg8 });
        return;
      }
      catch (InvocationTargetException e)
      {
        throw ((RuntimeException)e.getTargetException());
      }
      catch (Exception e)
      {
        factory.adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingURLStreamHandler.class.getName(), 4, 0, "setURL", 0, e, null));
        throw new RuntimeException(e.getMessage(), e);
      }
    }
    throw new IllegalStateException();
  }
  
  protected String toExternalForm(URL url)
  {
    URLStreamHandler handler = factory.findAuthorizedURLStreamHandler(protocol);
    if (handler != null) {
      try
      {
        return (String)toExternalFormMethod.invoke(handler, new Object[] { url });
      }
      catch (InvocationTargetException e)
      {
        throw ((RuntimeException)e.getTargetException());
      }
      catch (Exception e)
      {
        factory.adaptor.getFrameworkLog().log(new FrameworkLogEntry(MultiplexingURLStreamHandler.class.getName(), 4, 0, "toExternalForm", 0, e, null));
        throw new RuntimeException(e.getMessage(), e);
      }
    }
    throw new IllegalStateException();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.protocol.MultiplexingURLStreamHandler
 * 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.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import org.osgi.service.url.URLStreamHandlerService;
import org.osgi.service.url.URLStreamHandlerSetter;

public class NullURLStreamHandlerService
  implements URLStreamHandlerService
{
  public URLConnection openConnection(URL u)
    throws IOException
  {
    throw new MalformedURLException();
  }
  
  public boolean equals(URL url1, URL url2)
  {
    throw new IllegalStateException();
  }
  
  public int getDefaultPort()
  {
    throw new IllegalStateException();
  }
  
  public InetAddress getHostAddress(URL url)
  {
    throw new IllegalStateException();
  }
  
  public int hashCode(URL url)
  {
    throw new IllegalStateException();
  }
  
  public boolean hostsEqual(URL url1, URL url2)
  {
    throw new IllegalStateException();
  }
  
  public boolean sameFile(URL url1, URL url2)
  {
    throw new IllegalStateException();
  }
  
  public void setURL(URL u, String protocol, String host, int port, String authority, String userInfo, String file, String query, String ref)
  {
    throw new IllegalStateException();
  }
  
  public void setURL(URL u, String protocol, String host, int port, String file, String ref)
  {
    throw new IllegalStateException();
  }
  
  public String toExternalForm(URL url)
  {
    throw new IllegalStateException();
  }
  
  public void parseURL(URLStreamHandlerSetter realHandler, URL u, String spec, int start, int limit)
  {
    throw new IllegalStateException();
  }
}

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

import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.osgi.framework.BundleContext;

public abstract interface ProtocolActivator
{
  public abstract void start(BundleContext paramBundleContext, FrameworkAdaptor paramFrameworkAdaptor);
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.protocol.ProtocolActivator
 * 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.URL;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
import java.security.AccessController;
import java.util.ArrayList;
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.service.url.URLStreamHandlerService;
import org.osgi.util.tracker.ServiceTracker;

public class StreamHandlerFactory
  extends MultiplexingFactory
  implements URLStreamHandlerFactory
{
  static final SecureAction secureAction = (SecureAction)AccessController.doPrivileged(SecureAction.createSecureAction());
  private ServiceTracker<URLStreamHandlerService, URLStreamHandlerService> handlerTracker;
  protected static final String URLSTREAMHANDLERCLASS = "org.osgi.service.url.URLStreamHandlerService";
  protected static final String PROTOCOL_HANDLER_PKGS = "java.protocol.handler.pkgs";
  protected static final String INTERNAL_PROTOCOL_HANDLER_PKG = "org.eclipse.osgi.framework.internal.protocol";
  private static final List<Class<?>> ignoredClasses = Arrays.asList(new Class[] { MultiplexingURLStreamHandler.class, StreamHandlerFactory.class, URL.class });
  private static final boolean useNetProxy;
  private Map<String, URLStreamHandler> proxies;
  private URLStreamHandlerFactory parentFactory;
  
  static
  {
    Class<?> clazz = null;
    try
    {
      clazz = Class.forName("java.net.Proxy");
    }
    catch (ClassNotFoundException localClassNotFoundException4) {}
    useNetProxy = clazz != null;
  }
  
  private ThreadLocal<List<String>> creatingProtocols = new ThreadLocal();
  
  public StreamHandlerFactory(BundleContext context, FrameworkAdaptor adaptor)
  {
    super(context, adaptor);
    
    proxies = new Hashtable(15);
    handlerTracker = new ServiceTracker(context, "org.osgi.service.url.URLStreamHandlerService", null);
    handlerTracker.open();
  }
  
  private Class<?> getBuiltIn(String protocol, String builtInHandlers, boolean fromFramework)
  {
    if (builtInHandlers == null) {
      return null;
    }
    StringTokenizer tok = new StringTokenizer(builtInHandlers, "|");
    while (tok.hasMoreElements())
    {
      StringBuffer name = new StringBuffer();
      name.append(tok.nextToken());
      name.append(".");
      name.append(protocol);
      name.append(".Handler");
      try
      {
        Class<?> clazz;
        Class<?> clazz;
        if (fromFramework) {
          clazz = secureAction.forName(name.toString());
        } else {
          clazz = secureAction.loadSystemClass(name.toString());
        }
        if (clazz != null) {
          return clazz;
        }
      }
      catch (ClassNotFoundException localClassNotFoundException) {}
    }
    return null;
  }
  
  public URLStreamHandler createURLStreamHandler(String protocol)
  {
    if (isRecursive(protocol)) {
      return null;
    }
    try
    {
      String builtInHandlers = secureAction.getProperty("java.protocol.handler.pkgs");
      Class<?> clazz = getBuiltIn(protocol, builtInHandlers, false);
      if (clazz != null) {
        return null;
      }
      URLStreamHandler result = null;
      if (isMultiplexing())
      {
        if (findAuthorizedURLStreamHandler(protocol) != null) {
          result = new MultiplexingURLStreamHandler(protocol, this);
        }
      }
      else {
        result = createInternalURLStreamHandler(protocol);
      }
      if ((result == null) && (parentFactory != null)) {
        result = parentFactory.createURLStreamHandler(protocol);
      }
      return result;
    }
    catch (Throwable t)
    {
      adaptor.getFrameworkLog().log(new FrameworkLogEntry(StreamHandlerFactory.class.getName(), 4, 0, "Unexpected error in factory.", 0, t, null));
      return null;
    }
    finally
    {
      releaseRecursive(protocol);
    }
  }
  
  private boolean isRecursive(String protocol)
  {
    List<String> protocols = (List)creatingProtocols.get();
    if (protocols == null)
    {
      protocols = new ArrayList(1);
      creatingProtocols.set(protocols);
    }
    if (protocols.contains(protocol)) {
      return true;
    }
    protocols.add(protocol);
    return false;
  }
  
  private void releaseRecursive(String protocol)
  {
    List<String> protocols = (List)creatingProtocols.get();
    protocols.remove(protocol);
  }
  
  public URLStreamHandler createInternalURLStreamHandler(String protocol)
  {
    String internalHandlerPkgs = secureAction.getProperty("equinox.interal.handler.pkgs");
    internalHandlerPkgs = internalHandlerPkgs + '|' + "org.eclipse.osgi.framework.internal.protocol";
    Class<?> clazz = getBuiltIn(protocol, internalHandlerPkgs, true);
    if (clazz == null)
    {
      URLStreamHandlerProxy handler = (URLStreamHandlerProxy)proxies.get(protocol);
      if (handler != null) {
        return handler;
      }
      ServiceReference[] serviceReferences = handlerTracker.getServiceReferences();
      if (serviceReferences == null) {
        return null;
      }
      for (int i = 0; i < serviceReferences.length; i++)
      {
        Object prop = serviceReferences[i].getProperty("url.handler.protocol");
        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.handler.protocol", "org.osgi.service.url.URLStreamHandlerService", serviceReferences[i].getBundle() });
          adaptor.getFrameworkLog().log(new FrameworkLogEntry("org.eclipse.osgi", 2, 0, message, 0, null, null));
        }
        else
        {
          String[] protocols = (String[])prop;
          for (int j = 0; j < protocols.length; j++) {
            if (protocols[j].equals(protocol))
            {
              handler = useNetProxy ? new URLStreamHandlerFactoryProxyFor15(protocol, serviceReferences[i], context) : new URLStreamHandlerProxy(protocol, serviceReferences[i], context);
              proxies.put(protocol, handler);
              return handler;
            }
          }
        }
      }
      return null;
    }
    try
    {
      URLStreamHandler handler = (URLStreamHandler)clazz.newInstance();
      if ((handler instanceof ProtocolActivator)) {
        ((ProtocolActivator)handler).start(context, adaptor);
      }
      return handler;
    }
    catch (Exception localException) {}
    return null;
  }
  
  protected URLStreamHandler findAuthorizedURLStreamHandler(String protocol)
  {
    Object factory = findAuthorizedFactory(ignoredClasses);
    if (factory == null) {
      return null;
    }
    if (factory == this) {
      return createInternalURLStreamHandler(protocol);
    }
    try
    {
      Method createInternalURLStreamHandlerMethod = factory.getClass().getMethod("createInternalURLStreamHandler", new Class[] { String.class });
      return (URLStreamHandler)createInternalURLStreamHandlerMethod.invoke(factory, new Object[] { protocol });
    }
    catch (Exception e)
    {
      adaptor.getFrameworkLog().log(new FrameworkLogEntry(StreamHandlerFactory.class.getName(), 4, 0, "findAuthorizedURLStreamHandler-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 = ((URLStreamHandlerFactory)parentFactory);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.protocol.StreamHandlerFactory
 * 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.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.url.URLStreamHandlerService;

public class URLStreamHandlerFactoryProxyFor15
  extends URLStreamHandlerProxy
{
  public URLStreamHandlerFactoryProxyFor15(String protocol, ServiceReference<URLStreamHandlerService> reference, BundleContext context)
  {
    super(protocol, reference, context);
  }
  
  protected URLConnection openConnection(URL u, Proxy p)
    throws IOException
  {
    try
    {
      Method openConn = realHandlerService.getClass().getMethod("openConnection", new Class[] { URL.class, Proxy.class });
      return (URLConnection)openConn.invoke(realHandlerService, new Object[] { u, p });
    }
    catch (InvocationTargetException e)
    {
      if ((e.getTargetException() instanceof IOException)) {
        throw ((IOException)e.getTargetException());
      }
      throw ((RuntimeException)e.getTargetException());
    }
    catch (Exception e)
    {
      throw ((UnsupportedOperationException)new UnsupportedOperationException().initCause(e));
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.protocol.URLStreamHandlerFactoryProxyFor15
 * 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.InetAddress;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import org.eclipse.osgi.framework.util.SecureAction;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.url.URLStreamHandlerService;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

public class URLStreamHandlerProxy
  extends URLStreamHandler
  implements ServiceTrackerCustomizer<URLStreamHandlerService, ServiceReference<URLStreamHandlerService>>
{
  protected URLStreamHandlerService realHandlerService;
  protected URLStreamHandlerSetter urlSetter;
  protected ServiceTracker<URLStreamHandlerService, ServiceReference<URLStreamHandlerService>> urlStreamHandlerServiceTracker;
  protected BundleContext context;
  protected ServiceReference<URLStreamHandlerService> urlStreamServiceReference;
  protected String protocol;
  protected int ranking = Integer.MIN_VALUE;
  
  public URLStreamHandlerProxy(String protocol, ServiceReference<URLStreamHandlerService> reference, BundleContext context)
  {
    this.context = context;
    this.protocol = protocol;
    
    urlSetter = new URLStreamHandlerSetter(this);
    
    setNewHandler(reference, getRank(reference));
    
    urlStreamHandlerServiceTracker = new ServiceTracker(context, "org.osgi.service.url.URLStreamHandlerService", this);
    StreamHandlerFactory.secureAction.open(urlStreamHandlerServiceTracker);
  }
  
  private void setNewHandler(ServiceReference<URLStreamHandlerService> reference, int rank)
  {
    if (urlStreamServiceReference != null) {
      context.ungetService(urlStreamServiceReference);
    }
    urlStreamServiceReference = reference;
    ranking = rank;
    if (reference == null) {
      realHandlerService = new NullURLStreamHandlerService();
    } else {
      realHandlerService = ((URLStreamHandlerService)StreamHandlerFactory.secureAction.getService(reference, context));
    }
  }
  
  protected boolean equals(URL url1, URL url2)
  {
    return realHandlerService.equals(url1, url2);
  }
  
  protected int getDefaultPort()
  {
    return realHandlerService.getDefaultPort();
  }
  
  protected InetAddress getHostAddress(URL url)
  {
    return realHandlerService.getHostAddress(url);
  }
  
  protected int hashCode(URL url)
  {
    return realHandlerService.hashCode(url);
  }
  
  protected boolean hostsEqual(URL url1, URL url2)
  {
    return realHandlerService.hostsEqual(url1, url2);
  }
  
  protected URLConnection openConnection(URL url)
    throws IOException
  {
    return realHandlerService.openConnection(url);
  }
  
  protected void parseURL(URL url, String str, int start, int end)
  {
    realHandlerService.parseURL(urlSetter, url, str, start, end);
  }
  
  protected boolean sameFile(URL url1, URL url2)
  {
    return realHandlerService.sameFile(url1, url2);
  }
  
  protected String toExternalForm(URL url)
  {
    return realHandlerService.toExternalForm(url);
  }
  
  public void setURL(URL u, String protocol, String host, int port, String authority, String userInfo, String file, String query, String ref)
  {
    super.setURL(u, protocol, host, port, authority, userInfo, file, query, ref);
  }
  
  public void setURL(URL url, String protocol, String host, int port, String file, String ref)
  {
    super.setURL(url, protocol, host, port, null, null, file, null, ref);
  }
  
  public ServiceReference<URLStreamHandlerService> addingService(ServiceReference<URLStreamHandlerService> reference)
  {
    Object prop = reference.getProperty("url.handler.protocol");
    if (!(prop instanceof String[])) {
      return null;
    }
    String[] protocols = (String[])prop;
    for (int i = 0; i < protocols.length; i++) {
      if (protocols[i].equals(protocol))
      {
        int newServiceRanking = getRank(reference);
        if ((newServiceRanking > ranking) || (urlStreamServiceReference == null)) {
          setNewHandler(reference, newServiceRanking);
        }
        return reference;
      }
    }
    return null;
  }
  
  public void modifiedService(ServiceReference<URLStreamHandlerService> reference, ServiceReference<URLStreamHandlerService> service)
  {
    int newRank = getRank(reference);
    if (reference == urlStreamServiceReference)
    {
      if (newRank < ranking)
      {
        ServiceReference<URLStreamHandlerService> newReference = urlStreamHandlerServiceTracker.getServiceReference();
        if ((newReference != urlStreamServiceReference) && (newReference != null)) {
          setNewHandler(newReference, ((Integer)newReference.getProperty("service.ranking")).intValue());
        }
      }
    }
    else if (newRank > ranking) {
      setNewHandler(reference, newRank);
    }
  }
  
  public void removedService(ServiceReference<URLStreamHandlerService> reference, ServiceReference<URLStreamHandlerService> service)
  {
    if (reference != urlStreamServiceReference) {
      return;
    }
    ServiceReference<URLStreamHandlerService> newReference = urlStreamHandlerServiceTracker.getServiceReference();
    
    setNewHandler(newReference, getRank(newReference));
  }
  
  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;
  }
}

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

import java.net.URL;

public class URLStreamHandlerSetter
  implements org.osgi.service.url.URLStreamHandlerSetter
{
  protected URLStreamHandlerProxy handlerProxy;
  
  public URLStreamHandlerSetter(URLStreamHandlerProxy handler)
  {
    handlerProxy = handler;
  }
  
  /**
   * @deprecated
   */
  public void setURL(URL url, String protocol, String host, int port, String file, String ref)
  {
    handlerProxy.setURL(url, protocol, host, port, file, ref);
  }
  
  public void setURL(URL url, String protocol, String host, int port, String authority, String userInfo, String path, String query, String ref)
  {
    handlerProxy.setURL(url, protocol, host, port, authority, userInfo, path, query, ref);
  }
}

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

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
import org.eclipse.osgi.framework.internal.core.AbstractBundle;
import org.eclipse.osgi.framework.internal.core.BundleResourceHandler;

public class Handler
  extends BundleResourceHandler
{
  public Handler() {}
  
  public Handler(BundleEntry bundleEntry, BaseAdaptor adaptor)
  {
    super(bundleEntry, adaptor);
  }
  
  protected BundleEntry findBundleEntry(URL url, AbstractBundle bundle)
    throws IOException
  {
    BaseData bundleData = (BaseData)bundle.getBundleData();
    BundleEntry entry = bundleData.getBundleFile().getEntry(url.getPath());
    if (entry == null) {
      throw new FileNotFoundException(url.getPath());
    }
    return entry;
  }
}

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

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
import org.eclipse.osgi.framework.internal.core.AbstractBundle;
import org.eclipse.osgi.framework.internal.core.BundleResourceHandler;

public class Handler
  extends BundleResourceHandler
{
  public Handler() {}
  
  public Handler(BundleEntry bundleEntry, BaseAdaptor adaptor)
  {
    super(bundleEntry, adaptor);
  }
  
  protected BundleEntry findBundleEntry(URL url, AbstractBundle bundle)
    throws IOException
  {
    BaseClassLoader classloader = getBundleClassLoader(bundle);
    if (classloader == null) {
      throw new FileNotFoundException(url.getPath());
    }
    ClasspathManager cpManager = classloader.getClasspathManager();
    BundleEntry entry = cpManager.findLocalEntry(url.getPath(), url.getPort());
    if (entry == null) {
      entry = cpManager.findLocalEntry(url.getPath());
    }
    if (entry == null) {
      throw new FileNotFoundException(url.getPath());
    }
    return entry;
  }
}

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

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;

public class Handler
  extends URLStreamHandler
{
  protected URLConnection openConnection(URL url)
    throws IOException
  {
    return new ReferenceURLConnection(url);
  }
  
  protected void parseURL(URL url, String str, int start, int end)
  {
    if (end < start) {
      return;
    }
    String reference = start < end ? str.substring(start, end) : url.getPath();
    
    setURL(url, url.getProtocol(), null, -1, null, null, reference, null, null);
  }
}

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

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.eclipse.osgi.framework.adaptor.FilePath;
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
import org.eclipse.osgi.framework.internal.core.ReferenceInputStream;

public class ReferenceURLConnection
  extends URLConnection
{
  protected URL reference;
  
  protected ReferenceURLConnection(URL url)
  {
    super(url);
  }
  
  public synchronized void connect()
    throws IOException
  {
    if (!connected)
    {
      String path = url.getPath().substring(5);
      File file = new File(path);
      if (!file.isAbsolute())
      {
        String installPath = getInstallPath();
        if (installPath != null) {
          file = makeAbsolute(installPath, file);
        }
      }
      if ((!file.exists()) && (path.indexOf('%') >= 0))
      {
        String decodePath = FrameworkProperties.decode(file.getAbsolutePath());
        File f = new File(decodePath);
        if (f.exists()) {
          file = f;
        }
      }
      URL ref = file.toURL();
      checkRead(file);
      
      reference = ref;
    }
  }
  
  private void checkRead(File file)
    throws IOException
  {
    if (!file.exists()) {
      throw new FileNotFoundException(file.toString());
    }
    if (file.isFile())
    {
      InputStream is = new FileInputStream(file);
      is.close();
    }
    else if (file.isDirectory())
    {
      File[] files = file.listFiles();
      if (files == null) {
        throw new FileNotFoundException(file.toString() 
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