|
Docmosis API 4.5.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.docmosis.template.population.ReflectiveDataProvider
This data provider uses reflection to try to obtain data from within an arbitrary given object. The reflection can be forgiving which means that if the contained object cannot provide the information then null values are assumed. If set to unforgiving, Runtime Exceptions will be thrown if the delegate object does not have a method to obtain the required value. Unforgiving might be helpful when debugging or developing.
Nested Class Summary | |
protected static class |
ReflectiveDataProvider.DataFormatManager
A Manager of data formats that are applied to the results of reflective calls to format the data before it is passed into the render process. |
Field Summary | |
protected ReflectiveDataProvider.DataFormatManager |
dataFormatManager
|
protected boolean |
forgiving
|
protected static MethodReflectionHelper |
METHOD_REFLECTION_HELPER
|
protected Object |
reflectedDelegate
|
protected Class |
reflectedDelegateClass
|
Constructor Summary | |
protected |
ReflectiveDataProvider(Object delegate,
boolean forgiving,
ReflectiveDataProvider.DataFormatManager dataFormatManager)
Construct a new Reflective Data Provider that will pull data out of the given delegate. |
Method Summary | |
abstract boolean |
getBoolean(String fieldName)
Get the boolean value from the reflected delegate. |
abstract DataProvider |
getDataProvider(String fieldName,
int idx)
Get the data provider from the reflected delegate. |
abstract int |
getDataProviderCount(String fieldName)
Get the data provider count from the reflected delegate. |
Object |
getDelegate()
Return the delegate inside this Reflective Data Provider. |
abstract InputStream |
getImage(String fieldName)
Get the image from the reflected delegate. |
static ReflectiveDataProvider |
getInstance(Object delegate)
Obtain a new Reflective Data Provider that will pull data out of the given delegate. |
static ReflectiveDataProvider |
getInstance(Object delegate,
boolean forgiving)
obtain a new Reflective Data Provider that will pull data out of the given delegate. |
abstract String |
getString(String fieldName)
Get the String from the reflected delegate. |
static ReflectiveDataProvider |
getWrappedInstance(Object delegate)
Obtain a new Reflective Data Provider that will pull data out of the given delegate. |
abstract boolean |
hasBooleanKey(String fieldName)
Determine if the boolean key has been set. |
abstract boolean |
hasDataProviderKey(String fieldName)
Determine if the data provider key has been set. |
abstract boolean |
hasImageKey(String fieldName)
Determine if the image key has been set. |
abstract boolean |
hasStringKey(String fieldName)
Determine if the String key has been set. |
boolean |
isForgiving()
Determine if this instance is forgiving or not. |
protected static boolean |
isPrimitive(Object o)
Determine if the given object is one of the "primitive" java types. |
protected static boolean |
isPrimitiveArray(Object o)
Determine if the given object is one of the "primitive" java array types. |
protected void |
logCall(Logger log,
String methodName,
String fieldName)
Log a call to any of the retrieval methods. |
protected void |
logCall(Logger log,
String methodName,
String fieldName,
int index)
Log a call to any of the retrieval methods. |
void |
setDataFormatter(Class type,
DataFormatter formatter)
Set the formatter for the given class type. |
void |
setDateFormat(SimpleDateFormat dateFormat)
Set the Date Format to use when rendering dates as Strings. |
void |
setDateFormat(String formatString)
Set the Date Format to use a SimpleDateFormat using the given format string as the format. |
String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected static final MethodReflectionHelper METHOD_REFLECTION_HELPER
protected final Object reflectedDelegate
protected final Class reflectedDelegateClass
protected final boolean forgiving
protected final ReflectiveDataProvider.DataFormatManager dataFormatManager
Constructor Detail |
protected ReflectiveDataProvider(Object delegate, boolean forgiving, ReflectiveDataProvider.DataFormatManager dataFormatManager)
delegate
- the object from which to retrieve informationforgiving
- if true, failure to reflectively locate a method
on the delegate fails quietly. If false, Runtime Exceptions
will be thrown.Method Detail |
public static ReflectiveDataProvider getInstance(Object delegate)
delegate
- the object from which to retrieve informationpublic static ReflectiveDataProvider getWrappedInstance(Object delegate)
delegate
- the object from which to retrieve informationpublic static ReflectiveDataProvider getInstance(Object delegate, boolean forgiving)
delegate
- the object from which to retrieve informationforgiving
- if true, failure to reflectively locate a method
on the delegate fails quietly. If false, Runtime Exceptions
will be thrown.public Object getDelegate()
public boolean isForgiving()
public abstract boolean hasBooleanKey(String fieldName)
hasBooleanKey
in interface DataProvider
fieldName
- the name of the field to use for reflection
public abstract boolean getBoolean(String fieldName)
getBoolean
in interface DataProvider
fieldName
- the key to lookup
DataProvisionNotFoundException
- if the reflected method cannot be found and we are not forgiving.
DataProvisionFetchException
- if the reflection fails for security or runtime reasons.public abstract boolean hasDataProviderKey(String fieldName)
hasDataProviderKey
in interface DataProvider
fieldName
- the name of the field to use for reflection
public abstract DataProvider getDataProvider(String fieldName, int idx)
getDataProvider
in interface DataProvider
fieldName
- the key (name) of the data provider to look for.idx
- the index of the data provider.
DataProvisionNotFoundException
- if the reflected method cannot be found and we are not forgiving.
DataProvisionFetchException
- if the reflection fails for security or runtime reasons.public abstract int getDataProviderCount(String fieldName)
getDataProviderCount
in interface DataProvider
fieldName
- the key (name) of the data providers to look for.
DataProvisionNotFoundException
- if the reflected method cannot be found and we are not forgiving.
DataProvisionFetchException
- if the reflection fails for security or runtime reasons.public abstract boolean hasImageKey(String fieldName)
hasImageKey
in interface DataProvider
fieldName
- the name of the field to use for reflection
public abstract InputStream getImage(String fieldName)
getImage
in interface DataProvider
fieldName
- the key under which to locate the image.
DataProvisionNotFoundException
- if the reflected method cannot be found and we are not forgiving.
DataProvisionFetchException
- if the reflection fails for security or runtime reasons.public abstract boolean hasStringKey(String fieldName)
hasStringKey
in interface DataProvider
fieldName
- the name of the field to use for reflection
public abstract String getString(String fieldName) throws DataProvisionNotFoundException
getString
in interface DataProvider
fieldName
- the to look up the value
DataProvisionNotFoundException
- if the reflected method cannot be found and we are not forgiving.
DataProvisionFetchException
- if the reflection fails for security or runtime reasons.public void setDataFormatter(Class type, DataFormatter formatter)
type
- the class to register the formatter againstformatter
- the formatter to use. Specify null to clear the
formatterDataFormatter
public void setDateFormat(SimpleDateFormat dateFormat)
dateFormat
- specify null to use the Java default date formatpublic void setDateFormat(String formatString)
formatString
- protected static boolean isPrimitive(Object o)
o
-
protected static boolean isPrimitiveArray(Object o)
o
-
protected void logCall(Logger log, String methodName, String fieldName)
log
- the logger to log to.methodName
- the name of the method being called.fieldName
- the name of the field being called.protected void logCall(Logger log, String methodName, String fieldName, int index)
log
- the logger to log to.methodName
- the name of the method being called.fieldName
- the name of the field being called.index
- the index of the field (if applicable).public String toString()
|
Docmosis API 4.5.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |