be.SIRAPRISE.client.jsba
Class DBObjectFactory

java.lang.Object
  extended by be.SIRAPRISE.client.jsba.DBObjectFactory

public abstract class DBObjectFactory
extends java.lang.Object

Author:
Erwin

Method Summary
static
<C> C
getObject(Tuple tuple, java.lang.Class<C> objectClass)
          Get an objects holding the same information as that which is held in this tuple.
static
<C> C
getObject(Tuple tuple, java.lang.Class<C> objectClass, java.util.HashMap<java.lang.String,SetterMethod> setterMethods)
          Gets an object of the given class, using the given set of setter methods and the attribute values from this tuple
static
<C> C[]
getObjectArray(AbstractTupleContainer c, java.lang.Class<C> objectClass)
          Get an array of objects holding the same information as that which is held in this TupleContainer.
static
<C> C[]
getObjectArrayIgnoringMissingSetters(AbstractTupleContainer c, java.lang.Class<C> objectClass)
          Get an array of objects holding a (potentially proper) subset of the information held in this TupleContainer.
static
<C> java.util.Collection<C>
getObjectCollection(AbstractTupleContainer tupleContainer, java.lang.Class<C> objectClass)
          Get a collection of objects holding the same information as that which is held in this TupleContainer.
static
<C> C
getObjectIgnoringMissingSetters(Tuple tuple, java.lang.Class<C> objectClass)
          Get an objects holding the same information as that which is held in this tuple.
static java.util.Map<java.lang.Class<?>,java.lang.Object> getObjects(Tuple tuple, java.lang.Class<?>[] objectClass)
          Get a Map of objects holding the same information as that which is held in this Tuple.
static java.lang.reflect.Constructor<?> getPublicNoArgConstructor(java.lang.Class<?> objectClass)
          Gets the public no-arg constructor from a class
static java.lang.reflect.Constructor<?> getPublicTupleConstructor(java.lang.Class<?> objectClass)
          Gets the 'Tuple' constructor from a class
static java.util.HashMap<java.lang.String,SetterMethod> getSetterMethods(java.lang.Class<?> objectClass, Heading heading)
          Gets the setter methods from a class applicable for the given set of attribute names
static java.util.Map<java.lang.Class<?>,java.lang.Object> toObjects(Tuple tuple, java.util.Map<java.lang.Class<?>,java.util.HashMap<java.lang.String,SetterMethod>> classesProcessingMap)
          Gets a Map of objects holding the same information as that which is held in this tuple.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getObject

public static <C> C getObject(Tuple tuple,
                              java.lang.Class<C> objectClass)
                   throws ConstructorMissingException,
                          ClassDoesNotImplementDBObjectException,
                          SettersMissingException
Get an objects holding the same information as that which is held in this tuple.

Parameters:
tuple - The tuple from which an object is to be built
objectClass - A Class object denoting the class of the objects to be returned. objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has a unique setter method for each attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), the attribute name (capitalized), and the suffix "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
An array of objects of the given object Class.
Throws:
SettersMissingException - if a needed setter is missing in the class denoted by objectClass
ConstructorMissingException - if objectClass does not denote a public class, or it denotes an abstract class, or the class does not have a public no-arg constructor
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface

getObjectArray

public static <C> C[] getObjectArray(AbstractTupleContainer c,
                                     java.lang.Class<C> objectClass)
                          throws SettersMissingException,
                                 ConstructorMissingException,
                                 ClassDoesNotImplementDBObjectException
Get an array of objects holding the same information as that which is held in this TupleContainer. One object is created for each tuple.

Type Parameters:
C - The name of the objectClass, also naming the class/object type of the objects making up the returned array
Parameters:
c - The tuple container whose tuples are to be 'transformed' into objects
objectClass - A Class object denoting the class of the objects to be returned. objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has a unique setter method for each attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), followed by the uppercased attribute name (i.e. first character uppercase, all others lowercase), followed by "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
An array of objects of the given object Class.
Throws:
ConstructorMissingException - if objectClass does not denote a public class, or it denotes an abstract class, or the class does not have a public no-arg constructor
SettersMissingException - if a needed setter is missing in the class denoted by objectClass
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface

getObjectArrayIgnoringMissingSetters

public static <C> C[] getObjectArrayIgnoringMissingSetters(AbstractTupleContainer c,
                                                           java.lang.Class<C> objectClass)
                                                throws ConstructorMissingException,
                                                       ClassDoesNotImplementDBObjectException
Get an array of objects holding a (potentially proper) subset of the information held in this TupleContainer. One object is created for each tuple. Setters matching an attribute in the heading will be invoked, attributes for which no corresponding setter is found, are ignored.

Type Parameters:
C - The name of the objectClass, also naming the class/object type of the objects making up the returned array
Parameters:
c - The tuple container whose tuples are to be 'transformed' into objects of the given class
objectClass - A Class object denoting the class of the objects to be returned. objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has at most one unique setter method for each attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), followed by the uppercased attribute name (i.e. first character uppercase, all others lowercase), followed by "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
An array of objects of the given object Class.
Throws:
ConstructorMissingException - if objectClass does not denote a public class, or it denotes an abstract class, or the class does not have a public no-arg constructor
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface
ConstructorMissingException
ClassDoesNotImplementDBObjectException

getObjectIgnoringMissingSetters

public static final <C> C getObjectIgnoringMissingSetters(Tuple tuple,
                                                          java.lang.Class<C> objectClass)
                                               throws ConstructorMissingException,
                                                      ClassDoesNotImplementDBObjectException
Get an objects holding the same information as that which is held in this tuple.

