net.sf.morph.reflect.reflectors
Class SimpleInstantiatingReflector

java.lang.Object
  extended by net.sf.morph.reflect.reflectors.BaseReflector
      extended by net.sf.morph.reflect.reflectors.SimpleInstantiatingReflector
All Implemented Interfaces:
net.sf.composite.Component, DecoratedReflector, InstantiatingReflector, Reflector

public class SimpleInstantiatingReflector
extends BaseReflector
implements InstantiatingReflector

A basic instantiating reflector that allows an arbitrary number of requested class types to be mapped to instantiated types. The default instance of this class can instantiate common interfaces such as Calendar and CharSequence.

Since:
Feb 27, 2005
Author:
Matt Sgarlata

Field Summary
 
Fields inherited from class net.sf.morph.reflect.reflectors.BaseReflector
log
 
Constructor Summary
SimpleInstantiatingReflector()
          Create a new SimpleInstantiatingReflector.
SimpleInstantiatingReflector(java.lang.Class instantiatedType)
          Create a new SimpleInstantiatingReflector for a single type.
SimpleInstantiatingReflector(java.lang.Class requestedType, java.lang.Class instantiatedType)
          Create a new SimpleInstantiatingReflector for a single type mapping.
SimpleInstantiatingReflector(java.util.Map requestedToInstantiatedClassMap)
          Create a new SimpleInstantiatingReflector for the specified type map.
 
Method Summary
 java.lang.Class getInstantiatedType()
          Returns the instantiated type if only a single mapping of requested type to instantiated type has been specified.
protected  java.lang.Class[] getReflectableClassesImpl()
          Implementation of Reflector.getReflectableClasses().
 java.util.Map getRequestedToInstantiatedTypeMap()
          Returns the mapping of requested types to instantiated types.
 java.lang.Class getRequestedType()
          Returns the requested type if only a single mapping of requested type to instantiated type has been specified.
protected  java.lang.Object newInstanceImpl(java.lang.Class requestedType, java.lang.Object parameters)
          Implementation of InstantiatingReflector.newInstance(Class, Object).
 void setInstantiatedType(java.lang.Class instantiatedType)
          Sets the instantiated type if only a single mapping of requested type to instantiated type is needed.
 void setRequestedToInstantiatedTypeMap(java.util.Map interfaceToImplementationMap)
          Sets the mapping of requested types to instantiated types.
 void setRequestedType(java.lang.Class requestedType)
          Sets the requested type if only a single mapping of requested type to instantiated type is needed.
 
Methods inherited from class net.sf.morph.reflect.reflectors.BaseReflector
add, addImpl, checkIndex, checkIsReflectable, createWrapperInvocationHandler, get, get, getContainedType, getContainedTypeImpl, getImpl, getImpl, getIterator, getIteratorImpl, getPropertyNames, getPropertyNamesImpl, getReflectableCallCache, getReflectableClasses, getReflectorName, getSize, getSizeImpl, getType, getTypeImpl, getWrapper, getWrapperImpl, initialize, initializeImpl, isCachingIsReflectableCalls, isInitialized, isPerformingLogging, isReadable, isReadableImpl, isReflectable, isReflectable, isReflectableImpl, isReflectableImpl, isStrictlyTyped, isValidIndex, isWrappingRuntimeExceptions, isWriteable, isWriteableImpl, newInstance, newInstanceImpl, set, set, setCachingIsReflectableCalls, setImpl, setImpl, setInitialized, setReflectableCallCache, setReflectorName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.morph.reflect.InstantiatingReflector
newInstance
 
Methods inherited from interface net.sf.morph.reflect.Reflector
getReflectableClasses, getWrapper
 

Constructor Detail

SimpleInstantiatingReflector

public SimpleInstantiatingReflector()
Create a new SimpleInstantiatingReflector.


SimpleInstantiatingReflector

public SimpleInstantiatingReflector(java.lang.Class instantiatedType)
Create a new SimpleInstantiatingReflector for a single type.

Parameters:
instantiatedType -

SimpleInstantiatingReflector

public SimpleInstantiatingReflector(java.lang.Class requestedType,
                                    java.lang.Class instantiatedType)
Create a new SimpleInstantiatingReflector for a single type mapping.

Parameters:
requestedType -
instantiatedType -

SimpleInstantiatingReflector

public SimpleInstantiatingReflector(java.util.Map requestedToInstantiatedClassMap)
Create a new SimpleInstantiatingReflector for the specified type map.

Parameters:
requestedToInstantiatedClassMap -
Method Detail

getReflectableClassesImpl

protected java.lang.Class[] getReflectableClassesImpl()
                                               throws java.lang.Exception
Implementation of Reflector.getReflectableClasses().

Specified by:
getReflectableClassesImpl in class BaseReflector
Throws:
java.lang.Exception
See Also:
BaseReflector.getReflectableClassesImpl()

newInstanceImpl

protected java.lang.Object newInstanceImpl(java.lang.Class requestedType,
                                           java.lang.Object parameters)
                                    throws java.lang.Exception
Implementation of InstantiatingReflector.newInstance(Class, Object). Default implementation returns a new instance of the given class by calling Class#newInstance()).

Overrides:
newInstanceImpl in class BaseReflector
Throws:
java.lang.Exception
See Also:
BaseReflector.newInstanceImpl(java.lang.Class, java.lang.Object)

getInstantiatedType

public final java.lang.Class getInstantiatedType()
Returns the instantiated type if only a single mapping of requested type to instantiated type has been specified.

Returns:
the instantiated type, if one has been specified or
null if no instantiated type has been specified
Throws:
java.lang.IllegalStateException - if there is more than one mapping of requested type to instantiated type

setInstantiatedType

public final void setInstantiatedType(java.lang.Class instantiatedType)
Sets the instantiated type if only a single mapping of requested type to instantiated type is needed.

Parameters:
instantiatedType - the instantiated type

getRequestedType

public final java.lang.Class getRequestedType()
Returns the requested type if only a single mapping of requested type to instantiated type has been specified.

Returns:
the requested type, if one has been specified or
null if no requested type has been specified
Throws:
java.lang.IllegalStateException - if there is more than one mapping of requested type to instantiated type

setRequestedType

public final void setRequestedType(java.lang.Class requestedType)
Sets the requested type if only a single mapping of requested type to instantiated type is needed.

Parameters:
requestedType - the requested type

getRequestedToInstantiatedTypeMap

public java.util.Map getRequestedToInstantiatedTypeMap()
Returns the mapping of requested types to instantiated types.

Returns:
the mapping of requested types to instantiated types

setRequestedToInstantiatedTypeMap

public void setRequestedToInstantiatedTypeMap(java.util.Map interfaceToImplementationMap)
Sets the mapping of requested types to instantiated types.

Parameters:
interfaceToImplementationMap - the mapping of requested types to instantiated types


Copyright © 2004-2008.