org.eclipse.ecf.provider.filetransfer_3.2.0.v20120610-1946

16:43:13.990 INFO  jd.cli.Main - Decompiling org.eclipse.ecf.provider.filetransfer_3.2.0.v20120610-1946.jar
package org.eclipse.ecf.internal.provider.filetransfer;

import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionDelta;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;

class Activator$1
  implements IRegistryChangeListener
{
  final Activator this$0;
  
  Activator$1(Activator paramActivator)
  {
    this$0 = paramActivator;
  }
  
  public void registryChanged(IRegistryChangeEvent event)
  {
    IExtensionDelta[] retrieveDelta = event.getExtensionDeltas("org.eclipse.ecf.provider.filetransfer", "retrieveFileTransferProtocolFactory");
    for (int i = 0; i < retrieveDelta.length; i++) {
      switch (retrieveDelta[i].getKind())
      {
      case 1: 
        this$0.addRetrieveExtensions(retrieveDelta[i].getExtension().getConfigurationElements());
        break;
      case 2: 
        this$0.removeRetrieveExtensions(retrieveDelta[i].getExtension().getConfigurationElements());
      }
    }
    IExtensionDelta[] sendDelta = event.getExtensionDeltas("org.eclipse.ecf.provider.filetransfer", "sendFileTransferProtocolFactory");
    for (int i = 0; i < sendDelta.length; i++) {
      switch (sendDelta[i].getKind())
      {
      case 1: 
        this$0.addSendExtensions(sendDelta[i].getExtension().getConfigurationElements());
        break;
      case 2: 
        this$0.removeSendExtensions(sendDelta[i].getExtension().getConfigurationElements());
      }
    }
    IExtensionDelta[] browseDelta = event.getExtensionDeltas("org.eclipse.ecf.provider.filetransfer", "browseFileTransferProtocolFactory");
    for (int i = 0; i < browseDelta.length; i++) {
      switch (browseDelta[i].getKind())
      {
      case 1: 
        this$0.addBrowseExtensions(browseDelta[i].getExtension().getConfigurationElements());
        break;
      case 2: 
        this$0.removeBrowseExtensions(browseDelta[i].getExtension().getConfigurationElements());
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ecf.internal.provider.filetransfer.Activator.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ecf.internal.provider.filetransfer;

import org.eclipse.ecf.filetransfer.service.IRetrieveFileTransfer;
import org.eclipse.ecf.filetransfer.service.IRetrieveFileTransferFactory;
import org.eclipse.ecf.provider.filetransfer.retrieve.MultiProtocolRetrieveAdapter;

class Activator$2
  implements IRetrieveFileTransferFactory
{
  final Activator this$0;
  
  Activator$2(Activator paramActivator)
  {
    this$0 = paramActivator;
  }
  
  public IRetrieveFileTransfer newInstance()
  {
    return new MultiProtocolRetrieveAdapter();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ecf.internal.provider.filetransfer.Activator.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ecf.internal.provider.filetransfer;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import org.eclipse.osgi.util.NLS;
import org.osgi.service.url.AbstractURLStreamHandlerService;

class Activator$DummyURLStreamHandlerService
  extends AbstractURLStreamHandlerService
{
  final Activator this$0;
  
  Activator$DummyURLStreamHandlerService(Activator paramActivator)
  {
    this$0 = paramActivator;
  }
  
  public URLConnection openConnection(URL u)
    throws IOException
  {
    throw new IOException(NLS.bind("URLConnection cannot be created for {0}", u.toExternalForm()));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ecf.internal.provider.filetransfer.Activator.DummyURLStreamHandlerService
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ecf.internal.provider.filetransfer;

class Activator$ProtocolFactory
  implements Comparable
{
  Object factory;
  int priority = 0;
  String id;
  
  public Activator$ProtocolFactory(Object factory, int priority, String id)
  {
    this.factory = factory;
    this.priority = priority;
    this.id = id;
  }
  
  public Object getFactory()
  {
    return factory;
  }
  
  public String getID()
  {
    return id;
  }
  
  public int getPriority()
  {
    return priority;
  }
  
  public int compareTo(Object another)
  {
    if (!(another instanceof ProtocolFactory)) {
      return -1;
    }
    ProtocolFactory other = (ProtocolFactory)another;
    if (priority == priority) {
      return 0;
    }
    return priority < priority ? -1 : 1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ecf.internal.provider.filetransfer.Activator.ProtocolFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ecf.internal.provider.filetransfer;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionDelta;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.core.util.LogHelper;
import org.eclipse.ecf.core.util.PlatformHelper;
import org.eclipse.ecf.filetransfer.service.IRemoteFileSystemBrowser;
import org.eclipse.ecf.filetransfer.service.IRemoteFileSystemBrowserFactory;
import org.eclipse.ecf.filetransfer.service.IRetrieveFileTransfer;
import org.eclipse.ecf.filetransfer.service.IRetrieveFileTransferFactory;
import org.eclipse.ecf.filetransfer.service.ISendFileTransfer;
import org.eclipse.ecf.filetransfer.service.ISendFileTransferFactory;
import org.eclipse.ecf.provider.filetransfer.IFileTransferProtocolToFactoryMapper;
import org.eclipse.ecf.provider.filetransfer.retrieve.MultiProtocolRetrieveAdapter;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogService;
import org.osgi.service.url.AbstractURLStreamHandlerService;
import org.osgi.service.url.URLStreamHandlerService;
import org.osgi.util.tracker.ServiceTracker;

public class Activator
  implements BundleActivator, IFileTransferProtocolToFactoryMapper
{
  public static final String PLUGIN_EXCLUDED_SYS_PROP_NAME = "org.eclipse.ecf.provider.filetransfer.excludeContributors";
  private static final String CLASS_ATTR = "class";
  private static final String PRIORITY_ATTR = "priority";
  private static final int DEFAULT_PRIORITY = 100;
  private static final String PROTOCOL_ATTR = "protocol";
  private static final String URI_ATTR = "uri";
  private static final String[] jvmSchemes = { Messages.FileTransferNamespace_Http_Protocol, Messages.FileTransferNamespace_Ftp_Protocol, Messages.FileTransferNamespace_File_Protocol, Messages.FileTransferNamespace_Jar_Protocol, Messages.FileTransferNamespace_Https_Protocol, Messages.FileTransferNamespace_Mailto_Protocol, Messages.FileTransferNamespace_Gopher_Protocol };
  private static final String URL_HANDLER_PROTOCOL_NAME = "url.handler.protocol";
  private static final String URLSTREAM_HANDLER_SERVICE_NAME = "org.osgi.service.url.URLStreamHandlerService";
  public static final String PLUGIN_ID = "org.eclipse.ecf.provider.filetransfer";
  private static final String RETRIEVE_FILETRANSFER_PROTOCOL_FACTORY_EPOINT_NAME = "retrieveFileTransferProtocolFactory";
  private static final String RETRIEVE_FILETRANSFER_PROTOCOL_FACTORY_EPOINT = "org.eclipse.ecf.provider.filetransfer.retrieveFileTransferProtocolFactory";
  private static final String SEND_FILETRANSFER_PROTOCOL_FACTORY_EPOINT_NAME = "sendFileTransferProtocolFactory";
  private static final String SEND_FILETRANSFER_PROTOCOL_FACTORY_EPOINT = "org.eclipse.ecf.provider.filetransfer.sendFileTransferProtocolFactory";
  private static final String BROWSE_FILETRANSFER_PROTOCOL_FACTORY_EPOINT_NAME = "browseFileTransferProtocolFactory";
  private static final String BROWSE_FILETRANSFER_PROTOCOL_FACTORY_EPOINT = "org.eclipse.ecf.provider.filetransfer.browseFileTransferProtocolFactory";
  private static Activator plugin;
  private BundleContext context = null;
  private ServiceRegistration fileTransferServiceRegistration;
  private ServiceTracker logServiceTracker = null;
  private ServiceTracker extensionRegistryTracker = null;
  private Map retrieveFileTransferProtocolMap;
  private Map sendFileTransferProtocolMap;
  private Map browseFileTransferProtocolMap;
  private ServiceTracker adapterManagerTracker = null;
  private ServiceTracker proxyServiceTracker = null;
  private IURLConnectionModifier urlConnectionModifier = null;
  private String[] excludedPlugins = null;
  private ServiceRegistration protocolMapperRegistration;
  private IRegistryChangeListener registryChangeListener = new IRegistryChangeListener()
  {
    public void registryChanged(IRegistryChangeEvent event)
    {
      IExtensionDelta[] retrieveDelta = event.getExtensionDeltas("org.eclipse.ecf.provider.filetransfer", "retrieveFileTransferProtocolFactory");
      for (int i = 0; i < retrieveDelta.length; i++) {
        switch (retrieveDelta[i].getKind())
        {
        case 1: 
          addRetrieveExtensions(retrieveDelta[i].getExtension().getConfigurationElements());
          break;
        case 2: 
          removeRetrieveExtensions(retrieveDelta[i].getExtension().getConfigurationElements());
        }
      }
      IExtensionDelta[] sendDelta = event.getExtensionDeltas("org.eclipse.ecf.provider.filetransfer", "sendFileTransferProtocolFactory");
      for (int i = 0; i < sendDelta.length; i++) {
        switch (sendDelta[i].getKind())
        {
        case 1: 
          addSendExtensions(sendDelta[i].getExtension().getConfigurationElements());
          break;
        case 2: 
          removeSendExtensions(sendDelta[i].getExtension().getConfigurationElements());
        }
      }
      IExtensionDelta[] browseDelta = event.getExtensionDeltas("org.eclipse.ecf.provider.filetransfer", "browseFileTransferProtocolFactory");
      for (int i = 0; i < browseDelta.length; i++) {
        switch (browseDelta[i].getKind())
        {
        case 1: 
          addBrowseExtensions(browseDelta[i].getExtension().getConfigurationElements());
          break;
        case 2: 
          removeBrowseExtensions(browseDelta[i].getExtension().getConfigurationElements());
        }
      }
    }
  };
  
  private String[] parseExcludedPlugins()
  {
    String prop = System.getProperty("org.eclipse.ecf.provider.filetransfer.excludeContributors");
    if (prop == null) {
      return new String[0];
    }
    StringTokenizer tok = new StringTokenizer(prop, ",");
    int count = tok.countTokens();
    String[] results = new String[count];
    for (int i = 0; i < count; i++) {
      results[i] = tok.nextToken();
    }
    return results;
  }
  
  protected LogService getLogService()
  {
    synchronized (this)
    {
      if (context == null) {
        return null;
      }
      if (logServiceTracker == null)
      {
        logServiceTracker = new ServiceTracker(context, LogService.class.getName(), null);
        logServiceTracker.open();
      }
      return (LogService)logServiceTracker.getService();
    }
  }
  
  public IProxyService getProxyService()
  {
    try
    {
      if (proxyServiceTracker == null)
      {
        proxyServiceTracker = new ServiceTracker(context, IProxyService.class.getName(), null);
        proxyServiceTracker.open();
      }
      return (IProxyService)proxyServiceTracker.getService();
    }
    catch (Exception e)
    {
      logNoProxyWarning(e);
    }
    catch (NoClassDefFoundError e)
    {
      logNoProxyWarning(e);
    }
    return null;
  }
  
  public static void logNoProxyWarning(Throwable e)
  {
    Activator a = getDefault();
    if (a != null) {
      a.log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 4, "Warning: Platform proxy API not available", e));
    }
  }
  
  public void log(IStatus status)
  {
    if (context == null) {
      return;
    }
    LogService logService = getLogService();
    if (logService != null) {
      logService.log(LogHelper.getLogCode(status), LogHelper.getLogMessage(status), status.getException());
    }
  }
  
  public Bundle getBundle()
  {
    if (context == null) {
      return null;
    }
    return context.getBundle();
  }
  
  public void start(BundleContext ctxt)
    throws Exception
  {
    plugin = this;
    context = ctxt;
    retrieveFileTransferProtocolMap = new HashMap(3);
    sendFileTransferProtocolMap = new HashMap(3);
    browseFileTransferProtocolMap = new HashMap(3);
    try
    {
      Class urlConnectionModifierClass = Class.forName("org.eclipse.ecf.internal.provider.filetransfer.ssl.ECFURLConnectionModifier");
      urlConnectionModifier = ((IURLConnectionModifier)urlConnectionModifierClass.newInstance());
      urlConnectionModifier.init(ctxt);
    }
    catch (ClassNotFoundException localClassNotFoundException) {}catch (Throwable t)
    {
      log(new Status(4, getDefault().getBundle().getSymbolicName(), "Unexpected Error in Activator.start", t));
    }
    fileTransferServiceRegistration = ctxt.registerService(IRetrieveFileTransferFactory.class.getName(), new IRetrieveFileTransferFactory()
    {
      public IRetrieveFileTransfer newInstance()
      {
        return new MultiProtocolRetrieveAdapter();
      }
    }, null);
    extensionRegistryTracker = new ServiceTracker(ctxt, IExtensionRegistry.class.getName(), null);
    extensionRegistryTracker.open();
    IExtensionRegistry registry = getExtensionRegistry();
    if (registry != null) {
      registry.addRegistryChangeListener(registryChangeListener);
    }
    loadProtocolHandlers();
    
    protocolMapperRegistration = context.registerService(IFileTransferProtocolToFactoryMapper.class.getName(), this, null);
  }
  
  public boolean reinitialize()
  {
    try
    {
      loadProtocolHandlers();
      return true;
    }
    catch (Exception e) {}
    return false;
  }
  
  public void stop(BundleContext ctxt)
    throws Exception
  {
    IExtensionRegistry registry = getExtensionRegistry();
    if (registry != null) {
      registry.removeRegistryChangeListener(registryChangeListener);
    }
    if (urlConnectionModifier != null)
    {
      urlConnectionModifier.dispose();
      urlConnectionModifier = null;
    }
    if (extensionRegistryTracker != null)
    {
      extensionRegistryTracker.close();
      extensionRegistryTracker = null;
    }
    if (fileTransferServiceRegistration != null)
    {
      fileTransferServiceRegistration.unregister();
      fileTransferServiceRegistration = null;
    }
    if (adapterManagerTracker != null)
    {
      adapterManagerTracker.close();
      adapterManagerTracker = null;
    }
    if (proxyServiceTracker != null)
    {
      proxyServiceTracker.close();
      proxyServiceTracker = null;
    }
    if (retrieveFileTransferProtocolMap != null)
    {
      retrieveFileTransferProtocolMap.clear();
      retrieveFileTransferProtocolMap = null;
    }
    if (sendFileTransferProtocolMap != null)
    {
      sendFileTransferProtocolMap.clear();
      sendFileTransferProtocolMap = null;
    }
    if (browseFileTransferProtocolMap != null)
    {
      browseFileTransferProtocolMap.clear();
      browseFileTransferProtocolMap = null;
    }
    if (protocolMapperRegistration != null)
    {
      protocolMapperRegistration.unregister();
      protocolMapperRegistration = null;
    }
    synchronized (this)
    {
      context = null;
    }
    plugin = null;
  }
  
  public static synchronized Activator getDefault()
  {
    if (plugin == null) {
      plugin = new Activator();
    }
    return plugin;
  }
  
  public String[] getPlatformSupportedSchemes()
  {
    ServiceTracker handlers = new ServiceTracker(context, "org.osgi.service.url.URLStreamHandlerService", null);
    handlers.open();
    ServiceReference[] refs = handlers.getServiceReferences();
    Set protocols = new HashSet();
    if (refs != null) {
      for (int i = 0; i < refs.length; i++)
      {
        Object protocol = refs[i].getProperty("url.handler.protocol");
        if ((protocol instanceof String))
        {
          protocols.add(protocol);
        }
        else if ((protocol instanceof String[]))
        {
          String[] ps = (String[])protocol;
          for (int j = 0; j < ps.length; j++) {
            protocols.add(ps[j]);
          }
        }
      }
    }
    handlers.close();
    for (int i = 0; i < jvmSchemes.length; i++) {
      protocols.add(jvmSchemes[i]);
    }
    return (String[])protocols.toArray(new String[0]);
  }
  
  public IExtensionRegistry getExtensionRegistry()
  {
    if (extensionRegistryTracker == null)
    {
      extensionRegistryTracker = new ServiceTracker(context, IExtensionRegistry.class.getName(), null);
      extensionRegistryTracker.open();
    }
    return (IExtensionRegistry)extensionRegistryTracker.getService();
  }
  
  static class ProtocolFactory
    implements Comparable
  {
    Object factory;
    int priority = 0;
    String id;
    
    public ProtocolFactory(Object factory, int priority, String id)
    {
      this.factory = factory;
      this.priority = priority;
      this.id = id;
    }
    
    public Object getFactory()
    {
      return factory;
    }
    
    public String getID()
    {
      return id;
    }
    
    public int getPriority()
    {
      return priority;
    }
    
    public int compareTo(Object another)
    {
      if (!(another instanceof ProtocolFactory)) {
        return -1;
      }
      ProtocolFactory other = (ProtocolFactory)another;
      if (priority == priority) {
        return 0;
      }
      return priority < priority ? -1 : 1;
    }
  }
  
  private int getPriority(IConfigurationElement configElement, String warning, String protocol)
  {
    String priorityString = configElement.getAttribute("priority");
    int priority = 100;
    if (priorityString != null) {
      try
      {
        priority = new Integer(priorityString).intValue();
        
        priority = priority < 0 ? 0 : priority;
      }
      catch (NumberFormatException e)
      {
        getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, NLS.bind("{0} for {1} from {2} has invalid priority {3}. Priority will be set to {4}", new Object[] { warning, protocol, configElement.getDeclaringExtension().getContributor().getName(), priorityString, String.valueOf(100) }), null));
      }
    }
    return priority;
  }
  
  boolean pluginExcluded(String pluginId)
  {
    if (excludedPlugins == null) {
      excludedPlugins = parseExcludedPlugins();
    }
    List l = Arrays.asList(excludedPlugins);
    return l.contains(pluginId);
  }
  
  void addRetrieveExtensions(IConfigurationElement[] configElements)
  {
    for (int i = 0; i < configElements.length; i++)
    {
      String protocol = configElements[i].getAttribute("protocol");
      if ((protocol == null) || ("".equals(protocol))) {
        return;
      }
      String uriStr = configElements[i].getAttribute("uri");
      boolean uri = uriStr == null ? false : Boolean.valueOf(uriStr).booleanValue();
      String CONTRIBUTION_WARNING = "File retrieve contribution";
      try
      {
        String pluginId = configElements[i].getDeclaringExtension().getContributor().getName();
        if (!pluginExcluded(pluginId))
        {
          IRetrieveFileTransferFactory retrieveFactory = (IRetrieveFileTransferFactory)configElements[i].createExecutableExtension("class");
          
          int priority = getPriority(configElements[i], CONTRIBUTION_WARNING, protocol);
          String contributorName = configElements[i].getDeclaringExtension().getContributor().getName();
          
          setRetrieveFileTransferFactory(protocol, contributorName, retrieveFactory, priority, uri);
        }
        else
        {
          getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, "Plugin " + pluginId + " excluded from contributing retrieve factory", null));
        }
      }
      catch (CoreException e)
      {
        getDefault().log(new Status(4, "org.eclipse.ecf.provider.filetransfer", 4, NLS.bind("Error loading from {0} extension point", "org.eclipse.ecf.provider.filetransfer.retrieveFileTransferProtocolFactory"), e));
      }
    }
  }
  
  void removeRetrieveExtensions(IConfigurationElement[] configElements)
  {
    for (int i = 0; i < configElements.length; i++)
    {
      String protocol = configElements[i].getAttribute("protocol");
      if ((protocol == null) || ("".equals(protocol))) {
        return;
      }
      String id = getRetrieveFileTransferFactoryId(protocol);
      if (id != null) {
        removeRetrieveFileTransferFactory(id);
      }
    }
  }
  
  void addSendExtensions(IConfigurationElement[] configElements)
  {
    for (int i = 0; i < configElements.length; i++)
    {
      String protocol = configElements[i].getAttribute("protocol");
      if ((protocol == null) || ("".equals(protocol))) {
        return;
      }
      String uriStr = configElements[i].getAttribute("uri");
      boolean uri = uriStr == null ? false : Boolean.valueOf(uriStr).booleanValue();
      String CONTRIBUTION_WARNING = "File send contribution";
      try
      {
        String pluginId = configElements[i].getDeclaringExtension().getContributor().getName();
        if (!pluginExcluded(pluginId))
        {
          ISendFileTransferFactory clazz = (ISendFileTransferFactory)configElements[i].createExecutableExtension("class");
          
          int priority = getPriority(configElements[i], CONTRIBUTION_WARNING, protocol);
          setSendFileTransferFactory(protocol, pluginId, clazz, priority, uri);
        }
        else
        {
          getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, "Plugin " + pluginId + " excluded from contributing send factory", null));
        }
      }
      catch (CoreException e)
      {
        getDefault().log(new Status(4, "org.eclipse.ecf.provider.filetransfer", 4, NLS.bind("Error loading from {0} extension point", "org.eclipse.ecf.provider.filetransfer.sendFileTransferProtocolFactory"), e));
      }
    }
  }
  
  void removeSendExtensions(IConfigurationElement[] configElements)
  {
    for (int i = 0; i < configElements.length; i++)
    {
      String protocol = configElements[i].getAttribute("protocol");
      if ((protocol == null) || ("".equals(protocol))) {
        return;
      }
      String id = getSendFileTransferFactoryId(protocol);
      if (id != null) {
        removeSendFileTransferFactory(id);
      }
    }
  }
  
  void addBrowseExtensions(IConfigurationElement[] configElements)
  {
    for (int i = 0; i < configElements.length; i++)
    {
      String protocol = configElements[i].getAttribute("protocol");
      if ((protocol == null) || ("".equals(protocol))) {
        return;
      }
      String uriStr = configElements[i].getAttribute("uri");
      boolean uri = uriStr == null ? false : Boolean.valueOf(uriStr).booleanValue();
      String CONTRIBUTION_WARNING = "File browse contribution";
      try
      {
        String pluginId = configElements[i].getDeclaringExtension().getContributor().getName();
        if (!pluginExcluded(pluginId))
        {
          IRemoteFileSystemBrowserFactory clazz = (IRemoteFileSystemBrowserFactory)configElements[i].createExecutableExtension("class");
          
          int priority = getPriority(configElements[i], CONTRIBUTION_WARNING, protocol);
          setBrowseFileTransferFactory(protocol, pluginId, clazz, priority, uri);
        }
        else
        {
          getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, "Plugin " + pluginId + " excluded from contributing browse factory", null));
        }
      }
      catch (CoreException e)
      {
        getDefault().log(new Status(4, "org.eclipse.ecf.provider.filetransfer", 4, NLS.bind("Error loading from {0} extension point", "org.eclipse.ecf.provider.filetransfer.browseFileTransferProtocolFactory"), e));
      }
    }
  }
  
  void removeBrowseExtensions(IConfigurationElement[] configElements)
  {
    for (int i = 0; i < configElements.length; i++)
    {
      String protocol = configElements[i].getAttribute("protocol");
      if ((protocol == null) || ("".equals(protocol))) {
        return;
      }
      String id = getBrowseFileTransferFactoryId(protocol);
      if (id != null) {
        removeBrowseFileTransferFactory(id);
      }
    }
  }
  
  private void loadProtocolHandlers()
  {
    IExtensionRegistry reg = getExtensionRegistry();
    if (reg != null)
    {
      IExtensionPoint retrieveExtensionPoint = reg.getExtensionPoint("org.eclipse.ecf.provider.filetransfer.retrieveFileTransferProtocolFactory");
      if (retrieveExtensionPoint != null) {
        addRetrieveExtensions(retrieveExtensionPoint.getConfigurationElements());
      }
      IExtensionPoint sendExtensionPoint = reg.getExtensionPoint("org.eclipse.ecf.provider.filetransfer.sendFileTransferProtocolFactory");
      if (sendExtensionPoint != null) {
        addSendExtensions(sendExtensionPoint.getConfigurationElements());
      }
      IExtensionPoint browseExtensionPoint = reg.getExtensionPoint("org.eclipse.ecf.provider.filetransfer.browseFileTransferProtocolFactory");
      if (browseExtensionPoint != null) {
        addBrowseExtensions(browseExtensionPoint.getConfigurationElements());
      }
    }
  }
  
  private boolean isSchemeRegistered(String protocol, String[] schemes)
  {
    for (int i = 0; i < schemes.length; i++) {
      if (protocol.equals(schemes[i])) {
        return true;
      }
    }
    return false;
  }
  
  class DummyURLStreamHandlerService
    extends AbstractURLStreamHandlerService
  {
    DummyURLStreamHandlerService() {}
    
    public URLConnection openConnection(URL u)
      throws IOException
    {
      throw new IOException(NLS.bind("URLConnection cannot be created for {0}", u.toExternalForm()));
    }
  }
  
  private final DummyURLStreamHandlerService dummyService = new DummyURLStreamHandlerService();
  
  private void registerScheme(String protocol)
  {
    Hashtable properties = new Hashtable();
    properties.put("url.handler.protocol", new String[] { protocol });
    context.registerService(URLStreamHandlerService.class.getName(), dummyService, properties);
  }
  
  public IRetrieveFileTransfer getFileTransfer(String protocol)
  {
    ProtocolFactory protocolFactory = null;
    synchronized (retrieveFileTransferProtocolMap)
    {
      protocolFactory = (ProtocolFactory)retrieveFileTransferProtocolMap.get(protocol);
    }
    if (protocolFactory == null) {
      return null;
    }
    IRetrieveFileTransferFactory factory = (IRetrieveFileTransferFactory)protocolFactory.getFactory();
    if (factory != null) {
      return factory.newInstance();
    }
    return null;
  }
  
  public ISendFileTransfer getSendFileTransfer(String protocol)
  {
    ProtocolFactory protocolFactory = null;
    synchronized (sendFileTransferProtocolMap)
    {
      protocolFactory = (ProtocolFactory)sendFileTransferProtocolMap.get(protocol);
    }
    if (protocolFactory == null) {
      return null;
    }
    ISendFileTransferFactory factory = (ISendFileTransferFactory)protocolFactory.getFactory();
    if (factory != null) {
      return factory.newInstance();
    }
    return null;
  }
  
  public IRemoteFileSystemBrowser getBrowseFileTransfer(String protocol)
  {
    ProtocolFactory protocolFactory = null;
    synchronized (browseFileTransferProtocolMap)
    {
      protocolFactory = (ProtocolFactory)browseFileTransferProtocolMap.get(protocol);
    }
    if (protocolFactory == null) {
      return null;
    }
    IRemoteFileSystemBrowserFactory factory = (IRemoteFileSystemBrowserFactory)protocolFactory.getFactory();
    if (factory != null) {
      return factory.newInstance();
    }
    return null;
  }
  
  public IAdapterManager getAdapterManager()
  {
    if (adapterManagerTracker == null)
    {
      adapterManagerTracker = new ServiceTracker(context, IAdapterManager.class.getName(), null);
      adapterManagerTracker.open();
    }
    IAdapterManager adapterManager = (IAdapterManager)adapterManagerTracker.getService();
    if (adapterManager == null) {
      adapterManager = PlatformHelper.getPlatformAdapterManager();
    }
    return adapterManager;
  }
  
  public IURLConnectionModifier getURLConnectionModifier()
  {
    return urlConnectionModifier;
  }
  
  public boolean setRetrieveFileTransferFactory(String protocol, String id, IRetrieveFileTransferFactory factory, int priority)
  {
    return setRetrieveFileTransferFactory(protocol, id, factory, priority, false);
  }
  
  public boolean setRetrieveFileTransferFactory(String protocol, String id, IRetrieveFileTransferFactory factory, int priority, boolean uri)
  {
    if ((protocol == null) || ("".equals(protocol))) {
      return false;
    }
    if (id == null) {
      return false;
    }
    if (factory == null) {
      return false;
    }
    if (!pluginExcluded(id))
    {
      ProtocolFactory newProtocolFactory = new ProtocolFactory(factory, priority, id);
      synchronized (retrieveFileTransferProtocolMap)
      {
        ProtocolFactory oldProtocolFactory = (ProtocolFactory)retrieveFileTransferProtocolMap.get(protocol);
        if (oldProtocolFactory != null)
        {
          String CONTRIBUTION_WARNING = "File retrieve contribution";
          int result = oldProtocolFactory.compareTo(newProtocolFactory);
          if (result < 0)
          {
            getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, NLS.bind("{0} for protocol {1} from {2} will be ignored.  Existing protocol factory has higher priority.", new Object[] { CONTRIBUTION_WARNING, protocol, id }), null));
            return false;
          }
          if (result == 0) {
            getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, NLS.bind("{0} for protocol {1} from {2} will be used in preference to existing handler.  Both have same priority={3}.", new Object[] { CONTRIBUTION_WARNING, protocol, id, new Integer(priority) }), null));
          } else if (result > 0) {
            getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, NLS.bind("{0} for protocol {1} from {2} will be used in preference to existing handler.  New handler has higher priority={3}<{4}.", new Object[] { CONTRIBUTION_WARNING, protocol, id, new Integer(priority), new Integer(priority) }), null));
          }
        }
        if (!uri)
        {
          String[] existingSchemes = getPlatformSupportedSchemes();
          if (!isSchemeRegistered(protocol, existingSchemes)) {
            registerScheme(protocol);
          }
        }
        retrieveFileTransferProtocolMap.put(protocol, newProtocolFactory);
        return true;
      }
    }
    return false;
  }
  
  public String getRetrieveFileTransferFactoryId(String protocol)
  {
    if (protocol == null) {
      return null;
    }
    synchronized (retrieveFileTransferProtocolMap)
    {
      ProtocolFactory oldProtocolFactory = (ProtocolFactory)retrieveFileTransferProtocolMap.get(protocol);
      if (oldProtocolFactory == null) {
        return null;
      }
      return oldProtocolFactory.getID();
    }
  }
  
  public int getRetrieveFileTransferPriority(String protocol)
  {
    if (protocol == null) {
      return -1;
    }
    synchronized (retrieveFileTransferProtocolMap)
    {
      ProtocolFactory oldProtocolFactory = (ProtocolFactory)retrieveFileTransferProtocolMap.get(protocol);
      if (oldProtocolFactory == null) {
        return -1;
      }
      return oldProtocolFactory.getPriority();
    }
  }
  
  public boolean removeRetrieveFileTransferFactory(String id)
  {
    if (id == null) {
      return false;
    }
    boolean removed = false;
    synchronized (retrieveFileTransferProtocolMap)
    {
      for (Iterator i = retrieveFileTransferProtocolMap.keySet().iterator(); i.hasNext();)
      {
        ProtocolFactory oldProtocolFactory = (ProtocolFactory)retrieveFileTransferProtocolMap.get(i.next());
        if (oldProtocolFactory != null) {
          if (id.equals(oldProtocolFactory.getID()))
          {
            i.remove();
            removed = true;
          }
        }
      }
      return removed;
    }
  }
  
  public boolean setBrowseFileTransferFactory(String protocol, String id, IRemoteFileSystemBrowserFactory factory, int priority)
  {
    return setBrowseFileTransferFactory(protocol, id, factory, priority, false);
  }
  
  public boolean setBrowseFileTransferFactory(String protocol, String id, IRemoteFileSystemBrowserFactory factory, int priority, boolean uri)
  {
    if ((protocol == null) || ("".equals(protocol))) {
      return false;
    }
    if (id == null) {
      return false;
    }
    if (factory == null) {
      return false;
    }
    if (!pluginExcluded(id))
    {
      ProtocolFactory newProtocolFactory = new ProtocolFactory(factory, priority, id);
      synchronized (browseFileTransferProtocolMap)
      {
        ProtocolFactory oldProtocolFactory = (ProtocolFactory)browseFileTransferProtocolMap.get(protocol);
        if (oldProtocolFactory != null)
        {
          String CONTRIBUTION_WARNING = "File browse contribution";
          int result = oldProtocolFactory.compareTo(newProtocolFactory);
          if (result < 0)
          {
            getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, NLS.bind("{0} for protocol {1} from {2} will be ignored.  Existing protocol factory has higher priority.", new Object[] { CONTRIBUTION_WARNING, protocol, id }), null));
            return false;
          }
          if (result == 0) {
            getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, NLS.bind("{0} for protocol {1} from {2} will be used in preference to existing handler.  Both have same priority={3}.", new Object[] { CONTRIBUTION_WARNING, protocol, id, new Integer(priority) }), null));
          } else if (result > 0) {
            getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, NLS.bind("{0} for protocol {1} from {2} will be used in preference to existing handler.  New handler has higher priority={3}<{4}.", new Object[] { CONTRIBUTION_WARNING, protocol, id, new Integer(priority), new Integer(priority) }), null));
          }
        }
        if (!uri)
        {
          String[] existingSchemes = getPlatformSupportedSchemes();
          if (!isSchemeRegistered(protocol, existingSchemes)) {
            registerScheme(protocol);
          }
        }
        browseFileTransferProtocolMap.put(protocol, newProtocolFactory);
        return true;
      }
    }
    return false;
  }
  
  public String getBrowseFileTransferFactoryId(String protocol)
  {
    if (protocol == null) {
      return null;
    }
    synchronized (browseFileTransferProtocolMap)
    {
      ProtocolFactory oldProtocolFactory = (ProtocolFactory)browseFileTransferProtocolMap.get(protocol);
      if (oldProtocolFactory == null) {
        return null;
      }
      return oldProtocolFactory.getID();
    }
  }
  
  public int getBrowseFileTransferPriority(String protocol)
  {
    if (protocol == null) {
      return -1;
    }
    synchronized (browseFileTransferProtocolMap)
    {
      ProtocolFactory oldProtocolFactory = (ProtocolFactory)browseFileTransferProtocolMap.get(protocol);
      if (oldProtocolFactory == null) {
        return -1;
      }
      return oldProtocolFactory.getPriority();
    }
  }
  
  public boolean removeBrowseFileTransferFactory(String id)
  {
    if (id == null) {
      return false;
    }
    boolean removed = false;
    synchronized (browseFileTransferProtocolMap)
    {
      for (Iterator i = browseFileTransferProtocolMap.keySet().iterator(); i.hasNext();)
      {
        ProtocolFactory oldProtocolFactory = (ProtocolFactory)browseFileTransferProtocolMap.get(i.next());
        if (oldProtocolFactory != null) {
          if (id.equals(oldProtocolFactory.getID()))
          {
            i.remove();
            removed = true;
          }
        }
      }
      return removed;
    }
  }
  
  public boolean setSendFileTransferFactory(String protocol, String id, ISendFileTransferFactory factory, int priority)
  {
    return setSendFileTransferFactory(protocol, id, factory, priority, false);
  }
  
  public boolean setSendFileTransferFactory(String protocol, String id, ISendFileTransferFactory factory, int priority, boolean uri)
  {
    if ((protocol == null) || ("".equals(protocol))) {
      return false;
    }
    if (id == null) {
      return false;
    }
    if (factory == null) {
      return false;
    }
    if (!pluginExcluded(id))
    {
      ProtocolFactory newProtocolFactory = new ProtocolFactory(factory, priority, id);
      synchronized (sendFileTransferProtocolMap)
      {
        ProtocolFactory oldProtocolFactory = (ProtocolFactory)sendFileTransferProtocolMap.get(protocol);
        if (oldProtocolFactory != null)
        {
          String CONTRIBUTION_WARNING = "File send contribution";
          int result = oldProtocolFactory.compareTo(newProtocolFactory);
          if (result < 0)
          {
            getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, NLS.bind("{0} for protocol {1} from {2} will be ignored.  Existing protocol factory has higher priority.", new Object[] { CONTRIBUTION_WARNING, protocol, id }), null));
            return false;
          }
          if (result == 0) {
            getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, NLS.bind("{0} for protocol {1} from {2} will be used in preference to existing handler.  Both have same priority={3}.", new Object[] { CONTRIBUTION_WARNING, protocol, id, new Integer(priority) }), null));
          } else if (result > 0) {
            getDefault().log(new Status(2, "org.eclipse.ecf.provider.filetransfer", 2, NLS.bind("{0} for protocol {1} from {2} will be used in preference to existing handler.  New handler has higher priority={3}<{4}.", new Object[] { CONTRIBUTION_WARNING, protocol, id, new Integer(priority), new Integer(priority) }), null));
          }
        }
        if (!uri)
        {
          String[] existingSchemes = getPlatformSupportedSchemes();
          if (!isSchemeRegistered(protocol, existingSchemes)) {
            registerScheme(protocol);
          }
        }
        sendFileTransferProtocolMap.put(protocol, newProtocolFactory);
        return true;
      }
    }
    return false;
  }
  
  public String getSendFileTransferFactoryId(String protocol)
  {
    if (protocol == null) {
      return null;
    }
    synchronized (sendFileTransferProtocolMap)
    {
      ProtocolFactory oldProtocolFactory = (ProtocolFactory)sendFileTransferProtocolMap.get(protocol);
      if (oldProtocolFactory == null) {
        return null;
      }
      return oldProtocolFactory.getID();
    }
  }
  
  public int getSendFileTransferPriority(String protocol)
  {
    if (protocol == null) {
      return -1;
    }
    synchronized (sendFileTransferProtocolMap)
    {
      ProtocolFactory oldProtocolFactory = (ProtocolFactory)sendFileTransferProtocolMap.get(protocol);
1 2 3 4 5 6

Further reading...

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

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd