org.eclipse.ecf.provider.discovery_2.1.200.v20111230-0120

16:43:08.741 INFO  jd.cli.Main - Decompiling org.eclipse.ecf.provider.discovery_2.1.200.v20111230-0120.jar
package org.eclipse.ecf.internal.provider.discovery;

import java.util.HashSet;
import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.util.Trace;
import org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;

class Activator$1
  implements ServiceFactory
{
  final Activator this$0;
  private final BundleContext val$context;
  
  Activator$1(Activator paramActivator, BundleContext paramBundleContext)
  {
    this$0 = paramActivator;val$context = paramBundleContext;
  }
  
  public Object getService(Bundle bundle, ServiceRegistration registration)
  {
    CompositeDiscoveryContainer cdc = new CompositeDiscoveryContainer(new HashSet());
    try
    {
      cdc.connect(null, null);
    }
    catch (ContainerConnectException e)
    {
      Trace.catching("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/catching", getClass(), "getService(Bundle, ServiceRegistration)", e);
      return null;
    }
    Filter filter = null;
    try
    {
      Class tmp58_55 = Activator.class$2;
      if (tmp58_55 == null)
      {
        tmp58_55;
        try
        {
          tmpTernaryOp = (Activator.class$2 = Class.forName("org.eclipse.ecf.discovery.IDiscoveryAdvertiser"));
        }
        catch (ClassNotFoundException localClassNotFoundException)
        {
          throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
        }
      }
      String filter2 = "(&(objectClass=" + tmp58_55.getName() + ")(!(" + "org.eclipse.ecf.discovery.containerName" + "=" + "ecf.discovery.composite" + ")))";
      filter = val$context.createFilter(filter2);
      val$context.addServiceListener(new Activator.2(this, val$context, cdc), 
      
        filter2);
    }
    catch (InvalidSyntaxException localInvalidSyntaxException) {}
    ServiceTracker tracker = new ServiceTracker(val$context, filter, null);
    tracker.open();
    Object[] services = tracker.getServices();
    tracker.close();
    if (services != null) {
      for (int i = 0; i < services.length; i++)
      {
        Object obj = services[i];
        if (obj != cdc) {
          cdc.addContainer(obj);
        }
      }
    }
    return cdc;
  }
  
  public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
  {
    ((CompositeDiscoveryContainer)service).dispose();
  }
}

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

import org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;

class Activator$2
  implements ServiceListener
{
  final Activator.1 this$1;
  private final BundleContext val$context;
  private final CompositeDiscoveryContainer val$cdc;
  
  Activator$2(Activator.1 param1, BundleContext paramBundleContext, CompositeDiscoveryContainer paramCompositeDiscoveryContainer)
  {
    this$1 = param1;val$context = paramBundleContext;val$cdc = paramCompositeDiscoveryContainer;
  }
  
  public void serviceChanged(ServiceEvent arg0)
  {
    Object anIDS = val$context.getService(arg0.getServiceReference());
    switch (arg0.getType())
    {
    case 1: 
      val$cdc.addContainer(anIDS);
      break;
    case 4: 
      val$cdc.removeContainer(anIDS);
      break;
    }
  }
}

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

import java.util.HashSet;
import java.util.Properties;
import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.util.Trace;
import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
import org.eclipse.ecf.discovery.IDiscoveryLocator;
import org.eclipse.ecf.discovery.service.IDiscoveryService;
import org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;

