com.fdsapi.arrays
Class ArrayConverterFactory

java.lang.Object
  |
  +--com.fdsapi.arrays.ArrayConverterFactory
All Implemented Interfaces:
java.lang.Cloneable

public class ArrayConverterFactory
extends java.lang.Object
implements java.lang.Cloneable

This class returns an array of Converter objects to be used in Converting an array based on the rules speicied below. This class is not thread safe, however if the factory elements are set at say application startup then it can be used in a thread safe manner. When looking up which Converter to use for each column in the array the following precedence order is used: 1) If a Converter was registered for the column. This can done by either column number or column name. In the case where both a column number and column name Converter were specified (a tie) the last one that was registered will be used. 2) If a Converter was registered for the column data type then use that Converter. The first cell within the column is used to get the data type. If the value is a null then there is no type. The most specific data type is matched first and then the inheritance chain is walked to find a match. If there is still no match then the interface tree is walked looking for a match. If there is still no match then an attempt is made to match Object.class. If there is no matches then proceed to the next step. 3) If there have been no matches to this point then the overall default Converter is used.

View Code


Constructor Summary
ArrayConverterFactory()
          default constructor
 
Method Summary
 java.lang.Object clone()
          Clone this factory
 ArrayConverterFactory copy()
          Clones this factory and returns it as the factory type.
 Converter[] getConverters(ArrayHeaderLocator colNameLocator, java.lang.Object[][] data)
          This method returns an array of Converter objects.
static java.lang.Class[] getTypes(java.lang.Object obj)
          This method returns an array of the classes and interfaces that the passed in Object extends or implements.
static void main(java.lang.String[] args)
          Test and sample usage code
 void removeColConverter(int colNum)
          Remove the column Converter associated with the column number.
 void removeColConverter(java.lang.String colName)
          Remove the column Converter associated with the column name
 void removeTypeConverter(java.lang.Class type)
          Remove the Converter associated with the data type
 void setColConverter(int colNum, Converter converter)
          Set the column Converter by number.
 void setColConverter(java.lang.String colName, Converter converter)
          Set the column Converter by name.
 void setDefaultConverter(Converter converter)
          Set the Converter to be used if no other matches occur based on column, or data type
 void setTypeConverter(java.lang.Class type, Converter converter)
          Set the column Converter by data type.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArrayConverterFactory

public ArrayConverterFactory()
default constructor

Method Detail

setDefaultConverter

public void setDefaultConverter(Converter converter)
Set the Converter to be used if no other matches occur based on column, or data type


setColConverter

public void setColConverter(int colNum,
                            Converter converter)
Set the column Converter by number. This Converter will be used by any data within this column


removeColConverter

public void removeColConverter(int colNum)
Remove the column Converter associated with the column number.


setColConverter

public void setColConverter(java.lang.String colName,
                            Converter converter)
Set the column Converter by name. This Converter will be used by any data within this column


removeColConverter

public void removeColConverter(java.lang.String colName)
Remove the column Converter associated with the column name


setTypeConverter

public void setTypeConverter(java.lang.Class type,
                             Converter converter)
Set the column Converter by data type. This Converter will be used by any data that matches this Data type rules subject to the rules specified above.


removeTypeConverter

public void removeTypeConverter(java.lang.Class type)
Remove the Converter associated with the data type


getConverters

public Converter[] getConverters(ArrayHeaderLocator colNameLocator,
                                 java.lang.Object[][] data)
This method returns an array of Converter objects. The array will have a Converter for each column in the Array that was passed in. The arrayHeaderLocator is used to associate Converters that were registered by column name to the data.


getTypes

public static java.lang.Class[] getTypes(java.lang.Object obj)
This method returns an array of the classes and interfaces that the passed in Object extends or implements.


clone

public java.lang.Object clone()
Clone this factory

Overrides:
clone in class java.lang.Object

copy

public ArrayConverterFactory copy()
Clones this factory and returns it as the factory type. This is useful if you want to reuse part of a factory and make changes/additions to it


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
Test and sample usage code