Docmosis API 4.5.0

com.docmosis.template.population
Class CompoundDataProvider

java.lang.Object
  extended bycom.docmosis.template.population.CompoundDataProvider
All Implemented Interfaces:
DataProvider, Serializable

public class CompoundDataProvider
extends Object
implements DataProvider, Serializable

A DataProvider that provides a "chain" of data providers. The DataProviders are used in the order they are added, so the first data provider will be used to supply a value in preference to the Data Provider added second, and so on. This allows arbitrary data providers to be linked together in a priority order.
To determine if a data provider can provide a value, the has*Key() methods are used. If has*Key() returns true for a DataProvider, then that DataProvider will be used. This allows a data provider to override values in another data provider, even with null/zero values.
Also, some methods allow arbitrary Objects to be added. Objects added via these methods will automatically be wrapped in a ReflectiveDataProvider if the Object does not already implement DataProvider.

See Also:
Serialized Form

Constructor Summary
CompoundDataProvider()
           
 
Method Summary
 CompoundDataProvider addDataObject(Object dp)
          Add an arbitrary object as a data provider to this compound provider.
 CompoundDataProvider addDataObject(Object dp, boolean forgiving)
          Add an arbitrary object as a data provider to this compound provider.
 CompoundDataProvider addDataProvider(DataProvider dp)
          Add a data provider to this compound provider.
 CompoundDataProvider addDataProviders(DataProvider[] dps)
          Add an array of DataProviders to this compound provider.
 CompoundDataProvider addDataProviders(List dps)
          Add a List of arbitrary objects as data providers to this compound provider.
 boolean getBoolean(String key)
          Return the value from the first data provider that has a boolean for the given key.
 DataProvider getDataProvider(String key, int index)
          Return the value from the first data provider that has a DataProvider for the given key.
 int getDataProviderCount(String key)
          Return the value from the first data provider that has a DataProvider for the given key.
 InputStream getImage(String key)
          Return the value from the first data provider that has an image for the given key.
 DataProvider getLastDataProvider()
          Get the last DataProvider in the compounded set of data providers
 String getString(String key)
          Return the value from the first data provider that has a String for the given key.
 boolean hasBooleanKey(String key)
          Return true if any data provider has a boolean for the given key
 boolean hasDataProviderKey(String key)
          Return true if any data provider has a DataProvider for the given key
 boolean hasImageKey(String key)
          Return true if any data provider has an image for the given key
 boolean hasStringKey(String key)
          Return true if any data provider has a String for the given key
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompoundDataProvider

public CompoundDataProvider()
Method Detail

addDataProvider

public CompoundDataProvider addDataProvider(DataProvider dp)
Add a data provider to this compound provider.

Parameters:
dp - the data provider to add
Returns:
this instance for convenience
Throws:
IllegalArgumentException - if the given DataProvider is null

getLastDataProvider

public DataProvider getLastDataProvider()
Get the last DataProvider in the compounded set of data providers

Returns:
null if there are none.

addDataObject

public CompoundDataProvider addDataObject(Object dp)
Add an arbitrary object as a data provider to this compound provider. If the object is not a DataProvider it will be wrapped in a ReflectiveDataProvider to extract its information. If a ReflectiveDataProvider is created, it will be in forgiving mode.

Parameters:
dp - the object to add as a data provider
Returns:
this instance for convenience
Throws:
IllegalArgumentException - if the given Object is null

addDataObject

public CompoundDataProvider addDataObject(Object dp,
                                          boolean forgiving)
Add an arbitrary object as a data provider to this compound provider. If the object is not a DataProvider it will be wrapped in a ReflectiveDataProvider to extract its information. If a ReflectiveDataProvider is created, it's forgiving mode will be that specified.

Parameters:
dp - the object to add as a data provider
forgiving - the mode to set for an created ReflectiveDataProvider
Returns:
this instance for convenience
Throws:
IllegalArgumentException - if the given Object is null

addDataProviders

public CompoundDataProvider addDataProviders(DataProvider[] dps)
Add an array of DataProviders to this compound provider.

Parameters:
dps - the array to add as a data providers
Returns:
this instance for convenience
Throws:
IllegalArgumentException - if the given array is null or contains a null item

addDataProviders

public CompoundDataProvider addDataProviders(List dps)
Add a List of arbitrary objects as data providers to this compound provider. If an object is not a DataProvider it will be wrapped in a ReflectiveDataProvider to extract its information.

Parameters:
dps - the List of objects to add as data providers
Returns:
this instance for convenience
Throws:
IllegalArgumentException - if the given List is null or contains a null element

getBoolean

public boolean getBoolean(String key)
Return the value from the first data provider that has a boolean for the given key.

Specified by:
getBoolean in interface DataProvider
Parameters:
key - the key to lookup
Returns:
false if the key is not set or has not been set to true
See Also:
DataProvider.getBoolean(String)

getDataProvider

public DataProvider getDataProvider(String key,
                                    int index)
Return the value from the first data provider that has a DataProvider for the given key.

Specified by:
getDataProvider in interface DataProvider
Parameters:
key - the key (name) of the data provider to look for.
index - the index of the data provider.
Returns:
a data provider.
See Also:
DataProvider.getDataProvider(String, int)

getDataProviderCount

public int getDataProviderCount(String key)
Return the value from the first data provider that has a DataProvider for the given key.

Specified by:
getDataProviderCount in interface DataProvider
Parameters:
key - the key (name) of the data providers to look for.
Returns:
the number of data providers.
See Also:
DataProvider.getDataProviderCount(String)

getImage

public InputStream getImage(String key)
Return the value from the first data provider that has an image for the given key.

Specified by:
getImage in interface DataProvider
Parameters:
key - the key under which to locate the image.
Returns:
null if the image cannot be found
See Also:
DataProvider.getImage(String)

getString

public String getString(String key)
Return the value from the first data provider that has a String for the given key.

Specified by:
getString in interface DataProvider
Parameters:
key - the to look up the value
Returns:
the String value or null
See Also:
DataProvider.getString(String)

hasBooleanKey

public boolean hasBooleanKey(String key)
Return true if any data provider has a boolean for the given key

Specified by:
hasBooleanKey in interface DataProvider
Parameters:
key - the key to lookup
Returns:
true if the boolean value has been set, regardless of what the value is.
See Also:
DataProvider.hasBooleanKey(String)

hasDataProviderKey

public boolean hasDataProviderKey(String key)
Return true if any data provider has a DataProvider for the given key

Specified by:
hasDataProviderKey in interface DataProvider
Parameters:
key - the key with which to lookup the data provider
Returns:
true if a data provider has been set for the given key, even if null
See Also:
DataProvider.hasDataProviderKey(String)

hasImageKey

public boolean hasImageKey(String key)
Return true if any data provider has an image for the given key

Specified by:
hasImageKey in interface DataProvider
Parameters:
key - the key for the String
Returns:
true if the key has been set.
See Also:
DataProvider.hasImageKey(String)

hasStringKey

public boolean hasStringKey(String key)
Return true if any data provider has a String for the given key

Specified by:
hasStringKey in interface DataProvider
Parameters:
key - the key for the String
Returns:
true if the key has been set.
See Also:
DataProvider.hasStringKey(String)

toString

public String toString()

Docmosis API 4.5.0

Copyright © 2014 Docmosis Pty Ltd. All Rights Reserved.