public class Activator
  implements BundleActivator
{
  private static Activator plugin;
  public static final String PLUGIN_ID = "org.eclipse.ecf.provider.discovery";
  
  public static Activator getDefault()
  {
    return plugin;
  }
  
  public Activator()
  {
    plugin = this;
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    Properties props = new Properties();
    props.put("org.eclipse.ecf.discovery.containerName", "ecf.discovery.composite");
    props.put("service.ranking", new Integer(1000));
    String[] clazzes = { IDiscoveryService.class.getName(), IDiscoveryLocator.class.getName(), IDiscoveryAdvertiser.class.getName() };
    context.registerService(clazzes, new ServiceFactory()
    {
      private final BundleContext val$context;
      
      public Object getService(Bundle bundle, ServiceRegistration registration)
      {
        CompositeDiscoveryContainer cdc = new CompositeDiscoveryContainer(new HashSet());
        try
        {
          cdc.connect(null, null);
        }
        catch (ContainerConnectException e)
        {
          Trace.catching("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/catching", getClass(), "getService(Bundle, ServiceRegistration)", e);
          return null;
        }
        Filter filter = null;
        try
        {
          Class tmp58_55 = Activator.class$2;
          if (tmp58_55 == null)
          {
            tmp58_55;
            try
            {
              tmpTernaryOp = (Activator.class$2 = Class.forName("org.eclipse.ecf.discovery.IDiscoveryAdvertiser"));
            }
            catch (ClassNotFoundException localClassNotFoundException)
            {
              throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
            }
          }
          String filter2 = "(&(objectClass=" + tmp58_55.getName() + ")(!(" + "org.eclipse.ecf.discovery.containerName" + "=" + "ecf.discovery.composite" + ")))";
          filter = val$context.createFilter(filter2);
          val$context.addServiceListener(new Activator.2(this, val$context, cdc), 
          
            filter2);
        }
        catch (InvalidSyntaxException localInvalidSyntaxException) {}
        ServiceTracker tracker = new ServiceTracker(val$context, filter, null);
        tracker.open();
        Object[] services = tracker.getServices();
        tracker.close();
        if (services != null) {
          for (int i = 0; i < services.length; i++)
          {
            Object obj = services[i];
            if (obj != cdc) {
              cdc.addContainer(obj);
            }
          }
        }
        return cdc;
      }
      
      public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
      {
        ((CompositeDiscoveryContainer)service).dispose();
      }
    }, props);
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    plugin = null;
  }
}

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

import java.net.URI;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.discovery.identity.IServiceTypeID;
import org.eclipse.ecf.discovery.identity.ServiceTypeID;

public class CompositeNamespace
  extends Namespace
{
  private static final long serialVersionUID = -4774766051014928510L;
  public static final String NAME = "ecf.namespace.composite";
  
  public ID createInstance(Object[] parameters)
  {
    if ((parameters == null) || (parameters.length < 1) || (parameters.length > 2)) {
      throw new IDCreateException("parameter count must be non null and of length >= 1 and =< 2");
    }
    if ((parameters.length == 2) && ((parameters[0] instanceof String)) && ((parameters[1] instanceof URI))) {
      return new CompositeServiceID(this, new ServiceTypeID(this, (String)parameters[0]), (URI)parameters[1]);
    }
    if ((parameters.length == 2) && ((parameters[0] instanceof IServiceTypeID)) && ((parameters[1] instanceof URI))) {
      return new CompositeServiceID(this, (IServiceTypeID)parameters[0], (URI)parameters[1]);
    }
    if ((parameters.length == 1) && ((parameters[0] instanceof IServiceTypeID)))
    {
      IServiceTypeID iServiceTypeID = (IServiceTypeID)parameters[0];
      return new ServiceTypeID(this, iServiceTypeID.getName());
    }
    throw new IDCreateException("wrong parameters");
  }
  
  public String getScheme()
  {
    return "composite";
  }
}

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

import java.net.URI;
import org.eclipse.ecf.discovery.identity.IServiceTypeID;
import org.eclipse.ecf.discovery.identity.ServiceID;

public class CompositeServiceID
  extends ServiceID
{
  private static final long serialVersionUID = -5296876662431183581L;
  
  public CompositeServiceID(CompositeNamespace compositeNamespace, IServiceTypeID serviceTypeID, URI anURI)
  {
    super(compositeNamespace, serviceTypeID, anURI);
  }
}

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

public abstract interface DiscoveryProviderDebugOptions
{
  public static final String DEBUG = "org.eclipse.ecf.provider.discovery/debug";
  public static final String EXCEPTIONS_CATCHING = "org.eclipse.ecf.provider.discovery/debug/exceptions/catching";
  public static final String EXCEPTIONS_THROWING = "org.eclipse.ecf.provider.discovery/debug/exceptions/throwing";
  public static final String METHODS_ENTERING = "org.eclipse.ecf.provider.discovery/debug/methods/entering";
  public static final String METHODS_EXITING = "org.eclipse.ecf.provider.discovery/debug/methods/exiting";
  public static final String METHODS_TRACING = "org.eclipse.ecf.provider.discovery/debug/methods/tracing";
}

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

import java.util.Collection;
import java.util.Iterator;
import org.eclipse.ecf.core.util.Trace;
import org.eclipse.ecf.discovery.IServiceEvent;
import org.eclipse.ecf.discovery.IServiceInfo;
import org.eclipse.ecf.discovery.IServiceListener;
import org.eclipse.ecf.discovery.identity.IServiceID;

public class CompositeDiscoveryContainer$CompositeContainerServiceListener
  implements IServiceListener
{
  final CompositeDiscoveryContainer this$0;
  
  protected CompositeDiscoveryContainer$CompositeContainerServiceListener(CompositeDiscoveryContainer paramCompositeDiscoveryContainer)
  {
    this$0 = paramCompositeDiscoveryContainer;
  }
  
  public void serviceDiscovered(IServiceEvent event)
  {
    Collection col = CompositeDiscoveryContainer.access$0(this$0, event.getServiceInfo().getServiceID().getServiceTypeID());
    if (!col.isEmpty()) {
      for (Iterator itr = col.iterator(); itr.hasNext();)
      {
        IServiceListener isl = (IServiceListener)itr.next();
        
        isl.serviceDiscovered(new CompositeServiceContainerEvent(event, this$0.getConnectedID()));
        Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "serviceDiscovered", 
          "serviceResolved fired for listener " + 
          isl.toString() + " with event: " + event.toString());
      }
    } else {
      Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "serviceDiscovered", 
        "serviceResolved fired without any listeners present");
    }
  }
  
  public void serviceUndiscovered(IServiceEvent event)
  {
    Collection col = CompositeDiscoveryContainer.access$0(this$0, event.getServiceInfo().getServiceID().getServiceTypeID());
    if (!col.isEmpty()) {
      for (Iterator itr = col.iterator(); itr.hasNext();)
      {
        IServiceListener isl = (IServiceListener)itr.next();
        
        isl.serviceUndiscovered(new CompositeServiceContainerEvent(event, this$0.getConnectedID()));
        Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "serviceUndiscovered", 
          "serviceRemoved fired for listener " + 
          isl.toString() + " with event: " + event.toString());
      }
    } else {
      Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "serviceUndiscovered", 
        "serviceRemoved fired without any listeners present");
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer.CompositeContainerServiceListener
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ecf.provider.discovery;

import java.util.Collection;
import java.util.Iterator;
import org.eclipse.ecf.core.util.Trace;
import org.eclipse.ecf.discovery.IDiscoveryLocator;
import org.eclipse.ecf.discovery.IServiceTypeEvent;
import org.eclipse.ecf.discovery.IServiceTypeListener;
import org.eclipse.ecf.discovery.identity.IServiceTypeID;

