net.sourceforge.groboutils.util.classes.v1
Class AbstractSingleStore

java.lang.Object
  extended bynet.sourceforge.groboutils.util.classes.v1.AbstractSingleStore
Direct Known Subclasses:
SingletonStore

public abstract class AbstractSingleStore
extends java.lang.Object

Aids pluggable factories and related classes by being a central repository for storing a singleton, and creating means to load and change the singleton.

Since:
March 30, 2002
Version:
$Date: 2003/02/10 22:52:36 $
Author:
Matt Albrecht groboclown@users.sourceforge.net

Constructor Summary
AbstractSingleStore(java.lang.Class instanceOf)
          Constructor specifying all the parameters for using a singleton in this framework.
 
Method Summary
protected static java.lang.Object createFromProperty(java.lang.String key, java.lang.Class defaultClass)
          Helper method to load an object from the class specified in the given system property; if the class is invalid, then the given default class will be used instead.
 java.lang.Object getSingleton()
          Returns the current inner singleton.
protected abstract  void setDefaultSingleton()
          Sets the inner singleton to the default, which is an implementation specific method.
 void setSingleton(java.lang.Object singleton)
          Sets the singleton.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSingleStore

public AbstractSingleStore(java.lang.Class instanceOf)
Constructor specifying all the parameters for using a singleton in this framework.

Parameters:
instanceOf - singletons must be of this class.
Method Detail

getSingleton

public java.lang.Object getSingleton()
Returns the current inner singleton. If it has never been set, then the default will be used instead.

Returns:
the inner singleton instance.
Throws:
java.lang.IllegalStateException - if no singleton was created.

setSingleton

public void setSingleton(java.lang.Object singleton)
Sets the singleton. It must be of the correct class, and non-null.

Parameters:
singleton - the singleton to set.
Throws:
java.lang.IllegalArgumentException - if singleton is null, or is not of the correct type.

setDefaultSingleton

protected abstract void setDefaultSingleton()
Sets the inner singleton to the default, which is an implementation specific method.


createFromProperty

protected static java.lang.Object createFromProperty(java.lang.String key,
                                                     java.lang.Class defaultClass)
Helper method to load an object from the class specified in the given system property; if the class is invalid, then the given default class will be used instead. No cast testing is performed.

Parameters:
key - the System property to reference for the classname to instantiate. It is passed to ClassLoadHelper.
defaultClass - class to instantiate if the class defined in the system property is invalid.
Returns:
the generated object.
Throws:
java.lang.IllegalArgumentException - if key is null.
See Also:
ClassLoadHelper.createObjectFromProperty( String, Class, boolean )


Copyright © 2001-2003 by The GroboUtils Project