package org.jworkplace;                                                 
 import java.io.*;                       
 import java.rmi.*;        
 import java.util.*;     
    
 import net.jini.core.entry.Entry;                    
 import net.jini.core.lookup.ServiceID;                            
 import net.jini.core.lookup.ServiceItem;                            
 import net.jini.core.lookup.ServiceMatches;                            
 import net.jini.core.lookup.ServiceRegistrar;    
 import net.jini.core.lookup.ServiceTemplate;    
 import net.jini.discovery.DiscoveryEvent;   
 import net.jini.discovery.DiscoveryListener;   
 import net.jini.discovery.LookupDiscoveryManager;    
 import net.jini.lookup.ClientLookupManager;
 import net.jini.space.JavaSpace;

 public class Scout implements DiscoveryListener {                   
                   
    protected String[] groups = new String[] { "" };          
    protected Vector services = new Vector();   
  
    protected LookupDiscoveryManager ldm;  
    protected ServiceTemplate template;  
    protected JavaSpace space;               
    protected ServiceID serviceID;      
    protected ServiceItem si;      
    
    public Scout(ServiceTemplate template) throws IOException  { 
       this.template = template;               
       ldm = new LookupDiscoveryManager(groups,null,this);             
    }  


    // display to console information on services that match template
    public synchronized void discovered(DiscoveryEvent de) {      
        System.out.println("Discovered a new lookup service: "+ de);     
        ServiceRegistrar[] registrars = de.getRegistrars();      
        for(int i=0; i < registrars.length; i++) {       
          try {      
             ServiceMatches sm = registrars[i].lookup(template,
Integer.MAX_VALUE);  
             System.out.println("Matching services found ------: " + 
sm.totalMatches);
             for(int j=0; j < sm.items.length; j++) {      
               // Process each ServiceItem
               if(sm.items[j].service != null) {   
                  System.out.println("Service --------------: " + 
sm.items[j].service);
                  System.out.println("ServiceID ------------: " + 
sm.items[j].serviceID);
                  Entry[] entries = sm.items[j].attributeSets;
                  System.out.println("Service attributes ---:");
                  for(int k=0; k