|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.tapestry.util.AdaptorRegistry
public class AdaptorRegistry
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.
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 |
---|
public AdaptorRegistry()
Method Detail |
---|
public void register(Class registrationClass, Object adaptor)
IllegalArgumentException
- if an adaptor has already
been registered for the given class.public Object getAdaptor(Class subjectClass)
IllegalArgumentException
- if no adaptor could be found.public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |