Docmosis API 4.5.0

com.docmosis.template.population
Class DataProviderFactory

java.lang.Object
  extended bycom.docmosis.template.population.DataProviderFactory

public class DataProviderFactory
extends Object

A convenience class for creating, building and extending DataProviders to feed templates.


Constructor Summary
DataProviderFactory()
           
 
Method Summary
static SQLDataProvider addToDataProvider(SQLDataProvider mdp, ResultSet results, DataProviderGrouping[] grouping)
          Alter a hierarchical data provider by adding data based on a given SQL result set.
static SQLDataProvider addToDataProvider(SQLDataProvider dp, ResultSet results, String dpRowName)
          Alter a simple data provider by adding data based on a given SQL result set.
static CompoundDataProvider createCompoundDataProvider(DataProvider[] providers)
          Create a CompoundDataProvider from the given array of DataProviders.
static CompoundDataProvider createCompoundDataProvider(List providers)
          Create a CompoundDataProvider from the given List of Objects.
static ReflectiveDataProvider createDataProvider(Object delegate)
          Create a Reflective data provider that extracts data from the given This data providers is forgiving (see ReflectiveDataProvider for more details).
static ReflectiveDataProvider createDataProvider(Object delegate, boolean forgiving)
          Create a Reflective data provider that extracts data from the given Object and is optionally forgiving (see ReflectiveDataProvider for more details).
static SQLDataProvider createDataProvider(ResultSet results, DataProviderGrouping[] grouping)
          Create a hierarchical data provider for a given SQL result set.
static SQLDataProvider createDataProvider(ResultSet results, String dpRowName)
          Create a simple data provider for a given SQL result set.
static MutableDataProvider createDataProvider(String[][] keyValuePairs)
          Create a hierarchical data provider for the given arrangement of key value pairs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataProviderFactory

public DataProviderFactory()
Method Detail

createDataProvider

public static SQLDataProvider createDataProvider(ResultSet results,
                                                 String dpRowName)
                                          throws SQLException
Create a simple data provider for a given SQL result set. The data provider will be in the following shape: (main-data-provider) ---+--- (row-data-provider[0]) (field-1) (field-2) ... (field-n) | +--- (row-data-provider[1]) (field-1) (field-2) ... (field-n) | | ... | +--- (row-data-provider[i]) (field-1) (field-2) ... (field-n) An example of how to access a string from a field called "myField" from the third row where the rows are called "myRow", would be: dataProvider.getDataProvider("myRow", 2).getString("myField");

Parameters:
results - the result set to populate the data provider with.
dpRowName - the name of the data provider for each row in the result set. In the diagram, this is the name of the data provider denoted by (row-data-provider).
Returns:
a populated data provider.
Throws:
SQLException - if an error occurs reading from the result set.

addToDataProvider

public static SQLDataProvider addToDataProvider(SQLDataProvider dp,
                                                ResultSet results,
                                                String dpRowName)
                                         throws SQLException
Alter a simple data provider by adding data based on a given SQL result set. The data provider will be in the following shape: (main-data-provider) ---+--- (row-data-provider[0]) (field-1) (field-2) ... (field-n) | +--- (row-data-provider[1]) (field-1) (field-2) ... (field-n) | | ... | +--- (row-data-provider[i]) (field-1) (field-2) ... (field-n) An example of how to access a string from a field called "myField" from the third row where the rows are called "myRow", would be: dataProvider.getDataProvider("myRow", 2).getString("myField");

Parameters:
dp - the SQL data provider to alter. This is mutated to the very same as the return value.
results - he result set to populate the data provider with.
dpRowName - the name of the data provider for each row in the result set. In the diagram, this is the name of the data provider denoted by (row-data-provider).
Returns:
the altered memory data provider.
Throws:
SQLException - if an error occurs reading from the result set.

createDataProvider

public static SQLDataProvider createDataProvider(ResultSet results,
                                                 DataProviderGrouping[] grouping)
                                          throws SQLException,
                                                 DataProviderGroupingException
Create a hierarchical data provider for a given SQL result set. This is used to populate templates with nested levels of data and the grouping parameter provides the way to identify nesting/discriminating fields.

Parameters:
results - the result set to populate the data provider with.
grouping - the various groupings for the data to be laid out in. Each element in the array represents the parent group of the next element.
Returns:
a populated data provider.
Throws:
SQLException - if an error occurs reading from the result set.
DataProviderGroupingException - if the groupings are invalid.

addToDataProvider

public static SQLDataProvider addToDataProvider(SQLDataProvider mdp,
                                                ResultSet results,
                                                DataProviderGrouping[] grouping)
                                         throws SQLException,
                                                DataProviderGroupingException
Alter a hierarchical data provider by adding data based on a given SQL result set.

Parameters:
mdp - the memory data provider to alter. This is mutated to the very same as the return value.
results - he result set to populate the data provider with.
Returns:
the altered memory data provider.
Throws:
SQLException - if an error occurs reading from the result set.
DataProviderGroupingException

createDataProvider

public static ReflectiveDataProvider createDataProvider(Object delegate)
Create a Reflective data provider that extracts data from the given This data providers is forgiving (see ReflectiveDataProvider for more details).

Parameters:
delegate - the object to reflect upon to get values.
Returns:
a reflective data provider.
See Also:
ReflectiveDataProvider

createDataProvider

public static ReflectiveDataProvider createDataProvider(Object delegate,
                                                        boolean forgiving)
Create a Reflective data provider that extracts data from the given Object and is optionally forgiving (see ReflectiveDataProvider for more details).

Parameters:
delegate - the object to reflect upon to get values.
forgiving - if false, any call into the delegate that results in no data being found throws an IllegalArgumentException (mostly for debugging)
Returns:
a reflective data provider.
See Also:
ReflectiveDataProvider

createCompoundDataProvider

public static CompoundDataProvider createCompoundDataProvider(DataProvider[] providers)
Create a CompoundDataProvider from the given array of DataProviders. Each provider in the array OVERRIDES the one following so a CompoundDataProvider acts as if it contains one DataProvider and extracts values from the first provider that contains information.

Parameters:
providers - the DataProviders to compound into one DataProvider
Returns:
a CompoundDataProvider
See Also:
CompoundDataProvider

createCompoundDataProvider

public static CompoundDataProvider createCompoundDataProvider(List providers)
Create a CompoundDataProvider from the given List of Objects. Each provider in the array OVERRIDES the one following so a CompoundDataProvider acts as if it contains one DataProvider and extracts values from the first provider that contains information. If any object in the List is not a DataProvider, it will be wrapped in a ReflectiveDataProvider to extract its information.

Parameters:
providers - the DataProviders to compound into one DataProvider
Returns:
a CompoundDataProvider
See Also:
CompoundDataProvider

createDataProvider

public static MutableDataProvider createDataProvider(String[][] keyValuePairs)
Create a hierarchical data provider for the given arrangement of key value pairs.

Parameters:
keyValuePairs - the key value pairs where the key is a flat mapping to get to a hierarchically structured part of the memory data provider. The value is the actual value for the key.
Returns:
a populated data provider.

Docmosis API 4.5.0

Copyright © 2014 Docmosis Pty Ltd. All Rights Reserved.