org.fishbolt.common.adapter.ext
Class SingleAdapterFactory

java.lang.Object
  extended by org.fishbolt.common.adapter.ext.SingleAdapterFactory
All Implemented Interfaces:
IAdapterFactory

public class SingleAdapterFactory
extends java.lang.Object
implements IAdapterFactory

Base implementation of the IAdapterFactory interface that can create an adapter of one type only.


Field Summary
protected  java.util.LinkedHashSet<java.lang.Class<?>> adaptableTypes
          types of adaptable objects.
protected  java.lang.Class<? extends IAdapter> adpterClass
          adapter class
 
Constructor Summary
SingleAdapterFactory(java.lang.Class<? extends IAdapter> adpterClass)
          The constructor of the Factory creating adapters with the required type for any adaptable object
SingleAdapterFactory(java.lang.Class<? extends IAdapter> adpterClass, java.lang.Class<? extends IAdaptable>... adaptableTypes)
          The constructor of the Factory creating adapters with the type, declared in the first parameter.
 
Method Summary
<A extends IAdapter>
A
create(java.lang.Class<A> adapterType, IAdaptable adaptable)
          In fact performs the creation of an adapter instance for the adaptable object.
 java.lang.Class<? extends IAdapter>[] getAdapterClasses()
          Declares the types of adapters, which instances can be created by the Factory.
protected
<A extends IAdapter>
A
instantiate(java.lang.Class<A> adapterType, IAdaptable adaptable)
          Defines creation of an object instance itself is provided by calling the newInstance() method for the adapter class defined in the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

adpterClass

protected java.lang.Class<? extends IAdapter> adpterClass
adapter class


adaptableTypes

protected java.util.LinkedHashSet<java.lang.Class<?>> adaptableTypes
types of adaptable objects.

Constructor Detail

SingleAdapterFactory

public SingleAdapterFactory(java.lang.Class<? extends IAdapter> adpterClass)
The constructor of the Factory creating adapters with the required type for any adaptable object

Parameters:
adpterClass - - required adapter type.
See Also:
instantiate(Class, IAdaptable), IAdapter

SingleAdapterFactory

public SingleAdapterFactory(java.lang.Class<? extends IAdapter> adpterClass,
                            java.lang.Class<? extends IAdaptable>... adaptableTypes)
The constructor of the Factory creating adapters with the type, declared in the first parameter. The adapter is created only for the adaptable objects that can be reduced to one of the types delivered as other parameters.

Parameters:
adpterClass - required adapter type.
adaptableTypes - defines adaptable types to allow adapter creation for
See Also:
instantiate(Class, IAdaptable), IAdapter, IAdaptable
Method Detail

getAdapterClasses

public java.lang.Class<? extends IAdapter>[] getAdapterClasses()
Description copied from interface: IAdapterFactory
Declares the types of adapters, which instances can be created by the Factory.

Specified by:
getAdapterClasses in interface IAdapterFactory
Returns:
the types of adapters, which instances can be created by the Factory.
See Also:
IAdapter

create

public <A extends IAdapter> A create(java.lang.Class<A> adapterType,
                                     IAdaptable adaptable)
Description copied from interface: IAdapterFactory
In fact performs the creation of an adapter instance for the adaptable object. If the Factory does not support the adapter for this adaptable object, the returned value is null.

Specified by:
create in interface IAdapterFactory
Type Parameters:
A - declares a type of the required adapter
Parameters:
adapterType - defines a type of the required adapter
adaptable - object for which the current adapter is being created.
Returns:
adapter for this adaptable object, the returned value is null.
See Also:
IAdapter, IAdaptable

instantiate

protected <A extends IAdapter> A instantiate(java.lang.Class<A> adapterType,
                                             IAdaptable adaptable)
Defines creation of an object instance itself is provided by calling the newInstance() method for the adapter class defined in the constructor. So, it is necessary to be able to create adapter instances using another way: we should override the method.

Type Parameters:
A - adapter type
Parameters:
adapterType - adapter type
adaptable - to create adapter for
Returns:
adapter instance
Throws:
java.lang.RuntimeException - when it's impossible to instantiate adapter.