|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
An implementation of the adapter pattern. The adapter 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 adapter). The implementation of the adapter is not relevant to the adapterRegistry class.
adapters are registered before they can be used; the registration maps a particular class to an adapter instance. The adapter 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, adapters can be registered against interfaces. Searching of interfaces occurs after searching of classes. The exact order is:
The first match terminates the search.
The AdapterRegistry caches the results of search; a subsequent search for the same subject class will be resolved immediately.
AdapterRegistry 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[]
. AdapterRegistry
"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 arrays), and then,
finally, Object
This tweak doesn't apply to arrays of primitives, since such arrays may not be
assigned to Object[]
.
AdapterRegistryImpl
Method Summary | |
java.lang.Object |
getAdapter(java.lang.Class subjectClass)
Gets the adapter for the specified subjectClass. |
void |
register(java.lang.Class registrationClass,
java.lang.Object adapter)
Registers an adapter for a registration class. |
Method Detail |
public void register(java.lang.Class registrationClass, java.lang.Object adapter)
java.lang.IllegalArgumentException
- if an adapter has already been registered for the given class.public java.lang.Object getAdapter(java.lang.Class subjectClass)
java.lang.IllegalArgumentException
- if no adapter could be found.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |