com.jfw.util
Class GenericCache

java.lang.Object
  extended by com.jfw.util.GenericCache
All Implemented Interfaces:
java.util.Observer
Direct Known Subclasses:
MyCache, ServicesCache

public abstract class GenericCache
extends java.lang.Object
implements java.util.Observer

Extended by classes used for cache data.
Is an observer of UpdateObservable.
The sub classes must implement the singleton pattern.

Example of sub class

 public final class MyCache extends GenericCache
 {
   //Used for logging
   private static String className = "package.MyCache";
 
   //The only instance of the class
   private static MyCache instance = new MyCache();
 
   //Cached data container
   private Object data;
 
   private MyCache()
   {
     super();
   }
 
   public static MyCache getInstance()
   {
     return instance;
   }
 
   protected void initialize() throws Exception
   {
     //get the data to cache and save them in attribute data
     ...
     data = ...;
   }
 
   public Object getData(Object object) throws Exception
   {
     return data;
   }
 }
 


Field Summary
protected  boolean isObserver
          Set to true when this instance set as observer.
protected  UpdateObservable updateObservable
          The observable object.
 
Constructor Summary
protected GenericCache()
          Sub class constructor must call using super() this constructor at first.
 
Method Summary
abstract  java.lang.Object getData(java.lang.Object object)
          Return cached data.
protected abstract  void initialize()
          Read from a source the data to cache.
protected  void update()
          Call method initialize().
 void update(java.util.Observable observable, java.lang.Object obj)
          Called by the Observable object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

updateObservable

protected UpdateObservable updateObservable
The observable object.


isObserver

protected boolean isObserver
Set to true when this instance set as observer.

Constructor Detail

GenericCache

protected GenericCache()
Sub class constructor must call using super() this constructor at first.

Method Detail

initialize

protected abstract void initialize()
                            throws java.lang.Exception
Read from a source the data to cache.
The method is called in the constructor and in update().

Throws:
java.lang.Exception

getData

public abstract java.lang.Object getData(java.lang.Object object)
                                  throws java.lang.Exception
Return cached data.

Parameters:
object - input object to use or null.
Returns:
cache data.
Throws:
java.lang.Exception

update

protected final void update()
Call method initialize().


update

public void update(java.util.Observable observable,
                   java.lang.Object obj)
Called by the Observable object. Call the method update().

Specified by:
update in interface java.util.Observer