[Webfunds-commits] java/webfunds/sox/value SSDStore.java SOXServerStore.java

Ian Grigg iang@cypherpunks.ai
Fri, 6 Apr 2001 18:51:45 -0400 (AST)


iang        01/04/06 18:51:45

  Added:       webfunds/sox/value SSDStore.java
  Removed:     webfunds/sox/value SOXServerStore.java
  Log:
  moved SOXServerStore to SSDStore, along with many changes for new SSD package.

Revision  Changes    Path
1.1                  java/webfunds/sox/value/SSDStore.java

Index: SSDStore.java
===================================================================
/*
 * $Id: SSDStore.java,v 1.1 2001/04/06 22:51:45 iang Exp $
 *
 * Copyright (c) 1995-2000 Systemics Inc. on behalf of
 * the WebFunds Development Team.  All Rights Reserved.
 */
package webfunds.sox.value;


import java.util.Enumeration;
import java.io.PrintWriter;
import java.security.cert.Certificate;

import webfunds.sox.Server;
import webfunds.sox.Issuer;
import webfunds.sox.ItemId;
import webfunds.sox.ServerFinder;
import webfunds.sox.SOXServerException;
import webfunds.sox.SOXIssuerException;
import webfunds.sox.SOXLaterException;
import webfunds.store.Store;

import webfunds.comms.*;
import webfunds.ricardian.*;
import webfunds.sox.server.*;

public class SSDStore
    extends DirSSDStore implements ServerFinder
{

    protected Store         store;
    protected ContractStore contracts;

    public SSDStore(Store store,
                    ContractStore contracts,
                    CommsManager comms,
                    PrintWriter bug)
    {
        super();
        debug(bug, "     ssS: ");

        if (comms == null)
            throw new IllegalArgumentException("SSDStore comms == null");
        setCommsManager(comms);
        this.contracts = contracts;

        if (store == null)
            throw new IllegalArgumentException("SSDStore store == null");
        this.store = store;
        readInStore();
        logmsg("SSDStore Open!");
    }

    protected void readInStore()
    {
        int i = 0;
        for (Enumeration e = store.elements(); e.hasMoreElements(); i++)
        {
            SSD sox = (SSD)e.nextElement();
            addSSD(sox);
        }
        if (store.checkErrors())
        {
            logmsg("Couldn't read in SSDs");
        }
    }


    /**
     * Overrides methods in base class, and sticks objects in local store.
     */
    protected void savePersistant(SSD x)
    {
        store.put(x.getName(), x); 
        logmsg("SSD = " + x.getName());
    }




    /**
     *  This is the IssuerFinder call, which returns the
     *  needed Server object from an ItemId.
     *
     *  This method is a/the bridge between webfunds.ricardian and
     *  webfunds.sox.server.
     *
     *  @return the Server for this contract
     *  @except SOXServerException if the id does not result in an Server
     */
    public Server getServer(ItemId id)
        throws SOXServerException, SOXLaterException
    {
        Contract con = contracts.getContract(id);

        if (con == null)
            throw new SOXServerException(SOXServerException.NO_CONTRACT,
                                         "cannot point to server " +
                                         "without contract for " + id);
        logmsg("Obtained contract: " + con);
        String[] locs = SSDFields.getLocation(con);
        String name = SSDFields.getName(con);

        SSD ssd;
        try {
            ssd = this.get(name, locs);
        } catch (SSDException ex) {
            throw new SOXServerException("SSDEx: " + ex);
        }

        if (ssd == null)
            throw new SOXServerException("none found for " + name);

        Certificate cert;
        try {
            cert = con.getServerCert();
        } catch (ContractException ex) {
   
            throw new SOXServerException("server cert in contract is bad: " +
                                         con + "\n" + ex);
        }

        Server server = new SmartServer(name, (DirSSDStore)this,
                                        cert, comms, getDebug());
        return server;
    }

    public Issuer getIssuer(ItemId id)
        throws SOXIssuerException, SOXLaterException
    {
        return getServer(id);
    }
}