org.jlf.util
Class ClassInstanceVariable

java.lang.Object
  |
  +--org.jlf.util.ClassInstanceVariable

public class ClassInstanceVariable
extends java.lang.Object

This class provides the concept of a Class Instance Variable as implemented in the Smalltalk language, with an additional optional context setting as well. Use this class to implement caches and other concepts where you would traditionally need a class/static variable that is inherited but different for every subclass.


Field Summary
protected static ClassInstanceVariable singleton
           
protected  java.util.Hashtable variableList
           
 
Constructor Summary
protected ClassInstanceVariable()
           
 
Method Summary
protected static ClassInstanceVariable getInstance()
           
static java.lang.Object getVariable(java.lang.Class variableClass, java.lang.String variableName)
          Gets a variable for a particular class.
static java.lang.Object getVariableInContext(java.lang.Class variableClass, java.lang.String variableName, java.lang.Object context)
          Gets a variable for a particular class.
protected  java.lang.Object getVariableInContextI(java.lang.Class variableClass, java.lang.String variableName, java.lang.Object context)
           
static void setVariable(java.lang.Class variableClass, java.lang.String variableName, java.lang.Object value)
          Sets a variable for a particular class.
static void setVariableInContext(java.lang.Class variableClass, java.lang.String variableName, java.lang.Object context, java.lang.Object value)
          Sets a variable for a particular class.
protected  void setVariableInContextI(java.lang.Class variableClass, java.lang.String variableName, java.lang.Object context, java.lang.Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleton

protected static ClassInstanceVariable singleton

variableList

protected java.util.Hashtable variableList
Constructor Detail

ClassInstanceVariable

protected ClassInstanceVariable()
Method Detail

getInstance

protected static ClassInstanceVariable getInstance()

setVariable

public static void setVariable(java.lang.Class variableClass,
                               java.lang.String variableName,
                               java.lang.Object value)
Sets a variable for a particular class. Use if no context object is needed.

Parameters:
variableClass - The Class the variable will be associated with.
variableName - The name of the variable for that class.
value - The value that variable should be set to.

setVariableInContext

public static void setVariableInContext(java.lang.Class variableClass,
                                        java.lang.String variableName,
                                        java.lang.Object context,
                                        java.lang.Object value)
Sets a variable for a particular class.

Parameters:
variableClass - The Class the variable will be associated with.
variableName - The name of the variable for that class.
context - An object that further controls the uniqueness of the variable. For example, the variable may have different settings for different users, so this object may be a User object. This object must properly implement the equals() protocol.
value - The value that variable should be set to.

getVariable

public static java.lang.Object getVariable(java.lang.Class variableClass,
                                           java.lang.String variableName)
Gets a variable for a particular class.

Parameters:
variableClass - The Class the variable will be associated with.
variableName - The name of the variable for that class.
Returns:
The value of the variable, null if none found.

getVariableInContext

public static java.lang.Object getVariableInContext(java.lang.Class variableClass,
                                                    java.lang.String variableName,
                                                    java.lang.Object context)
Gets a variable for a particular class.

Parameters:
variableClass - The Class the variable will be associated with.
variableName - The name of the variable for that class.
context - An object that further controls the uniqueness of the variable. For example, the variable may have different settings for different users, so this object may be a User object. This object must properly implement the equals() protocol.
Returns:
The value of the variable, null if none found.

setVariableInContextI

protected void setVariableInContextI(java.lang.Class variableClass,
                                     java.lang.String variableName,
                                     java.lang.Object context,
                                     java.lang.Object value)

getVariableInContextI

protected java.lang.Object getVariableInContextI(java.lang.Class variableClass,
                                                 java.lang.String variableName,
                                                 java.lang.Object context)