public class CompositeDiscoveryContainer$CompositeContainerServiceTypeListener
  implements IServiceTypeListener
{
  final CompositeDiscoveryContainer this$0;
  
  protected CompositeDiscoveryContainer$CompositeContainerServiceTypeListener(CompositeDiscoveryContainer paramCompositeDiscoveryContainer)
  {
    this$0 = paramCompositeDiscoveryContainer;
  }
  
  public synchronized void serviceTypeDiscovered(IServiceTypeEvent event)
  {
    synchronized (CompositeDiscoveryContainer.access$1(this$0))
    {
      for (Iterator itr = CompositeDiscoveryContainer.access$1(this$0).iterator(); itr.hasNext();)
      {
        IServiceTypeListener listener = (IServiceTypeListener)itr.next();
        
        listener.serviceTypeDiscovered(new CompositeServiceTypeContainerEvent(event, this$0.getConnectedID()));
        Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "serviceTypeDiscovered", 
          "serviceTypeDiscovered fired for listener " + 
          listener.toString() + " with event: " + event.toString());
      }
    }
    IServiceTypeID istid = event.getServiceTypeID();
    synchronized (this$0.containers)
    {
      for (Iterator itr = this$0.containers.iterator(); itr.hasNext();)
      {
        IDiscoveryLocator idca = (IDiscoveryLocator)itr.next();
        idca.addServiceListener(istid, this$0.ccsl);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer.CompositeContainerServiceTypeListener
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ecf.provider.discovery;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.events.ContainerConnectedEvent;
import org.eclipse.ecf.core.events.ContainerConnectingEvent;
import org.eclipse.ecf.core.events.ContainerDisconnectedEvent;
import org.eclipse.ecf.core.events.ContainerDisconnectingEvent;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.identity.IIDFactory;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.security.IConnectContext;
import org.eclipse.ecf.core.util.ECFRuntimeException;
import org.eclipse.ecf.core.util.Trace;
import org.eclipse.ecf.discovery.AbstractDiscoveryContainerAdapter;
import org.eclipse.ecf.discovery.DiscoveryContainerConfig;
import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
import org.eclipse.ecf.discovery.IDiscoveryLocator;
import org.eclipse.ecf.discovery.IServiceEvent;
import org.eclipse.ecf.discovery.IServiceInfo;
import org.eclipse.ecf.discovery.IServiceListener;
import org.eclipse.ecf.discovery.IServiceTypeEvent;
import org.eclipse.ecf.discovery.IServiceTypeListener;
import org.eclipse.ecf.discovery.ServiceInfo;
import org.eclipse.ecf.discovery.identity.IServiceID;
import org.eclipse.ecf.discovery.identity.IServiceIDFactory;
import org.eclipse.ecf.discovery.identity.IServiceTypeID;
import org.eclipse.ecf.discovery.identity.ServiceIDFactory;
import org.eclipse.ecf.discovery.service.IDiscoveryService;

public class CompositeDiscoveryContainer
  extends AbstractDiscoveryContainerAdapter
  implements IDiscoveryService
{
  public static final String NAME = "ecf.discovery.composite";
  protected static final String METHODS_CATCHING = "org.eclipse.ecf.provider.discovery/debug/methods/catching";
  protected static final String METHODS_TRACING = "org.eclipse.ecf.provider.discovery/debug/methods/tracing";
  
  protected class CompositeContainerServiceListener
    implements IServiceListener
  {
    protected CompositeContainerServiceListener() {}
    
    public void serviceDiscovered(IServiceEvent event)
    {
      Collection col = getListeners(event.getServiceInfo().getServiceID().getServiceTypeID());
      if (!col.isEmpty()) {
        for (Iterator itr = col.iterator(); itr.hasNext();)
        {
          IServiceListener isl = (IServiceListener)itr.next();
          
          isl.serviceDiscovered(new CompositeServiceContainerEvent(event, getConnectedID()));
          Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "serviceDiscovered", 
            "serviceResolved fired for listener " + 
            isl.toString() + " with event: " + event.toString());
        }
      } else {
        Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "serviceDiscovered", 
          "serviceResolved fired without any listeners present");
      }
    }
    
    public void serviceUndiscovered(IServiceEvent event)
    {
      Collection col = getListeners(event.getServiceInfo().getServiceID().getServiceTypeID());
      if (!col.isEmpty()) {
        for (Iterator itr = col.iterator(); itr.hasNext();)
        {
          IServiceListener isl = (IServiceListener)itr.next();
          
          isl.serviceUndiscovered(new CompositeServiceContainerEvent(event, getConnectedID()));
          Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "serviceUndiscovered", 
            "serviceRemoved fired for listener " + 
            isl.toString() + " with event: " + event.toString());
        }
      } else {
        Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "serviceUndiscovered", 
          "serviceRemoved fired without any listeners present");
      }
    }
  }
  
  protected class CompositeContainerServiceTypeListener
    implements IServiceTypeListener
  {
    protected CompositeContainerServiceTypeListener() {}
    
    public synchronized void serviceTypeDiscovered(IServiceTypeEvent event)
    {
      synchronized (serviceTypeListeners)
      {
        for (Iterator itr = serviceTypeListeners.iterator(); itr.hasNext();)
        {
          IServiceTypeListener listener = (IServiceTypeListener)itr.next();
          
          listener.serviceTypeDiscovered(new CompositeServiceTypeContainerEvent(event, getConnectedID()));
          Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "serviceTypeDiscovered", 
            "serviceTypeDiscovered fired for listener " + 
            listener.toString() + " with event: " + event.toString());
        }
      }
      IServiceTypeID istid = event.getServiceTypeID();
      synchronized (containers)
      {
        for (Iterator itr = containers.iterator(); itr.hasNext();)
        {
          IDiscoveryLocator idca = (IDiscoveryLocator)itr.next();
          idca.addServiceListener(istid, ccsl);
        }
      }
    }
  }
  
  protected final CompositeContainerServiceListener ccsl = new CompositeContainerServiceListener();
  protected final CompositeContainerServiceTypeListener ccstl = new CompositeContainerServiceTypeListener();
  protected Set registeredServices;
  protected final Collection containers;
  private ID targetID;
  
  public CompositeDiscoveryContainer(Collection containers)
  {
    super("ecf.namespace.composite", new DiscoveryContainerConfig(IDFactory.getDefault().createStringID(CompositeDiscoveryContainer.class.getName())));
    this.containers = containers;
    registeredServices = new HashSet();
  }
  
  public void connect(ID aTargetID, IConnectContext connectContext)
    throws ContainerConnectException
  {
    if ((targetID != null) || (getConfig() == null)) {
      throw new ContainerConnectException("Already connected");
    }
    targetID = (aTargetID == null ? getConfig().getID() : aTargetID);
    fireContainerEvent(new ContainerConnectingEvent(getID(), targetID, connectContext));
    synchronized (containers)
    {
      Collection containersFailedToConnect = new HashSet();
      for (Iterator itr = containers.iterator(); itr.hasNext();)
      {
        IContainer container = (IContainer)itr.next();
        if (container.getConnectedID() == null) {
          try
          {
            container.connect(targetID, connectContext);
          }
          catch (ContainerConnectException cce)
          {
            Trace.catching("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "connect", 
              cce);
            containersFailedToConnect.add(container);
            continue;
          }
        }
        IDiscoveryLocator idca = (IDiscoveryLocator)container;
        idca.addServiceListener(ccsl);
        idca.addServiceTypeListener(ccstl);
      }
      containers.removeAll(containersFailedToConnect);
    }
    fireContainerEvent(new ContainerConnectedEvent(getID(), targetID));
  }
  
  public void disconnect()
  {
    fireContainerEvent(new ContainerDisconnectingEvent(getID(), getConnectedID()));
    targetID = null;
    synchronized (containers)
    {
      for (Iterator itr = containers.iterator(); itr.hasNext();)
      {
        IContainer container = (IContainer)itr.next();
        container.disconnect();
      }
      containers.clear();
    }
    synchronized (registeredServices)
    {
      registeredServices.clear();
    }
    synchronized (allServiceListeners)
    {
      allServiceListeners.clear();
    }
    synchronized (serviceListeners)
    {
      serviceListeners.clear();
    }
    synchronized (serviceTypeListeners)
    {
      serviceTypeListeners.clear();
    }
    fireContainerEvent(new ContainerDisconnectedEvent(getID(), getConnectedID()));
  }
  
  public void dispose()
  {
    disconnect();
    synchronized (containers)
    {
      for (Iterator itr = containers.iterator(); itr.hasNext();)
      {
        IContainer container = (IContainer)itr.next();
        container.dispose();
      }
      containers.clear();
    }
    targetID = null;
    super.dispose();
  }
  
  public ID getConnectedID()
  {
    return targetID;
  }
  
  private IServiceID getServiceIDForDiscoveryContainer(IServiceID service, IDiscoveryLocator dca)
  {
    Namespace connectNamespace = dca.getServicesNamespace();
    if (!connectNamespace.equals(service.getNamespace())) {
      return (IServiceID)connectNamespace.createInstance(new Object[] { service.getServiceTypeID().getName(), service.getLocation() });
    }
    return service;
  }
  
  public IServiceInfo getServiceInfo(IServiceID aService)
  {
    Assert.isNotNull(aService);
    synchronized (containers)
    {
      for (Iterator itr = containers.iterator(); itr.hasNext();)
      {
        IDiscoveryLocator idca = (IDiscoveryLocator)itr.next();
        IServiceID isi = getServiceIDForDiscoveryContainer(aService, idca);
        IServiceInfo service = idca.getServiceInfo(isi);
        if (service != null) {
          return service;
        }
      }
    }
    return null;
  }
  
  private IServiceInfo getServiceInfoForDiscoveryContainer(IServiceInfo aSi, IDiscoveryLocator idca)
  {
    IServiceID serviceId = aSi.getServiceID();
    IServiceID sid = getServiceIDForDiscoveryContainer(serviceId, idca);
    IServiceTypeID serviceTypeID = sid.getServiceTypeID();
    return new ServiceInfo(serviceId.getLocation(), aSi.getServiceName(), serviceTypeID, aSi.getPriority(), aSi.getWeight(), aSi.getServiceProperties());
  }
  
  public IServiceInfo[] getServices()
  {
    Set set = new HashSet();
    synchronized (containers)
    {
      for (Iterator itr = containers.iterator(); itr.hasNext();)
      {
        IDiscoveryLocator idca = (IDiscoveryLocator)itr.next();
        IServiceInfo[] services = idca.getServices();
        set.addAll(Arrays.asList(services));
      }
    }
    return (IServiceInfo[])set.toArray(new IServiceInfo[set.size()]);
  }
  
  public IServiceInfo[] getServices(IServiceTypeID type)
  {
    Assert.isNotNull(type);
    Set set = new HashSet();
    synchronized (containers)
    {
      for (Iterator itr = containers.iterator(); itr.hasNext();)
      {
        IDiscoveryLocator idca = (IDiscoveryLocator)itr.next();
        IServiceTypeID isti = getServiceTypeIDForDiscoveryContainer(type, idca);
        IServiceInfo[] services = idca.getServices(isti);
        set.addAll(Arrays.asList(services));
      }
    }
    return (IServiceInfo[])set.toArray(new IServiceInfo[set.size()]);
  }
  
  private IServiceTypeID getServiceTypeIDForDiscoveryContainer(IServiceTypeID type, IDiscoveryLocator dca)
  {
    Namespace connectNamespace = dca.getServicesNamespace();
    if (!connectNamespace.equals(type.getNamespace())) {
      return ServiceIDFactory.getDefault().createServiceTypeID(connectNamespace, type);
    }
    return type;
  }
  
  public IServiceTypeID[] getServiceTypes()
  {
    Set set = new HashSet();
    synchronized (containers)
    {
      for (Iterator itr = containers.iterator(); itr.hasNext();)
      {
        IDiscoveryLocator idca = (IDiscoveryLocator)itr.next();
        IServiceTypeID[] services = idca.getServiceTypes();
        set.addAll(Arrays.asList(services));
      }
    }
    return (IServiceTypeID[])set.toArray(new IServiceTypeID[set.size()]);
  }
  
  public void registerService(IServiceInfo serviceInfo)
  {
    Assert.isNotNull(serviceInfo);
    synchronized (registeredServices)
    {
      Assert.isTrue(registeredServices.add(serviceInfo));
    }
    synchronized (containers)
    {
      for (Iterator itr = containers.iterator(); itr.hasNext();)
      {
        IDiscoveryAdvertiser dca = (IDiscoveryAdvertiser)itr.next();
        IServiceInfo isi = getServiceInfoForDiscoveryContainer(serviceInfo, (IDiscoveryLocator)dca);
        dca.registerService(isi);
        Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "registerService", "registeredService " + 
          serviceInfo.toString());
      }
    }
  }
  
  public void unregisterService(IServiceInfo serviceInfo)
  {
    Assert.isNotNull(serviceInfo);
    synchronized (registeredServices)
    {
      registeredServices.remove(serviceInfo);
    }
    synchronized (containers)
    {
      for (Iterator itr = containers.iterator(); itr.hasNext();)
      {
        IDiscoveryAdvertiser idca = (IDiscoveryAdvertiser)itr.next();
        IServiceInfo isi = getServiceInfoForDiscoveryContainer(serviceInfo, (IDiscoveryLocator)idca);
        idca.unregisterService(isi);
      }
    }
  }
  
  public void unregisterAllServices()
  {
    synchronized (registeredServices)
    {
      synchronized (containers)
      {
        Iterator itr2;
        for (Iterator itr = containers.iterator(); itr.hasNext(); itr2.hasNext())
        {
          IDiscoveryAdvertiser idca = (IDiscoveryAdvertiser)itr.next();
          itr2 = registeredServices.iterator(); continue;
          IServiceInfo serviceInfo = (IServiceInfo)itr2.next();
          IServiceInfo isi = getServiceInfoForDiscoveryContainer(serviceInfo, (IDiscoveryLocator)idca);
          idca.unregisterService(isi);
        }
      }
    }
  }
  
  public IServiceInfo[] purgeCache()
  {
    Set set = new HashSet();
    synchronized (containers)
    {
      for (Iterator itr = containers.iterator(); itr.hasNext();)
      {
        IDiscoveryLocator idca = (IDiscoveryLocator)itr.next();
        IServiceInfo[] services = idca.purgeCache();
        set.addAll(Arrays.asList(services));
      }
    }
    return (IServiceInfo[])set.toArray(new IServiceInfo[set.size()]);
  }
  
  public boolean addContainer(Object object)
  {
    IContainer iContainer = (IContainer)object;
    if (iContainer.getConnectedID() == null) {
      try
      {
        iContainer.connect(targetID, null);
      }
      catch (ContainerConnectException e)
      {
        Trace.catching("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/catching", getClass(), "addContainer(Object)", e);
        return false;
      }
    }
    IDiscoveryLocator idca = (IDiscoveryLocator)object;
    idca.addServiceListener(ccsl);
    idca.addServiceTypeListener(ccstl);
    synchronized (registeredServices)
    {
      IDiscoveryAdvertiser ida = (IDiscoveryAdvertiser)object;
      for (Iterator itr = registeredServices.iterator(); itr.hasNext();)
      {
        IServiceInfo serviceInfo = (IServiceInfo)itr.next();
        try
        {
          ida.registerService(serviceInfo);
        }
        catch (ECFRuntimeException e)
        {
          Trace.catching("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/catching", getClass(), "addContainer(Object)", e);
        }
      }
    }
    synchronized (containers)
    {
      Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "addContainer(Object)", "addContainer " + 
        object.toString());
      return containers.add(object);
    }
  }
  
  public boolean removeContainer(Object object)
  {
    IDiscoveryLocator idca = (IDiscoveryLocator)object;
    idca.removeServiceListener(ccsl);
    idca.removeServiceTypeListener(ccstl);
    synchronized (containers)
    {
      Trace.trace("org.eclipse.ecf.provider.discovery", "org.eclipse.ecf.provider.discovery/debug/methods/tracing", getClass(), "removeContainer(Object)", "removeContainer " + 
        object.toString());
      return containers.remove(object);
    }
  }
  
  public Collection getDiscoveryContainers()
  {
    return Collections.unmodifiableCollection(containers);
  }
  
  public String getContainerName()
  {
    return "ecf.discovery.composite";
  }
}

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

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.ecf.core.ContainerCreateException;
import org.eclipse.ecf.core.ContainerFactory;
import org.eclipse.ecf.core.ContainerTypeDescription;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.IContainerFactory;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.provider.IContainerInstantiator;
import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
import org.eclipse.ecf.discovery.IDiscoveryLocator;

public class CompositeDiscoveryContainerInstantiator
  implements IContainerInstantiator
{
  private static final String ADVERTISER = ".advertiser";
  private static final String LOCATOR = ".locator";
  
  public IContainer createInstance(ContainerTypeDescription description, Object[] parameters)
    throws ContainerCreateException
  {
    try
    {
      IContainerFactory factory = ContainerFactory.getDefault();
      Set containers = new HashSet();
      List list = factory.getDescriptions();
      for (Iterator itr = list.iterator(); itr.hasNext();)
      {
        ContainerTypeDescription ctd = (ContainerTypeDescription)itr.next();
        String name = ctd.getName();
        if (!name.startsWith("ecf.discovery.composite")) {
          if (name.startsWith("ecf.discovery."))
          {
            String ccName = description.getName();
            if ("ecf.discovery.composite".equals(ccName))
            {
              IContainer container = factory.createContainer(ctd.getName());
              containers.add(container);
            }
            else if ((ccName.endsWith(".locator")) && (name.endsWith(".locator")))
            {
              IContainer container = factory.createContainer(ctd.getName());
              containers.add(container);
            }
            else if ((ccName.endsWith(".advertiser")) && (name.endsWith(".advertiser")))
            {
              IContainer container = factory.createContainer(ctd.getName());
              containers.add(container);
            }
          }
        }
      }
      return new CompositeDiscoveryContainer(containers);
    }
    catch (IDCreateException e)
    {
      ContainerCreateException excep = new ContainerCreateException(e.getMessage());
      excep.setStackTrace(e.getStackTrace());
      throw excep;
    }
    catch (ContainerCreateException e)
    {
      ContainerCreateException excep = new ContainerCreateException(e.getMessage());
      excep.setStackTrace(e.getStackTrace());
      throw excep;
    }
  }
  
  public String[] getSupportedAdapterTypes(ContainerTypeDescription description)
  {
    return new String[] { IDiscoveryAdvertiser.class.getName(), IDiscoveryLocator.class.getName() };
  }
  
  public Class[][] getSupportedParameterTypes(ContainerTypeDescription description)
  {
    return new Class[0][0];
  }
  
  public String[] getSupportedIntents(ContainerTypeDescription description)
  {
    return null;
  }
}

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

import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.discovery.IServiceEvent;
import org.eclipse.ecf.discovery.ServiceContainerEvent;

public class CompositeServiceContainerEvent
  extends ServiceContainerEvent
  implements IServiceEvent
{
  private final ID origId;
  
  public CompositeServiceContainerEvent(IServiceEvent event, ID connectedId)
  {
    super(event.getServiceInfo(), connectedId);
    origId = event.getLocalContainerID();
  }
  
  public ID getOriginalLocalContainerID()
  {
    return origId;
  }
  
  public String toString()
  {
    return origId.toString() + ": " + super.toString();
  }
}

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

import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.discovery.IServiceTypeEvent;
import org.eclipse.ecf.discovery.ServiceTypeContainerEvent;

public class CompositeServiceTypeContainerEvent
  extends ServiceTypeContainerEvent
  implements IServiceTypeEvent
{
  private final ID origLocalContainerId;
  
  public CompositeServiceTypeContainerEvent(IServiceTypeEvent event, ID connectedId)
  {
    super(event.getServiceTypeID(), connectedId);
    origLocalContainerId = event.getLocalContainerID();
  }
  
  public ID getOriginalLocalContainerId()
  {
    return origLocalContainerId;
  }
}

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

import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.IContainerListener;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.security.IConnectContext;
import org.eclipse.ecf.discovery.IDiscoveryContainerAdapter;
import org.eclipse.ecf.discovery.IServiceInfo;
import org.eclipse.ecf.discovery.IServiceListener;
import org.eclipse.ecf.discovery.IServiceTypeListener;
import org.eclipse.ecf.discovery.identity.IServiceID;
import org.eclipse.ecf.discovery.identity.IServiceTypeID;
import org.eclipse.equinox.concurrent.future.IFuture;

