FileDocCategorySizeDatePackage
RegistryService.javaAPI DocApache Axis 1.43713Sat Apr 22 18:56:52 BST 2006samples.bidbuy

RegistryService

public class RegistryService extends Object

Fields Summary
private static Hashtable
registry
Constructors Summary
public RegistryService()
Find a named service in a list

param
list of services
param
name to search for
return
service found (or null)


                               

      
      load();
    
Methods Summary
public Service[]Lookup(java.lang.String stype)
Return the current list of services as an array

param
Service Name
return
List of servers that implement that service

        if (!registry.containsKey(stype)) return new Service[] {};
        Vector list = (Vector)registry.get(stype);
        Service[] result = new Service[list.size()];
        list.copyInto(result);
        return result;
    
public java.lang.StringLookupAsString(java.lang.String stype)

        Service[] services = Lookup(stype);
        String result = "";
        for (int i=0; i<services.length; i++) {
            Service service = services[i];
            result += service.getServiceName() + "\t" +
                      service.getServiceUrl() + "\t" +
                      service.getServiceType() + "\t" +
                      service.getServiceWsdl() + "\n";
        }
        return result;
    
public voidRegister(java.lang.String name, java.lang.String url, java.lang.String stype, java.lang.String wsdl)
Register a new serivce

param
server name
param
url of endpoint
param
stype
param
wsdl

        Vector list = (Vector)registry.get(stype);
        if (list == null) registry.put(stype, list=new Vector());
        Service service = find(list, name);
        if (service==null)
            list.add(service=new Service());
        service.setServiceName(name);
        service.setServiceUrl(url);
        service.setServiceType(stype);
        service.setServiceWsdl(wsdl);
        save();
    
public voidUnregister(java.lang.String name)
Unregister a serivce

param
server name

        Enumeration e1 = registry.keys();
        while (e1.hasMoreElements()) {
            Vector list = (Vector) registry.get(e1.nextElement());
            Enumeration e2 = list.elements();
            while (e2.hasMoreElements()) {
                Service s = (Service) e2.nextElement();
                if (s.getServiceName().equals(name)) {
                    list.remove(s);
                    save();
                }
            }
        }
    
private Servicefind(java.util.Vector list, java.lang.String name)

        Enumeration e = list.elements();
        while (e.hasMoreElements()) {
            Service s = (Service) e.nextElement();
            if (s.getServiceName().equals(name)) return s;
        }
        return null;
    
public voidload()

      try {
        FileInputStream fis = new FileInputStream("bid.reg");
        ObjectInputStream ois = new ObjectInputStream( fis );
        registry = (Hashtable) ois.readObject();
        ois.close();
        fis.close();
      } catch(java.io.FileNotFoundException fnfe){
        // nop
      } catch(Exception e){
        e.printStackTrace();
      }
    
public voidsave()

      try {
        FileOutputStream fos = new FileOutputStream("bid.reg");
        ObjectOutputStream oos = new ObjectOutputStream( fos );
        oos.writeObject( registry );
        oos.close();
        fos.close();
      } catch(Exception e){
        e.printStackTrace();
      }