com.businessobjects.samples.pojo
Class POJOResultSetFactory

java.lang.Object
  |
  +--com.businessobjects.samples.pojo.POJOResultSetFactory

public class POJOResultSetFactory
extends java.lang.Object

Provides "Plain Old Java Object" reporting abilities, allowing users' application domain objects to be used directly for report generation via result sets. Only simple tables are currently supported. By default, reflection is used, such that for the domain class, all class field and methods are traversed, and all members for which shouldReport() is true are included in the result set. Class members with non-reportable data are quietly ignored. Assumes all public fields, and all no-argument public methods that return a reportable type, should be included in the report. Super classes are also processed up to but not including java.lang.Object. For domain classes that are actually interfaces, the entire interface hierarchy is traversed.


Constructor Summary
POJOResultSetFactory(java.lang.Class domainClass)
           
 
Method Summary
 POJOResultSet createResultSet(java.util.Collection domainData)
          Creates a result set from the domain data, using report fields as implied by the domain class.
 POJOResultSet createResultSet(java.lang.Object[] domainData)
           
 java.lang.String defaultColumnNameOf(java.lang.reflect.Field field)
          Returns the default column name to used to identify the Java field.
 java.lang.String defaultColumnNameOf(java.lang.reflect.Method method, java.lang.String[] prefixes)
          Returns the default column name to use for the Java method.
 java.lang.Class domainClass()
          Specifies the domain class being analyzed.
 java.lang.String[] getExcludedMembers()
          Describes the fields or methods to explicitly exclude from the report.
 java.lang.String[] getExplicitMembers()
          If non-empty, describes the explicit set of class members that are desired for use in the result set, overriding the default member processing.
 java.lang.String[] getIncludedMembers()
          Describes the fields or methods to explicitly include in the report, in addition to those picked up by the normal processing rules.
 java.lang.String[] getIncludedMethodPrefixes()
          Returns the set of prefixes that specify what methods to consider.
 int getMemberColumnDisplaySize(java.lang.String memberName, java.lang.Class columnType)
          Returns number of characters needed to display the member's values.
 java.lang.String getMemberColumnLabel(java.lang.String memberName)
          Specifies the value to use for column label associated with the member.
 java.lang.String getMemberColumnName(java.lang.String memberName)
          Specifies the value to use for column name associated with the member.
 int getMemberColumnPrecision(java.lang.String memberName, java.lang.Class columnType)
          Returns number of digits of precision needed to display the member's values.
 int getMemberColumnScale(java.lang.String memberName, java.lang.Class columnType)
          Returns number of digits to the right of the decimal point to use for this member's values.
 POJOResultSetMetaData getMetaData()
          Returns a result set meta data description of the domain class, using result set columns as implied by the domain class' "reportable" fields and methods.
 java.lang.String getTableName()
          Specifies the table name to use in the result set.
static boolean isBoolean(java.lang.Class type)
           
static boolean isByte(java.lang.Class type)
           
static boolean isChar(java.lang.Class type)
           
 boolean isCurrencyMember(java.lang.String memberName)
          Specifies if this member is to be considered as a currency value.
static boolean isDouble(java.lang.Class type)
           
static boolean isFloat(java.lang.Class type)
           
static boolean isInt(java.lang.Class type)
           
static boolean isIntegerType(java.lang.Class type)
           
static boolean isLong(java.lang.Class type)
           
static boolean isNumberType(java.lang.Class type)
           
static boolean isRealType(java.lang.Class type)
           
 boolean isReportable(java.lang.Class type)
          Returns true members with the specified type can be included in the result set.
 boolean isReportable(java.lang.reflect.Field field)
          Returns true if the field is public, non-static, non-final and of a reportable type.
 boolean isReportable(java.lang.reflect.Method method)
          Returns true if the method is public, non-static, returns a reportable type, and has no arguments.
static boolean isShort(java.lang.Class type)
           
