edu.kzoo.grid.gui
Class GridPkgFactory

java.lang.Object
  |
  +--edu.kzoo.grid.gui.GridPkgFactory

public class GridPkgFactory
extends java.lang.Object

Grid GUI Support Package:
The GridPkgFactory class provides a set of static methods for constructing grids and the objects they contain, and for keeping track of what types of grids or grid objects are available to a specific application.

The GridPkgFactory class is based on the College Board's MBSFactory class, as allowed by the GNU General Public License.

Version:
1 August 2002
Author:
Julie Zelenski (author of MBSFactory)

Constructor Summary
GridPkgFactory()
           
 
Method Summary
static void addBoundedGridClassNames(java.lang.String[] classNames)
          Adds bounded grid classes to the set maintained by the factory.
protected static void addClassesToFactory(java.lang.String[] classNames, java.lang.String whichCategory)
          Helper to add new classes to the factory.
static void addGridObjClassNames(java.lang.String[] classNames)
          Adds grid object classes to the set maintained by the factory.
static void addUnboundedGridClassNames(java.lang.String[] classNames)
          Adds unbounded grid classes to the set maintained by the factory.
static java.util.Set boundedGridClasses()
          Returns the set of bounded grid classes known to the factory.
static Grid constructGrid(java.lang.Class cls)
          Creates an instance of a Grid using the default constructor of the given class.
static Grid constructGrid(java.lang.Class cls, int numRows, int numCols)
          Creates an instance of a Grid using the 2-argument constructor of the given class.
static java.lang.Object constructGridObject(java.lang.Class cls, Grid grid, Location loc)
          Creates an instance of the given grid object class using a two-argument constructor that takes a grid and a location.
static java.lang.Object constructGridObject(java.lang.Class cls, Grid grid, Location loc, Direction dir)
          Creates an instance of the given grid object class using a three-argument constructor that takes a grid, a location, and a direction.
static java.lang.Object constructGridObject(java.lang.Class cls, Grid grid, Location loc, Direction dir, java.awt.Color color)
          Creates an instance of the given grid object class using a four-argument constructor that takes a grid, a location, a direction, and a color.
static java.lang.Object constructObject(java.lang.Class cls, java.lang.Class[] parameterTypes, java.lang.Object[] parameters)
          Creates an object of the given class.
static java.util.Set gridObjectClasses()
          Returns the set of grid object classes known to the factory.
protected static boolean hasCorrectCtor(java.lang.Class cls, java.lang.Class requiredCls, java.lang.Class[] ctorParameters)
          Verifies that a class has the required constructor and is properly assignable.
static boolean hasFourArgCtor(java.lang.Class cls)
          Reports wehther a given grid object class has an accessible four-arg constructor that takes Grid, Location, Direction, and Color.
static boolean isValidGridClass(java.lang.Class cls, java.lang.Class[] ctorParameters)
          Verifies that a class has the required constructor and is properly assignable to Grid.
static boolean isValidGridObjectClass(java.lang.Class cls, java.lang.Class[] ctorParameters)
          Verifies that a class has the required constructor and is properly assignable to GridObject.
static java.util.Set unboundedGridClasses()
          Returns the set of unbounded grid classes known to the factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridPkgFactory

public GridPkgFactory()
Method Detail

constructObject

public static java.lang.Object constructObject(java.lang.Class cls,
                                               java.lang.Class[] parameterTypes,
                                               java.lang.Object[] parameters)
Creates an object of the given class.

Parameters:
cls - class of new object
parameterTypes - parameter types expected by constructor for class
parameters - actual parameters to pass to constructor
Returns:
the newly created object
Throws:
java.lang.RuntimeException - if an object of the specified class cannot be constructed with the specified parameters

constructGridObject

public static java.lang.Object constructGridObject(java.lang.Class cls,
                                                   Grid grid,
                                                   Location loc)
Creates an instance of the given grid object class using a two-argument constructor that takes a grid and a location.

Parameters:
cls - class of new grid object
grid - grid in which this object will act
loc - location the object will occupy
Returns:
the newly created grid object
Throws:
MBSException - if an object of the specified class cannot be constructed with the specified parameters

constructGridObject

public static java.lang.Object constructGridObject(java.lang.Class cls,
                                                   Grid grid,
                                                   Location loc,
                                                   Direction dir)
Creates an instance of the given grid object class using a three-argument constructor that takes a grid, a location, and a direction.

Parameters:
cls - class of new grid object
grid - grid in which this object will act
loc - location the object will occupy
dir - direction the object will face
Returns:
the newly created grid object
Throws:
MBSException - if an object of the specified class cannot be constructed with the specified parameters

constructGridObject

public static java.lang.Object constructGridObject(java.lang.Class cls,
                                                   Grid grid,
                                                   Location loc,
                                                   Direction dir,
                                                   java.awt.Color color)
Creates an instance of the given grid object class using a four-argument constructor that takes a grid, a location, a direction, and a color.

Parameters:
cls - class of new grid object
grid - grid in which this object will act
loc - location the object will occupy
dir - direction the object will face
color - color of the object
Returns:
the newly created grid object
Throws:
MBSException - if an object of the specified class cannot be constructed with the specified parameters

constructGrid

public static Grid constructGrid(java.lang.Class cls)
Creates an instance of a Grid using the default constructor of the given class. Used to create unbounded grids; no dimensions are specified.

Parameters:
cls - class of new grid
Returns:
the newly created grid
Throws:
MBSException - if a grid of the specified class cannot be constructed

constructGrid

public static Grid constructGrid(java.lang.Class cls,
                                 int numRows,
                                 int numCols)
Creates an instance of a Grid using the 2-argument constructor of the given class. Used to create bounded grids; dimensions must be specified.

Parameters:
cls - class of new grid
Returns:
the newly created grid
Throws:
MBSException - if an grid of the specified class cannot be constructed with the given number of rows and columns

gridObjectClasses

public static java.util.Set gridObjectClasses()
Returns the set of grid object classes known to the factory. Classes are added to the factory via the addGridObjClassNames method.

Returns:
the set of grid object classes

boundedGridClasses

public static java.util.Set boundedGridClasses()
Returns the set of bounded grid classes known to the factory. Classes are added to the factory via the addBoundedClassNames method.

Returns:
the set of bounded grid classes

unboundedGridClasses

public static java.util.Set unboundedGridClasses()
Returns the set of unbounded grid classes known to the factory. Classes are added to the factory via the addUnboundedClassNames method.

Returns:
the set of unbounded grid classes

addClassesToFactory

protected static void addClassesToFactory(java.lang.String[] classNames,
                                          java.lang.String whichCategory)
Helper to add new classes to the factory. Classes are specified by string name. For each name, error-checking is done to ensure the name class exists, is accessible, and has the proper constructor. If all checks out, the class is added to the appropriate set maintained by the factory. On errors, a message is printed and the class is skipped.

Parameters:
classNames - an array of class names
whichCategory - descriptive name for category (e.g., "bounded grid")

addGridObjClassNames

public static void addGridObjClassNames(java.lang.String[] classNames)
Adds grid object classes to the set maintained by the factory. If the named class cannot be found or the class is not a proper GridObject object, an error message is printed and the class is not added to the set.

Parameters:
classNames - an array of grid object class names

addBoundedGridClassNames

public static void addBoundedGridClassNames(java.lang.String[] classNames)
Adds bounded grid classes to the set maintained by the factory. If the named class cannot be found or the class is not a proper bounded grid, an error message is printed, and that class is not added to the set.

Parameters:
classNames - an array of bounded grid class names

addUnboundedGridClassNames

public static void addUnboundedGridClassNames(java.lang.String[] classNames)
Adds unbounded grid classes to the set maintained by the factory. If the named class cannot be found or the class is not a proper unbounded grid, an error message is printed, and that class is not added to the set.

Parameters:
classNames - an array of unbounded grid class names

isValidGridClass

public static boolean isValidGridClass(java.lang.Class cls,
                                       java.lang.Class[] ctorParameters)
                                throws java.lang.NoSuchMethodException
Verifies that a class has the required constructor and is properly assignable to Grid. This is used to vet grid classes given to the factory before adding them to the list of known classes.

java.lang.NoSuchMethodException

isValidGridObjectClass

public static boolean isValidGridObjectClass(java.lang.Class cls,
                                             java.lang.Class[] ctorParameters)
                                      throws java.lang.NoSuchMethodException
Verifies that a class has the required constructor and is properly assignable to GridObject. This is used to vet grid object classes given to the factory before adding them to the list of known classes.

java.lang.NoSuchMethodException

hasCorrectCtor

protected static boolean hasCorrectCtor(java.lang.Class cls,
                                        java.lang.Class requiredCls,
                                        java.lang.Class[] ctorParameters)
                                 throws java.lang.NoSuchMethodException
Verifies that a class has the required constructor and is properly assignable. This is used to vet classes given to the factory before adding them to the list of known classes.

java.lang.NoSuchMethodException

hasFourArgCtor

public static boolean hasFourArgCtor(java.lang.Class cls)
Reports wehther a given grid object class has an accessible four-arg constructor that takes Grid, Location, Direction, and Color.