org.onemind.commons.java.lang.reflect
Class ClassLookupCache

java.lang.Object
  extended byorg.onemind.commons.java.datastructure.LookupCache
      extended byorg.onemind.commons.java.lang.reflect.ClassLookupCache

public class ClassLookupCache
extends LookupCache

A class lookup cache can lookup non-fully-qualified name classes for a given set of packages and will cache the lookup for later use. For example,

      ClassLookupCache cache = new ClassLookupCache();
      cache.addPackage("*"); //default package
      cache.addPackage("java.io.*");
  
      Class c = cache.getClass("File"); //c = java.io.File
      c = cache.getClass("File1"); //c = null
 
NOTE: 1. The cache is static for all instances of the lookup cache. 2. The packages is instance specific 3. It will cache only positive and negative response of fully qualified name thus lookup of non-fully-qualified has some performance hit, but for the sake of correctness

Version:
$Id: ClassLookupCache.java,v 1.6 2006/10/29 17:02:38 thlee Exp $ $Name: $
Author:
TiongHiang Lee (thlee@onemindsoft.org)

Constructor Summary
ClassLookupCache()
          {@inheritDoc}
 
Method Summary
 void addImport(java.lang.String importName)
          Add a new package.
protected  void clearNegCache()
          Clear all the negative cache
 java.lang.Class getClass(java.lang.String className)
          Get the class given by the fully-qualified or non-fully qualified java class name
 java.util.Set getPackages()
          Get all the import packages in this lookup cache.
protected  boolean isInCache(java.lang.Object o)
          Test if the key is in cache
protected  boolean isInNegCache(java.lang.Object o)
          Get whether the object is in negative cache
 java.lang.Object produce(java.lang.Object key)
          Produce the class given the key Produce the object given the key. This is assumed to be an expensive operation and it will be called by the lookup method. The result will be cached by the lookup method and negative result also will be cached to if the doNegCache is turned on.
protected  void setDoNegativeCache(boolean b)
          Turn on/off the negative cache
 
Methods inherited from class org.onemind.commons.java.datastructure.LookupCache
lookup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassLookupCache

public ClassLookupCache()
{@inheritDoc}

Method Detail

addImport

public void addImport(java.lang.String importName)
Add a new package.


getClass

public java.lang.Class getClass(java.lang.String className)
Get the class given by the fully-qualified or non-fully qualified java class name

Parameters:
className - the class name
Returns:
the class or null

produce

public java.lang.Object produce(java.lang.Object key)
Produce the class given the key Produce the object given the key. This is assumed to be an expensive operation and it will be called by the lookup method. The result will be cached by the lookup method and negative result also will be cached to if the doNegCache is turned on.

Specified by:
produce in class LookupCache
Parameters:
key - the key
Returns:
the result or null if no result

getPackages

public java.util.Set getPackages()
Get all the import packages in this lookup cache.

Returns:
the packages

clearNegCache

protected void clearNegCache()
Clear all the negative cache

Overrides:
clearNegCache in class LookupCache

isInCache

protected boolean isInCache(java.lang.Object o)
Test if the key is in cache

Overrides:
isInCache in class LookupCache
Parameters:
o - the object
Returns:
true if is in cache

isInNegCache

protected boolean isInNegCache(java.lang.Object o)
Get whether the object is in negative cache

Overrides:
isInNegCache in class LookupCache
Parameters:
o - the object
Returns:
true if is in negative cache

setDoNegativeCache

protected void setDoNegativeCache(boolean b)
Turn on/off the negative cache

Overrides:
setDoNegativeCache in class LookupCache
Parameters:
b - true to turn on the neg cache


Copyright © 2004-2006 . All Rights Reserved.