org.fishbolt.common.adapter.ext
Class AdapterFactoryManager

java.lang.Object
  extended by org.fishbolt.common.adapter.ext.AdapterFactoryManager

public class AdapterFactoryManager
extends java.lang.Object

It contains the regisrty of Factories creating adapters. In the context of one system the AdapterFactoryManager object generally exists as a single instance.

All Adaptable objects address to it in the case if the necessary adapter instance is absent in their regisrty. The AdapterFactoryManager object finds the Factory that is responsible for creation of the adapter with the required type and delegates its creation to this Factory. The newly created object is added to the regisrty of the adaptable object.


Field Summary
protected  java.util.LinkedHashMap<java.lang.Class<? extends IAdapter>,java.util.LinkedHashSet<IAdapterFactory>> adapterFactories
          regisrty of objects implementing the IAdapterFactory interface.
 
Constructor Summary
AdapterFactoryManager()
           
 
Method Summary
protected
<A extends IAdapter>
A
createAdapter(java.lang.Class<A> adapterType, IAdaptable adaptable)
          Delegates creation of the concrete adapter for the adaptable object to the corresponding Factory instance from the Factories saved in the regisrty
protected static java.lang.Class<? extends IAdapter> getDerivedFrom(java.lang.Class<? extends IAdapter> base, java.util.Set<java.lang.Class<? extends IAdapter>> derived)
          Determines first class or interface from the set derived which is either the same as class, or is a subclass or subinterface of, the class or interface represented by the specified base parameter
 void register(IAdapterFactory factory)
          Supports possibility to include a new Factory object into the regisrty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

adapterFactories

protected java.util.LinkedHashMap<java.lang.Class<? extends IAdapter>,java.util.LinkedHashSet<IAdapterFactory>> adapterFactories
regisrty of objects implementing the IAdapterFactory interface.

Constructor Detail

AdapterFactoryManager

public AdapterFactoryManager()
Method Detail

register

public void register(IAdapterFactory factory)
Supports possibility to include a new Factory object into the regisrty.

Parameters:
factory - adapter factory
See Also:
IAdapterFactory

createAdapter

protected <A extends IAdapter> A createAdapter(java.lang.Class<A> adapterType,
                                               IAdaptable adaptable)
Delegates creation of the concrete adapter for the adaptable object to the corresponding Factory instance from the Factories saved in the regisrty

Type Parameters:
A - adapter being created.
Parameters:
adapterType - adapter type.
adaptable - adaptable object to create adapter for.
Returns:
adapter instance or null.
See Also:
IAdapter, IAdaptable

getDerivedFrom

protected static java.lang.Class<? extends IAdapter> getDerivedFrom(java.lang.Class<? extends IAdapter> base,
                                                                    java.util.Set<java.lang.Class<? extends IAdapter>> derived)
Determines first class or interface from the set derived which is either the same as class, or is a subclass or subinterface of, the class or interface represented by the specified base parameter

Parameters:
base - defines instance of class to look for.
derived - set of classes to look in.
Returns:
first type from the set which is either the same as class, or is a subclass or subinterface ornull.