com.sun.tdk.sampleapi
Class StockInfoManager

java.lang.Object
  |
  +--com.sun.tdk.sampleapi.StockInfoManager

public class StockInfoManager
extends java.lang.Object

StockInfoManager is an entry point to the Sample API.
Its getStock method is used to create a StockSymbol object which in turn can be used to retrieve a quote.
Stock information is retrieved using the quote agents. Quote agents can be added to (addQuoteAgent), removed (removeQuoteAgent) and retrieved (getQuoteAgents) from the manager.
This class also contains pair of static methods to deal with the default StockInfoManager (setDefault, getDefault)


Constructor Summary
StockInfoManager()
          Default constructor.
 
Method Summary
 void addQuoteAgent(QuoteAgent agent)
          Adds a QuoteAgent to the StockInfoManager lookup table.
static StockInfoManager getDefault()
          Gets the default StockInfoManager.
 java.util.Enumeration getQuoteAgents()
          Gets an enumeration of all installed QuoteAgents in the same order they were added to the StockInfoManager.
 StockSymbol getStock(java.lang.String symbol)
          Retrieves a StockSymbol object for the specified symbol.
 void removeQuoteAgent(QuoteAgent agent)
          Removes a QuoteAgent from the StockInfoManager lookup table.
static void setDefault(StockInfoManager newDefault)
          Sets the default StockInfoManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StockInfoManager

public StockInfoManager()
Default constructor. Does nothing.

Method Detail

getDefault

public static StockInfoManager getDefault()
Gets the default StockInfoManager.

Returns:
A StockInfoManager object that represents the default value (may be null)
See Also:
setDefault(StockInfoManager)

setDefault

public static void setDefault(StockInfoManager newDefault)
Sets the default StockInfoManager. If newDefault is null there is no default StockInfoManager.

Parameters:
newDefault - A StockInfoManager object that specifies the default value
See Also:
getDefault()

addQuoteAgent

public void addQuoteAgent(QuoteAgent agent)
Adds a QuoteAgent to the StockInfoManager lookup table. If the StockInfoManager lookup table contains a QuoteAgent passed (determined by the equals method), calling this method has no effect.

Parameters:
agent - A QuoteAgent object
Throws:
java.lang.NullPointerException - if the specified agent is null

removeQuoteAgent

public void removeQuoteAgent(QuoteAgent agent)
Removes a QuoteAgent from the StockInfoManager lookup table. If the StockInfoManager lookup table does not contain QuoteAgent passed (determined by the equals method), calling this method has no effect.

Parameters:
agent - A QuoteAgent object
Throws:
java.lang.NullPointerException - if the specified agent is null

getQuoteAgents

public java.util.Enumeration getQuoteAgents()
Gets an enumeration of all installed QuoteAgents in the same order they were added to the StockInfoManager.

Returns:
An Enumeration object with all installed QuoteAgents

getStock

public StockSymbol getStock(java.lang.String symbol)
Retrieves a StockSymbol object for the specified symbol. Looks up the installed agents for the symbols (first added gets looked up first), calling QuoteAgent.getQuote(String) method. Returns the first matching symbol. If a particular agent cannot retrieve the symbol due to a GetQuoteException, it is ignored. If symbol cannot be retrieved (there is no installed agent whose getStock(symbol) method returns non-null StockSymbol), this method returns null.

Parameters:
symbol - A String
Returns:
Created StockSymbol object for the specified symbol, or null if the symbol cannot be not found or no agents are installed
Throws:
java.lang.NullPointerException - if the specified agent is null