org.epics.pvmanager
Class TypeSupport<T>

java.lang.Object
  extended by org.epics.pvmanager.TypeSupport<T>
Type Parameters:
T - the type for which to add support
Direct Known Subclasses:
NotificationSupport, TimeSupport

public abstract class TypeSupport<T>
extends java.lang.Object

Implements the mechanism for registering different types so that the library knows how to handle them.

For a type to be usable by the library it needs to be defined:

Author:
carcassi

Constructor Summary
TypeSupport(java.lang.Class<T> type, java.lang.Class<? extends TypeSupport> typeSupportFamily)
          Creates a new type support of the given type
 
Method Summary
static void addTypeSupport(TypeSupport<?> typeSupport)
          Adds type support for the given class.
protected static
<T> TypeSupport<T>
findTypeSupportFor(java.lang.Class<? extends TypeSupport> supportFamily, java.lang.Class<T> typeClass)
          Calculates and caches the type support for a particular class, so that introspection does not occur at every call.
protected  java.lang.Class<T> getType()
          Defines on which class the support is defined.
protected  java.lang.Class<? extends TypeSupport> getTypeSupportFamily()
          Defines which type of support is implementing, notification or time.
static boolean isTypeDirectlySupported(java.lang.Class<? extends TypeSupport> typeSupportFamily, java.lang.Class<?> type)
          Checks whether the type is supported on the same exact type.
static boolean isTypeSupported(java.lang.Class<? extends TypeSupport> typeSupportFamily, java.lang.Class<?> type)
          Checks whether the type is supported directly or through one of the supertypes.
protected static
<T extends TypeSupport<?>>
java.util.Collection<T>
typeSupportsFor(java.lang.Class<T> supportFamily)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeSupport

public TypeSupport(java.lang.Class<T> type,
                   java.lang.Class<? extends TypeSupport> typeSupportFamily)
Creates a new type support of the given type

Parameters:
type - the type on which support is defined
typeSupportFamily - the kind of support is being defined
Method Detail

addTypeSupport

public static void addTypeSupport(TypeSupport<?> typeSupport)
Adds type support for the given class. The type support added will apply to the given class and all of its subclasses. Support of the same family cannot be added twice and will cause an exception. Support for the more specific subclass overrides support for the more abstract class. A class cannot have two types support in the same family coming from two different and unrelated interfaces.

Parameters:
typeSupport - the support to add

isTypeSupported

public static boolean isTypeSupported(java.lang.Class<? extends TypeSupport> typeSupportFamily,
                                      java.lang.Class<?> type)
Checks whether the type is supported directly or through one of the supertypes.

Parameters:
type - type to check support for
typeSupportFamily - the family in which to look for
Returns:
true if supported
Throws:
java.lang.RuntimeException - if multiple conflicting support is found

isTypeDirectlySupported

public static boolean isTypeDirectlySupported(java.lang.Class<? extends TypeSupport> typeSupportFamily,
                                              java.lang.Class<?> type)
Checks whether the type is supported on the same exact type.

Parameters:
type - type to check support for
typeSupportFamily - the family in which to look for
Returns:
true if supported

findTypeSupportFor

protected static <T> TypeSupport<T> findTypeSupportFor(java.lang.Class<? extends TypeSupport> supportFamily,
                                                       java.lang.Class<T> typeClass)
Calculates and caches the type support for a particular class, so that introspection does not occur at every call.

Find the supports for all supertypes. If multiple supports for different supertypes are found, and there isn't a most specific one (i.e. one that implements all the others) then an exception is thrown.

Type Parameters:
T - the type to retrieve support for
Parameters:
supportFamily - the support family for which to find support
typeClass - the class of the type
Returns:
the support for the type or null
Throws:
java.lang.RuntimeException - if multiple conflicting support is found

typeSupportsFor

protected static <T extends TypeSupport<?>> java.util.Collection<T> typeSupportsFor(java.lang.Class<T> supportFamily)

getTypeSupportFamily

protected java.lang.Class<? extends TypeSupport> getTypeSupportFamily()
Defines which type of support is implementing, notification or time.

Returns:
the support family

getType

protected java.lang.Class<T> getType()
Defines on which class the support is defined.