static boolean isType(java.lang.Class type, java.lang.Class[] inTypes)
           
 void setCurrencyMember(java.lang.String memberName, boolean toCurrency)
           
 void setExcludedMembers(java.lang.String[] toMembers)
           
 void setExplicitMembers(java.lang.String[] toMembers)
           
 void setIncludedMembers(java.lang.String[] toMembers)
           
 void setIncludedMethodPrefixes(java.lang.String[] toPrefixes)
           
 void setMemberColumnDisplaySize(java.lang.String memberName, int toDisplaySize)
           
 void setMemberColumnLabel(java.lang.String memberName, java.lang.String toColumnLabel)
           
 void setMemberColumnName(java.lang.String memberName, java.lang.String toColumnName)
           
 void setMemberColumnPrecision(java.lang.String memberName, int toPrecision)
           
 void setMemberColumnScale(java.lang.String memberName, int toScale)
           
 void setTableName(java.lang.String toName)
           
 void setVerbose(boolean toVerbose)
          If true, informative status about the domain class processing is reported.
 boolean shouldReport(java.lang.reflect.Field field)
          Controls what fields are included in reports.
 boolean shouldReport(java.lang.reflect.Method method, java.lang.String[] prefixes)
          Controls what methods are included in reports.
static java.lang.String simpleNameOf(java.lang.Class c)
           
static int sqlTypeOf(java.lang.Class type)
          Returns the appropriate Types value for the type.
static void update(java.util.Map map, java.lang.String name, java.lang.Object withValue)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

POJOResultSetFactory

public POJOResultSetFactory(java.lang.Class domainClass)
Method Detail

setVerbose

public void setVerbose(boolean toVerbose)
If true, informative status about the domain class processing is reported.


domainClass

public java.lang.Class domainClass()
Specifies the domain class being analyzed.


getMetaData

public POJOResultSetMetaData getMetaData()
                                  throws POJOException
Returns a result set meta data description of the domain class, using result set columns as implied by the domain class' "reportable" fields and methods.

POJOException

createResultSet

public POJOResultSet createResultSet(java.util.Collection domainData)
                              throws POJOException
Creates a result set from the domain data, using report fields as implied by the domain class. Data object instances that are not compatible with the domain class are quietly ignored.

POJOException

createResultSet

public POJOResultSet createResultSet(java.lang.Object[] domainData)
                              throws POJOException
POJOException

isReportable

public boolean isReportable(java.lang.Class type)
Returns true members with the specified type can be included in the result set. By default the type is accepted if it is primitive, a primitive wrapper, or a string, or one of the java.sql types.


sqlTypeOf

public static int sqlTypeOf(java.lang.Class type)
Returns the appropriate Types value for the type.


isReportable

public boolean isReportable(java.lang.reflect.Method method)
Returns true if the method is public, non-static, returns a reportable type, and has no arguments.


isReportable

public boolean isReportable(java.lang.reflect.Field field)
Returns true if the field is public, non-static, non-final and of a reportable type.


shouldReport

public boolean shouldReport(java.lang.reflect.Field field)
Controls what fields are included in reports. All reportable fields are reported by default. Override to customize.

Note: reported fields must satisfy both isReportable() and shouldReport().


shouldReport

public boolean shouldReport(java.lang.reflect.Method method,
                            java.lang.String[] prefixes)
Controls what methods are included in reports. By default only methods that start with one of the specified prefixes are reported.

Note: reported methods must satisfy both isReportable() and shouldReport().

See Also:
getIncludedMethodPrefixes()

getExplicitMembers

public java.lang.String[] getExplicitMembers()
If non-empty, describes the explicit set of class members that are desired for use in the result set, overriding the default member processing.

See Also:
setExplicitMembers(String[])

setExplicitMembers

public void setExplicitMembers(java.lang.String[] toMembers)

getIncludedMembers

public java.lang.String[] getIncludedMembers()
Describes the fields or methods to explicitly include in the report, in addition to those picked up by the normal processing rules.

See Also:
setIncludedMembers(String[])

setIncludedMembers

public void setIncludedMembers(java.lang.String[] toMembers)

getExcludedMembers

public java.lang.String[] getExcludedMembers()
Describes the fields or methods to explicitly exclude from the report.

See Also:
setExcludedMembers(String[])

setExcludedMembers

public void setExcludedMembers(java.lang.String[] toMembers)

getIncludedMethodPrefixes

public java.lang.String[] getIncludedMethodPrefixes()
Returns the set of prefixes that specify what methods to consider. Defaults to just "get". If null, all reportable methods are considered. If non-null but empty, then no methods are considered.