public class SingletonDiscoveryContainer
  implements IDiscoveryContainerAdapter, IContainer
{
  private final IDiscoveryContainerAdapter discovery;
  private final IContainer container;
  private boolean initialized = false;
  
  public SingletonDiscoveryContainer(IContainer container)
  {
    this.container = container;
    discovery = ((IDiscoveryContainerAdapter)container.getAdapter(IDiscoveryContainerAdapter.class));
  }
  
  public synchronized void connect(ID targetID, IConnectContext connectContext)
    throws ContainerConnectException
  {
    if (!initialized)
    {
      initialized = true;
      container.connect(targetID, connectContext);
    }
  }
  
  public void disconnect() {}
  
  public void dispose() {}
  
  public Object getAdapter(Class adapter)
  {
    if (adapter == null) {
      return null;
    }
    if (adapter.isInstance(this)) {
      return this;
    }
    return null;
  }
  
  public void addServiceListener(IServiceTypeID type, IServiceListener listener)
  {
    discovery.addServiceListener(type, listener);
  }
  
  public void addServiceTypeListener(IServiceTypeListener listener)
  {
    discovery.addServiceTypeListener(listener);
  }
  
  public IServiceInfo getServiceInfo(IServiceID service)
  {
    return discovery.getServiceInfo(service);
  }
  
  public IServiceInfo[] getServices(IServiceTypeID type)
  {
    return discovery.getServices(type);
  }
  
  public Namespace getServicesNamespace()
  {
    return discovery.getServicesNamespace();
  }
  
  public void registerService(IServiceInfo serviceInfo)
  {
    discovery.registerService(serviceInfo);
  }
  
  public void removeServiceListener(IServiceTypeID type, IServiceListener listener)
  {
    discovery.removeServiceListener(type, listener);
  }
  
  public void removeServiceTypeListener(IServiceTypeListener listener)
  {
    discovery.removeServiceTypeListener(listener);
  }
  
  public void unregisterService(IServiceInfo serviceInfo)
  {
    
1 2

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