org.makumba.commons
Class NamedResourceFactory
java.lang.Object
org.makumba.commons.NamedResourceFactory
- All Implemented Interfaces:
- Serializable
public abstract class NamedResourceFactory
- extends Object
- implements Serializable
This models a factory for named resources. Normally a subclass should just implement
makeResource(name)
, which is called whenever the
NamedResources
is requested an object that it doesn't hold. Still, there are some
special cases:
- the
NamedResources
keeps objects in a hashtable. If the key for that hashtable
corresponding to a certain name is not the name itself, the getHashObject(name)
method should be redefined.
- if the process of constructing the resource needs the hash key, the
makeResource(name, hashName)
method should be redefined,
instead of makeResource(name)
- if the process of constructing the resource needs other resources, that in turn might need the resource which is
just built, these resources should not be retreived in the makeResource() methods, since that would cause infinite
loops. makeResource() should just build the resource, and
configureResource(name, hashName,
resource)
should be redefined to do further resource adjustments.
- Version:
- $Id: NamedResourceFactory.java 5125 2010-05-18 17:57:27Z rosso_nero $
- Author:
- Cristian Bogdan
- See Also:
- Serialized Form
Method Summary |
protected void |
configureResource(Object name,
Object hashName,
Object resource)
This method is called immediately after the resource is built, but before making it accessible to other threads,
and before the resource being returned to the client that requested it. |
protected Object |
getHashObject(Object name)
This method builds the hash object from the name of the object. |
protected Object |
makeResource(Object name)
This method should make the resource with the given name. |
protected Object |
makeResource(Object name,
Object hashName)
If the hash object for the resource is different from the name, this is the method used to build the named
resource. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
supplementary
protected Object supplementary
NamedResourceFactory
public NamedResourceFactory()
makeResource
protected Object makeResource(Object name)
throws Throwable
- This method should make the resource with the given name. All exceptions thrown here will be caught and thrown
further as RuntimeWrappedExceptions. This method should not lead to the request of the same resource from the
NamedResources (by for example requesting another resource that needs to refer this resource). Such actions
should be performed in configureResource()
- Parameters:
name
- the name of the resource to be made
- Returns:
- the newly created resource
- Throws:
Throwable
makeResource
protected Object makeResource(Object name,
Object hashName)
throws Throwable
- If the hash object for the resource is different from the name, this is the method used to build the named
resource. All exceptions throws here will be caught and thrown further as RuntimeWrappedExceptions. This method
should not lead to the request of the same resource from the NamedResources (by e.g. requesting another resource
that needs to refer this resource). Such actions should be performed in configureResource()
- Parameters:
name
- name of the resource to be madehashName
- name of the hash for the object
- Returns:
- the newly created resource
- Throws:
Throwable
getHashObject
protected Object getHashObject(Object name)
throws Throwable
- This method builds the hash object from the name of the object. By default, it returns the name
- Parameters:
name
- the name of the object
- Returns:
- The hash object
- Throws:
Throwable
configureResource
protected void configureResource(Object name,
Object hashName,
Object resource)
throws Throwable
- This method is called immediately after the resource is built, but before making it accessible to other threads,
and before the resource being returned to the client that requested it.
- Parameters:
name
- the name of the objecthashName
- the hash name of the objectresource
- the resource
- Throws:
Throwable