See Also:
setIncludedMethodPrefixes(String[])

setIncludedMethodPrefixes

public void setIncludedMethodPrefixes(java.lang.String[] toPrefixes)

getTableName

public java.lang.String getTableName()
Specifies the table name to use in the result set. Defaults to the simple domain class name.

See Also:
setTableName(String)

setTableName

public void setTableName(java.lang.String toName)

defaultColumnNameOf

public java.lang.String defaultColumnNameOf(java.lang.reflect.Field field)
Returns the default column name to used to identify the Java field. By default this is just the field name itself. Override to customize.


defaultColumnNameOf

public java.lang.String defaultColumnNameOf(java.lang.reflect.Method method,
                                            java.lang.String[] prefixes)
Returns the default column name to use for the Java method. By default this is just the method name itself, except that any prefixes are stripped. Override to customize.


getMemberColumnName

public java.lang.String getMemberColumnName(java.lang.String memberName)
Specifies the value to use for column name associated with the member. If not previously set then null is returned, in which case the default column name for the member will be used.

See Also:
setMemberColumnName(String,String), defaultColumnNameOf(Field), defaultColumnNameOf(Method,String[])

setMemberColumnName

public void setMemberColumnName(java.lang.String memberName,
                                java.lang.String toColumnName)

getMemberColumnLabel

public java.lang.String getMemberColumnLabel(java.lang.String memberName)
Specifies the value to use for column label associated with the member. If not previously set then null is returned, in which case the column name for the member will be used.

See Also:
setMemberColumnLabel(String,String), getMemberColumnName(String)

setMemberColumnLabel

public void setMemberColumnLabel(java.lang.String memberName,
                                 java.lang.String toColumnLabel)

isCurrencyMember

public boolean isCurrencyMember(java.lang.String memberName)
Specifies if this member is to be considered as a currency value.

See Also:
setCurrencyMember(String,boolean)

setCurrencyMember

public void setCurrencyMember(java.lang.String memberName,
                              boolean toCurrency)

getMemberColumnDisplaySize

public int getMemberColumnDisplaySize(java.lang.String memberName,
                                      java.lang.Class columnType)
Returns number of characters needed to display the member's values. Defaults to 7 for integer types, 12 for long integer types, the precision + 1 for floating types, and 12 otherwise.

See Also:
setMemberColumnDisplaySize(String,int), getMemberColumnPrecision(String,Class)

setMemberColumnDisplaySize

public void setMemberColumnDisplaySize(java.lang.String memberName,
                                       int toDisplaySize)

getMemberColumnPrecision

public int getMemberColumnPrecision(java.lang.String memberName,
                                    java.lang.Class columnType)
Returns number of digits of precision needed to display the member's values. Defaults to 6 for floating types, otherwise 0.

See Also:
setMemberColumnPrecision(String,int)

setMemberColumnPrecision

public void setMemberColumnPrecision(java.lang.String memberName,
                                     int toPrecision)

getMemberColumnScale

public int getMemberColumnScale(java.lang.String memberName,
                                java.lang.Class columnType)
Returns number of digits to the right of the decimal point to use for this member's values. Defaults to 2 for floating types, otherwise 0.

See Also:
setMemberColumnScale(String,int)

setMemberColumnScale

public void setMemberColumnScale(java.lang.String memberName,
                                 int toScale)

isRealType

public static boolean isRealType(java.lang.Class type)

isIntegerType

public static boolean isIntegerType(java.lang.Class type)

isDouble

public static boolean isDouble(java.lang.Class type)

isFloat

public static boolean isFloat(java.lang.Class type)

isNumberType

public static boolean isNumberType(java.lang.Class type)

isLong

public static boolean isLong(java.lang.Class type)

isByte

public static boolean isByte(java.lang.Class type)

isShort

public static boolean isShort(java.lang.Class type)

isInt

public static boolean isInt(java.lang.Class type)

isChar

public static boolean isChar(java.lang.Class type)

isType

public static boolean isType(java.lang.Class type,
                             java.lang.Class[] inTypes)

isBoolean

public static boolean isBoolean(java.lang.Class type)

simpleNameOf

public static java.lang.String simpleNameOf(java.lang.Class c)

update

public static void update(java.util.Map map,
                          java.lang.String name,
                          java.lang.Object withValue)