Poseidon for UMLTM
  UMLdoc
 PREV  CLASSIFIER    NEXT  CLASSIFIER     FRAMES    NO FRAMES      
SUMMARY:   INNER | ATTR | ASSOC | CONSTR | METHOD     DETAIL:   INNER | ATTR | ASSOC | CONSTR | METHOD     DIAGRAMS:   COLLAB | SEQ | STATE | ACTIV

com.gentleware.services.util

Class InstanceCache

com.gentleware.services.util.InstanceCache

public class InstanceCache


Cache that holds a single instance per Java class, where the class is specified by a {link ClassMap}. Instances are created as necessary. On creation a callback can be called.

Created : kelvin, Nov 13, 2002, 1:27:13 PM

Authors:
kelvin
See also:
com.gentleware.services.util.ClassMap


 Inner Classifier Summary
public   InstanceCache.CreationListener
A instance of this class can be specified as a callback that is executed whenever a new instance is created. 
arrow_up
 

 Attribute Summary
private ClassMap  _classMap
the class map that is used to enable mapping of subclasses/interfaces  
private Object[]  _constructorArguments
 
private Class[]  _constructorParameters
 
private static Object[]  _defaultConstructorArguments
 
private static Class[]  _defaultConstructorParameters
 
private Map  _instanceByClass
instance cache, key is target class  
arrow_up
 

 Association Summary
private CreationListener  _creationListener
the callback to be used for notification of a new instance  
arrow_up
 

 Constructor Summary
public   InstanceCache()
Creates a new instance cache that does not have any creation listener. 
public   InstanceCache(InstanceCache.CreationListener creationListener)
Creates a new instance cache where the given creation listener is called whenever an instance is created. 
public   InstanceCache(InstanceCache.CreationListener creationListener, Class[] constructorParameters, Object[] constructorArguments)
Creates a new instance cache where the given creation listener is called whenever an instance is created. 
arrow_up
 

 Method Summary
public void   clear()
Removes all instances that have been created so far from the cache. 
public void   dispose()
 
public Object   find(Class sourceClass)
Uses the mappings added with put to find a target class for the source class without a further key. 
public Object   find(Class sourceClass, Object key)
Uses the mappings added with put to find a target class for the source class and the key. 
public Object   getInstance(Class sourceClass)
Uses the mappings added with put to find a target class for the source class. 
public Set   getInstances()
 
public void   put(Class sourceClass, Object key, Class targetClass)
Adds a mapping from the given source class/interface (and all its subclasses/interfaces) and from the given key to the target class. 
public void   put(Class sourceClass, Class targetClass)
Adds a mapping from the given source class/interface (and all its subclasses/interfaces) to the target class without a further key. 
public void   remove(Class sourceClass)
Removes the mapping for a source class witout a further key. 
public void   remove(Class sourceClass, Object key)
Removes the mapping for a source class and a further key. 
arrow_up
 

Tagged Values
static false
 

 Inner Classifier Detail

InstanceCache.CreationListener

public  InstanceCache.CreationListener

A instance of this class can be specified as a callback that is executed whenever a new instance is created.  
arrow_up
 Attribute Detail

_classMap

private ClassMap _classMap

the class map that is used to enable mapping of subclasses/interfaces  
arrow_up


_constructorArguments

private Object[] _constructorArguments

arrow_up


_constructorParameters

private Class[] _constructorParameters

arrow_up


_defaultConstructorArguments

private static Object[] _defaultConstructorArguments

arrow_up


_defaultConstructorParameters

private static Class[] _defaultConstructorParameters

arrow_up


_instanceByClass

private Map _instanceByClass

instance cache, key is target class  
arrow_up
 Association Detail

_creationListener

private CreationListener _creationListener

the callback to be used for notification of a new instance  
arrow_up
 Constructor Detail

InstanceCache

public InstanceCache InstanceCache()


Creates a new instance cache that does not have any creation listener.  
Returns:
arrow_up


InstanceCache

public InstanceCache InstanceCache(InstanceCache.CreationListener creationListener)


Creates a new instance cache where the given creation listener is called whenever an instance is created.  
Parameters:
creationListener -
Returns:
arrow_up


InstanceCache

public InstanceCache InstanceCache(InstanceCache.CreationListener creationListener, Class[] constructorParameters, Object[] constructorArguments)


Creates a new instance cache where the given creation listener is called whenever an instance is created.  
Parameters:
creationListener -
constructorParameters -
constructorArguments -
Returns:
arrow_up
 Method Detail

clear

public void clear()


Removes all instances that have been created so far from the cache. New instances will be created at subsequent invocations of find().  
arrow_up


dispose

public void dispose()

arrow_up


find

public Object find(Class sourceClass)


Uses the mappings added with put to find a target class for the source class without a further key.  
Parameters:
sourceClass -
Returns:
arrow_up


find

public Object find(Class sourceClass, Object key)


Uses the mappings added with put to find a target class for the source class and the key. Returns an instance of the target class. If no such instance previously existed it is created using reflection.  
Parameters:
sourceClass -
key -
Returns:
arrow_up


getInstance

public Object getInstance(Class sourceClass)


Uses the mappings added with put to find a target class for the source class. Returns an instance of the target class. If no such instance exists returns null.  
Parameters:
sourceClass -
Returns:
arrow_up


getInstances

public Set getInstances()

Returns:
a set of all instances created so far
arrow_up


put

public void put(Class sourceClass, Object key, Class targetClass)


Adds a mapping from the given source class/interface (and all its subclasses/interfaces) and from the given key to the target class. In the future whenever find is called with this source class an instance of target class will be returned. Target class must have a constructor that takes no arguments. This will invalidate all curent instances, so that new ones will be created at each subsequent find().  
Parameters:
sourceClass -
key -
targetClass -
arrow_up


put

public void put(Class sourceClass, Class targetClass)


Adds a mapping from the given source class/interface (and all its subclasses/interfaces) to the target class without a further key. In the future whenever find is called with this source class an instance of target class will be returned. Target class must have a constructor that takes no arguments. This will invalidate all curent instances, so that new ones will be created at each subsequent find().  
Parameters:
sourceClass -
targetClass -
arrow_up


remove

public void remove(Class sourceClass)


Removes the mapping for a source class witout a further key.  
Parameters:
sourceClass -
arrow_up


remove

public void remove(Class sourceClass, Object key)


Removes the mapping for a source class and a further key. This will invalidate all curent instances, so that new ones will be created at each subsequent find().  
Parameters:
sourceClass -
key -
arrow_up
Created  2004 - 10 - 21

    Poseidon for UMLTM
  UMLdoc
 PREV  CLASSIFIER    NEXT  CLASSIFIER     FRAMES    NO FRAMES      
SUMMARY:   INNER | ATTR | ASSOC | CONSTR | METHOD     DETAIL:   INNER | ATTR | ASSOC | CONSTR | METHOD     DIAGRAMS:   COLLAB | SEQ | STATE | ACTIV

Generated with Poseidon for UMLTM.
Poseidon is a registered trademark of Gentleware AG in Germany, USA and other countries. Copyright 2003-2004 Gentleware AG, Schanzenstr. 70, 20357 Hamburg, Germany. All Rights Reserved.

UML is a trademark or registered trademark of Object Management Group, Inc. in the U.S. and other countries.