wt.fc
Class ReferenceResolver

java.lang.Object
  extended bywt.fc.ReferenceResolver

public final class ReferenceResolver
extends Object

Uses introspection and reflection to find the best matching reference class for a given Persistable class.

The public APIs are all thread-safe.


Field Summary
private static String CLASSNAME
           
private static boolean DEBUG
           
static Map DEFAULT_OVERRIDES
           
private static DebugWriter LOG
           
private static Object NO_MATCH
           
private  HashMap persistableTypesToReferenceTypes
           
private  Map referenceTypesToPersistableFactoryMethods
           
private  Map referenceTypesToQueryKeyFactoryMethods
           
 
Constructor Summary
ReferenceResolver(Class root_class)
          Creates a ReferenceResolver for all descendents of the given reference class
ReferenceResolver(Class root_class, Map overrides)
          Creates a ReferenceResolver for all descendents of the given reference class
 
Method Summary
private  void addTarget(ClassInfo info)
          Called by the constructor to build up the persistableTypesToReferenceTypes map
(package private) static Method getFactoryMethod(Class object_class, Class parameter_class)
          Tries to use reflection to get a system-generated factory method for the given object type that has the given parameter type.
(package private) static String getFactoryMethodName(Class reference_class)
          Gets the system-generated factory method for the given class
(package private) static Class getPersistableTypeByIntrospection(ClassInfo info)
          Tries to use introspection to get the Persistsble object type that corresponds to the given reference type, by looking at the references CONSTRAINED_TYPE property
 WTReference getReference(Persistable p)
          Create a reference to the given Persistable
 WTReference getReference(QueryKey query_key)
          Create a reference to the given QueryKey
 Class getReferenceClass(Class persistable_class)
          Get the Class of WTReference that should be used for instances of the given Persistable class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSNAME

private static final String CLASSNAME

DEBUG

private static final boolean DEBUG

LOG

private static final DebugWriter LOG

NO_MATCH

private static final Object NO_MATCH

persistableTypesToReferenceTypes

private volatile HashMap persistableTypesToReferenceTypes

referenceTypesToPersistableFactoryMethods

private final Map referenceTypesToPersistableFactoryMethods

referenceTypesToQueryKeyFactoryMethods

private final Map referenceTypesToQueryKeyFactoryMethods

DEFAULT_OVERRIDES

public static final Map DEFAULT_OVERRIDES
Constructor Detail

ReferenceResolver

public ReferenceResolver(Class root_class)
Creates a ReferenceResolver for all descendents of the given reference class

Parameters:
root_class - The root class that all references resolved by this instance will be subclasses of

ReferenceResolver

public ReferenceResolver(Class root_class,
                         Map overrides)
Creates a ReferenceResolver for all descendents of the given reference class

Parameters:
root_class - The root class that all references resolved by this instance will be subclasses of
overrides - Mapping of persistable types to reference types that will override what would have been found via introspection or reflection
Method Detail

getReference

public WTReference getReference(Persistable p)
Create a reference to the given Persistable

Parameters:
p -
Returns:
WTReference

getReference

public WTReference getReference(QueryKey query_key)
Create a reference to the given QueryKey

Parameters:
query_key -
Returns:
WTReference

getReferenceClass

public Class getReferenceClass(Class persistable_class)
Get the Class of WTReference that should be used for instances of the given Persistable class.

The implementation uses a copy-on-write strategy to keep this method from paying synchronization costs

Parameters:
persistable_class - The class of Persistable to find a reference class for.
Returns:
The corresponding subclass of ObjectReference, or null if one can't be found

addTarget

private void addTarget(ClassInfo info)
                throws WTException
Called by the constructor to build up the persistableTypesToReferenceTypes map

Throws:
WTException

getPersistableTypeByIntrospection

static Class getPersistableTypeByIntrospection(ClassInfo info)
                                        throws WTException
Tries to use introspection to get the Persistsble object type that corresponds to the given reference type, by looking at the references CONSTRAINED_TYPE property

Returns:
The matching Persistable Class, or null if it couldn't be found
Throws:
WTException

getFactoryMethod

static Method getFactoryMethod(Class object_class,
                               Class parameter_class)
Tries to use reflection to get a system-generated factory method for the given object type that has the given parameter type.

Parameters:
object_class - The class to find a factory method for
parameter_class - The class of parameter the method should have
Returns:
The matching factory method, or null if it couldn't be found

getFactoryMethodName

static String getFactoryMethodName(Class reference_class)
Gets the system-generated factory method for the given class

Parameters:
reference_class - A Class that ObjectReference is assignable from
Returns:
String