webfunds.ricardian
Class DirSOXStore

java.lang.Object
  |
  +--webfunds.utils.Debug
        |
        +--webfunds.ricardian.DirSOXStore
Direct Known Subclasses:
SOXServerStore

public class DirSOXStore
extends Debug
implements SOXStore

A Store for SOXServers. Provides access to SOXServer files, and caches the ones it gets. Locating it in ricardian is probably wrong, but SOXServer uses the same IniFile as Contract.


Field Summary
protected  java.io.File dir
           
static java.lang.String local
           
static java.lang.String no_urls
           
protected  java.lang.String postfix
           
protected  java.util.Hashtable soxes
          All the SOXServers, indexed by unique name.
protected  java.util.Hashtable soxNames
          All the SOXServers, indexed by urls, pointing to unique name.
static java.lang.String suffix
           
 
Fields inherited from class webfunds.utils.Debug
bug, debugAll, logfix
 
Constructor Summary
DirSOXStore()
          Create a memory store without any backing store.
DirSOXStore(java.io.File dir, java.io.PrintWriter bug)
          Read in a directory of SOXServer files and provide access to them.
 
Method Summary
protected  void addAndSave(SOXServer sox)
           
protected  void addSOXServer(SOXServer sox)
          Index the sox file into the temporary hashtables.
protected  void addThisSOXName(java.lang.String name, java.lang.String unique)
          Add a name (url) for a SOX server file.
protected  void cleanStore()
           
 java.lang.String[] getAllNames()
          There are many names for each SOXServer.
 SOXServer[] getAllSOXServers()
          Return all SOXServers in the store.
 java.io.File getDirectory()
           
protected  SOXServer getFromStore(java.lang.String name)
          If you wish to change the way that things are stored, override these methods.
 Issuer getIssuer(Contract contract)
          Request an Issuer for contract.
 SOXServer getSOXServer(Contract contract)
          Request a SOXServer for contract.
 SOXServer getSOXServer(java.lang.String[] urls)
          Request a SOXServer for contract.
protected  SOXServer getSOXServerFromCache(java.lang.String[] urls)
          Request a SOXServer for URLs but get it from the cache.
protected  SOXServer getSOXServerFromNet(java.lang.String[] urls)
          Browse a SOXServer from some URLs.
static java.lang.String[] getUrls(Contract contract)
          Get the urls for the SOXServer from the contract.
protected  void initHashtables()
           
static void main(java.lang.String[] arg)
           
 boolean refreshSOXServer(SOXServer old)
          Refresh a SOXServer from the URLs off the net.
protected  void savePersistant(SOXServer sox)
          Override this method to change the nature of the persistant storage.
protected  void setDir(java.io.File storedir)
          Read in a directory of SOXServer files.
 java.lang.String toString()
           
 
Methods inherited from class webfunds.utils.Debug
debug, debug, debug, debug, err, getDebug, logend, logmsg, logstart, logword
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

soxes

protected java.util.Hashtable soxes
All the SOXServers, indexed by unique name. String ==> SOXServer

soxNames

protected java.util.Hashtable soxNames
All the SOXServers, indexed by urls, pointing to unique name. String ==> String

dir

protected java.io.File dir

suffix

public static final java.lang.String suffix

local

public static final java.lang.String local

postfix

protected java.lang.String postfix

no_urls

public static final java.lang.String no_urls
Constructor Detail

DirSOXStore

public DirSOXStore()
Create a memory store without any backing store.

DirSOXStore

public DirSOXStore(java.io.File dir,
                   java.io.PrintWriter bug)
Read in a directory of SOXServer files and provide access to them.
Parameters:
storedir - a directory with server files
bug - place to put debugging during construction
Method Detail

getDirectory

public java.io.File getDirectory()

initHashtables

protected void initHashtables()

setDir

protected void setDir(java.io.File storedir)
Read in a directory of SOXServer files. Make the directory if needed. It is not an error if files cannot be rewritten.

addSOXServer

protected void addSOXServer(SOXServer sox)
Index the sox file into the temporary hashtables. This is the running cache, not the persistant store.

addThisSOXName

protected void addThisSOXName(java.lang.String name,
                              java.lang.String unique)
Add a name (url) for a SOX server file.

getIssuer

public Issuer getIssuer(Contract contract)
                 throws SOXIssuerException,
                        SOXLaterException
Request an Issuer for contract.
Specified by:
getIssuer in interface SOXStore
Returns:
the issuer that handles the contract

getSOXServer

public SOXServer getSOXServer(Contract contract)
                       throws SOXServerException,
                              SOXLaterException
Request a SOXServer for contract. This is the normal way to get new SOXServers into the store.
Specified by:
getSOXServer in interface SOXStore
Returns:
the contract that uniquely matches hash

refreshSOXServer

public boolean refreshSOXServer(SOXServer old)
                         throws SOXServerException,
                                SOXLaterException
Refresh a SOXServer from the URLs off the net. For some reason - bounced connections - the caller has decided that the Issuer is bad. One reason might be that the Issuer has moved. Refresh the SOXServer and see if it has changed. Experimental!
Returns:
true if it changed (caller should retry activity)

getSOXServer

public SOXServer getSOXServer(java.lang.String[] urls)
                       throws SOXServerException,
                              SOXLaterException
Request a SOXServer for contract. This is the backdoor way to get new SOXServers into the store, for when the SOXServer is expressed differently.
Returns:
the SOXServer that uniquely matches hash

getSOXServerFromCache

protected SOXServer getSOXServerFromCache(java.lang.String[] urls)
                                   throws SOXServerException
Request a SOXServer for URLs but get it from the cache.
Returns:
the SOXServer that matches the urls

getSOXServerFromNet

protected SOXServer getSOXServerFromNet(java.lang.String[] urls)
                                 throws SOXServerException,
                                        SOXLaterException
Browse a SOXServer from some URLs.
Returns:
the first SOXServer that we find

getFromStore

protected SOXServer getFromStore(java.lang.String name)
                          throws SOXServerException
If you wish to change the way that things are stored, override these methods. // this method not used - deprecate

addAndSave

protected void addAndSave(SOXServer sox)
                   throws SOXServerException

savePersistant

protected void savePersistant(SOXServer sox)
                       throws SOXServerException
Override this method to change the nature of the persistant storage.

cleanStore

protected void cleanStore()
                   throws java.io.IOException

getUrls

public static java.lang.String[] getUrls(Contract contract)
Get the urls for the SOXServer from the contract.
Returns:
array of urls

getAllNames

public java.lang.String[] getAllNames()
Description copied from interface: SOXStore
There are many names for each SOXServer. This list will be larger than the number of SOXServers.
Specified by:
getAllNames in interface SOXStore
Returns:
a list of the names of all SOXServers

getAllSOXServers

public SOXServer[] getAllSOXServers()
Description copied from interface: SOXStore
Return all SOXServers in the store.
Specified by:
getAllSOXServers in interface SOXStore
Returns:
a list of all SOXServers

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] arg)
                 throws ContractException,
                        ContractDirectoryException,
                        SOXServerException,
                        SOXLaterException