JBoss Common Classes 2.2.17.GA

org.jboss.util.collection
Class WeakClassCache<T>

java.lang.Object
  extended by org.jboss.util.collection.WeakClassCache<T>
Type Parameters:
T - exact value type

public abstract class WeakClassCache<T>
extends Object

A weak class cache that instantiates does not a hold a strong reference to either the classloader or class.

It creates the class specific data in two stages to avoid recursion.

instantiate - creates the data
generate - fills in the details

Author:
Adrian Brock, Ales Justin

Field Summary
protected  Map<ClassLoader,Map<String,WeakReference<T>>> cache
          The cache
 
Constructor Summary
WeakClassCache()
           
 
Method Summary
protected abstract  void generate(Class<?> clazz, T result)
          Fill in the result
 T get(Class<?> clazz)
          Get the information for a class
 T get(String name, ClassLoader cl)
          Get the information for a class
protected  Map<String,WeakReference<T>> getClassLoaderCache(ClassLoader cl)
          Get the cache for the classloader
protected abstract  T instantiate(Class<?> clazz)
          Instantiate for a class
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected final Map<ClassLoader,Map<String,WeakReference<T>>> cache
The cache

Constructor Detail

WeakClassCache

public WeakClassCache()
Method Detail

get

public T get(Class<?> clazz)
Get the information for a class

Parameters:
clazz - the class
Returns:
the info

get

public T get(String name,
             ClassLoader cl)
      throws ClassNotFoundException
Get the information for a class

Parameters:
name - the name
cl - the classloader
Returns:
the info
Throws:
ClassNotFoundException - when the class cannot be found

instantiate

protected abstract T instantiate(Class<?> clazz)
Instantiate for a class

Parameters:
clazz - the class
Returns:
the result

generate

protected abstract void generate(Class<?> clazz,
                                 T result)
Fill in the result

Parameters:
clazz - the class
result - the result

getClassLoaderCache

protected Map<String,WeakReference<T>> getClassLoaderCache(ClassLoader cl)
Get the cache for the classloader

Parameters:
cl - the classloader
Returns:
the map

JBoss Common Classes 2.2.17.GA

Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.