org.apache.tapestry.util
Class AdaptorRegistry

java.lang.Object
  extended by org.apache.tapestry.util.AdaptorRegistry

public class AdaptorRegistry
extends Object

An implementation of the Adaptor pattern. The adaptor pattern allows new functionality to be assigned to an existing class. As implemented here, this is a smart lookup between a particular class (the class to be adapted, called the subject class) and some object instance that can provide the extra functionality (called the adaptor). The implementation of the adaptor is not relevant to the AdaptorRegistry class.

Adaptors are registered before they can be used; the registration maps a particular class to an adaptor instance. The adaptor instance will be used when the subject class matches the registered class, or the subject class inherits from the registered class.

This means that a search must be made that walks the inheritance tree (upwards from the subject class) to find a registered mapping.

In addition, adaptors can be registered against interfaces. Searching of interfaces occurs after searching of classes. The exact order is:

The first match terminates the search.

The AdaptorRegistry caches the results of search; a subsequent search for the same subject class will be resolved immediately.

AdaptorRegistry does a minor tweak of the "natural" inheritance. Normally, the parent class of an object array (i.e., Foo[]) is simply Object, even though you may assign Foo[] to a variable of type Object[]. AdaptorRegistry "fixes" this by searching for Object[] as if it was the superclass of any object array. This means that the search path for Foo[] is Foo[], Object[], then a couple of interfaces Cloneable, Serializable, etc. that are\ implicitily implemented by arrarys), and then, finally, Object

This tweak doesn't apply to scalar arrays, since scalar arrays may not be assigned to Object[].

This class is thread safe.

Version:
$Id: AdaptorRegistry.java 243791 2004-02-19 17:38:13Z hlship $
Author:
Howard Lewis Ship

Constructor Summary
AdaptorRegistry()
           
 
Method Summary
 Object getAdaptor(Class subjectClass)
          Gets the adaptor for the specified subjectClass.
 void register(Class registrationClass, Object adaptor)
          Registers an adaptor for a registration class.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AdaptorRegistry

public AdaptorRegistry()
Method Detail

register

public void register(Class registrationClass,
                     Object adaptor)
Registers an adaptor for a registration class.

Throws:
IllegalArgumentException - if an adaptor has already been registered for the given class.

getAdaptor

public Object getAdaptor(Class subjectClass)
Gets the adaptor for the specified subjectClass.

Throws:
IllegalArgumentException - if no adaptor could be found.

toString

public String toString()
Overrides:
toString in class Object