Type Parameters:
C -
Parameters:
tuple - The tuple from which an Object is to be built
objectClass - A Class object denoting the class of the objects to be returned. objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has a unique setter method for each attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), the attribute name (capitalized), and the suffix "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
An array of objects of the given object Class.
Throws:
ConstructorMissingException - if objectClass does not denote a public class, or it denotes an abstract class, or the class does not have a public no-arg constructor
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface

getObjects

public static java.util.Map<java.lang.Class<?>,java.lang.Object> getObjects(Tuple tuple,
                                                                            java.lang.Class<?>[] objectClass)
                                                                     throws ConstructorMissingException,
                                                                            ClassDoesNotImplementDBObjectException,
                                                                            SettersMissingException
Get a Map of objects holding the same information as that which is held in this Tuple. The entries in the map have one of the objectClass[] objects as their key, and an object of that class as their value. The object of that class holds the attribute values of the tuple for which a corresponding setter method was found in the class.

Parameters:
tuple - The tuple from which objects are to be contructed
objectClass - An array of Class objects denoting the classes of the objects to be returned for each tuple. Each objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has a unique setter method for some attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), the attribute name (capitalized), and the suffix "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
A map of objects holding the same information as this tuple. The key in each map entry is one of the objectClass objects given as an argument, the corresponding value in the map entry is the created object of that class.
Throws:
SettersMissingException - if some attribute in the heading exists for which no corresponding setter could be found in any of the classes denoted by objectClass[]
ConstructorMissingException - if objectClass[] contains any class that does not denote a public class, or denotes an abstract class, or does not have a public no-arg constructor
ClassDoesNotImplementDBObjectException - if objectClass[] contains any class that does not implement the required DBObject interface

getPublicNoArgConstructor

public static java.lang.reflect.Constructor<?> getPublicNoArgConstructor(java.lang.Class<?> objectClass)
                                                                  throws ConstructorMissingException,
                                                                         ClassDoesNotImplementDBObjectException
Gets the public no-arg constructor from a class

Parameters:
objectClass - the class
Returns:
the public no-arg constructor of the class
Throws:
ConstructorMissingException - if objectClass does not denote a public class, or it denotes an abstract class, or the class does not have a public no-arg constructor
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface

getPublicTupleConstructor

public static java.lang.reflect.Constructor<?> getPublicTupleConstructor(java.lang.Class<?> objectClass)
                                                                  throws ConstructorMissingException,
                                                                         ClassDoesNotImplementDBObjectException
Gets the 'Tuple' constructor from a class

Parameters:
objectClass - the class
Returns:
the public constructor of the class that takes a single argument of a type/class that implements the Tuple interface
Throws:
ConstructorMissingException - if objectClass does not denote a public class, or it denotes an abstract class, or the class does not have a public single-arg Tuple constructor
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface

getSetterMethods

public static java.util.HashMap<java.lang.String,SetterMethod> getSetterMethods(java.lang.Class<?> objectClass,
                                                                                Heading heading)
Gets the setter methods from a class applicable for the given set of attribute names

Parameters:
objectClass - The class to extract the setter methods from
heading - The heading of the tuple container, in which to inspect whether an attribute is relation-valued, so that a "relation" setter may also match
Returns:
A Map in which the key is the attribute name of some attribute in the heading of a TupleContainer, and the value is the setter method for that attribute obtained from the objectClass.

getObject

public static final <C> C getObject(Tuple tuple,
                                    java.lang.Class<C> objectClass,
                                    java.util.HashMap<java.lang.String,SetterMethod> setterMethods)
Gets an object of the given class, using the given set of setter methods and the attribute values from this tuple

Type Parameters:
C -
Parameters:
tuple - The tuple from which an object is to be built
objectClass - The Class of the object to be created and returned
setterMethods - The setter methods to be invoked to set attribute values in the returned object
Returns:
An object of the given Class holding the attribute values obtained from the given tuple

toObjects

public static final java.util.Map<java.lang.Class<?>,java.lang.Object> toObjects(Tuple tuple,
                                                                                 java.util.Map<java.lang.Class<?>,java.util.HashMap<java.lang.String,SetterMethod>> classesProcessingMap)
Gets a Map of objects holding the same information as that which is held in this tuple.

Parameters:
tuple - The tuple from which objects are to be constrcuted
classesProcessingMap - The processing map that defines how the conversion of a tuple to a series of objects should proceed. Each entry in the map is a Class object, defining the class of an object to be instantiated for containing values of the tuple. The value mapped to this class object is a Map defining the setter methods to be invoked for setting the appropriate values in the instantiated object.
Returns:
a Map of objects holding the same information as that which is held in this tuple. The entries in the map have Class objects as their key, and an object of that class as their value. The object of that class holds the attribute values of the tuple for which a corresponding setter method was found in the class.

getObjectCollection

public static <C> java.util.Collection<C> getObjectCollection(AbstractTupleContainer tupleContainer,
                                                              java.lang.Class<C> objectClass)
                                                   throws ConstructorMissingException,
                                                          ClassDoesNotImplementDBObjectException,
                                                          SettersMissingException
Get a collection of objects holding the same information as that which is held in this TupleContainer. One object is created for each tuple.

Type Parameters:
C -
Parameters:
tupleContainer - The TupleContainer holding the tuples to be used for constructing DBObjects
objectClass - A Class object denoting the class of the objects to be returned. objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has a unique setter method for each attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), followed by the uppercased attribute name (i.e. first character uppercase, all others lowercase), followed by "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
An array of objects of the given object Class.
Throws:
ConstructorMissingException - if objectClass does not denote a public class, or it denotes an abstract class, or the class does not have a public no-arg constructor
SettersMissingException - if a needed setter is missing in the class denoted by objectClass
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface