All Packages  Class Hierarchy  This Package  Previous  Next  Index

Interface PREDATOR.ADT.SubclassSelector

public interface SubclassSelector
The interface implemented by objects which wish to subclass the object data objects used by the ADTs. Interface designers may wish to use an object which implements this interface so that they may add some type of functionality to the data type objects. For instance, the designer of an interface to the Sequoia 2000 benchmark data may wish to have all of the GIS (Geographic Information System) types to be displayed on a map of California. The GIS types (Point, Polygon, and Raster E-ADTs) currently do not have this capability. To extend their functionality, the interface designer would take the following steps:
  1. Design an interface (in the Java sense) which defines methods to extend functionality. In the Sequoia example, the interface would look much like this:
           public interface CommonDisplayObject {
              public void Draw(CaliforniaMap Map);
           }
           
  2. Create subclasses of the RasterObject, PolygonObject, and PointObject classes which implement the new interface described above.
  3. Create an object which implements the SubclassSelector interface. In the getSubclass(Class) function, it should return the class of the subclass defined in the previous step, given the class of the original DataObject class. For those DataObject subclasses which are not GIS types, the getSubclass(Class) function must return the original class. For example, if the subclasses were given the prefix GIS, the getSubclass(Class) function would be implemented as follows:
           public Class getSubclass(Class SuperClass)
           {
             // Form the name of the subclass, if it exists
             String BaseClassName = SuperClass.getName();
             String SubclassName = "Sequoia.GIS" +
               BaseClassName.substring("PREDATOR.ADT.".length(), 
                                       BaseClassName.length());
             // Try to load the class.  If it exists, return it.  Otherwise
             // return the original class.
             Class returnClass = null;
             try {
                returnClass = Class.forName(SubclassName);
             } catch (java.lang.ClassNotFoundException X) {
               return SuperClass;
             }
             return returnClass;
           }
           
    Note how this function works: when the Raster E-ADT asks the SubclassSelector for a subclass of RasterObject, the function above attempts to load the class Sequoia.GISRasterObject and substitute it. If it cannot find the class, it returns the original class. That insures that DataObjects such as IntegerData are unaffected by the SubclassSelector. As long as the getSubclass(Class) is written in this extensible manner, it is possible for classes added later to also assume the new functionality. For instance, if a PolyLine E-ADT were added to the system, the Sequoia interface designer need only define the Sequoia.GISPolyLineObject class to allow it to draw itself on a map of California. If the function checked to see if the incoming class was RasterObject, PointObject or PolygonObject, the SubclassSelector would be much less useful.
  4. Pass in the SubclassSelector object to all calls to RecordStreamResult.getNextRecord(SubclassSelector).
If all of these steps are followed, the objects returned from calls to RecordStreamResult.getNextRecord(SubclassSelector) will be of the class specified by the SubclassSelector. (In the Sequoia example, they will be capable of drawing themselves on a common map of California. If the SubclassSelector supplied to the RecordStreamResult.getNextRecord(SubclassSelector) function returns null or a class which is not either the supplied class or a direct subclass of the supplied class, a BadSubclassSelectorException will be thrown.

See Also:
DataObject, getNextRecord, BadSubclassSelectorException

Method Index

 o getSubclass(Class)
Permits an interface to add functionality to DataObject objects by selecting a direct subclass of that class which implements an interface describing the new functionality.

Methods

 o getSubclass
 public abstract Class getSubclass(Class SuperClass)
Permits an interface to add functionality to DataObject objects by selecting a direct subclass of that class which implements an interface describing the new functionality.

Parameters:
SuperClass - the class of the DataObject which might need to be subclassed for added functionality
Returns:
SuperClass, a direct subclass of it. If something is returned which does not satisfy this criteria (null, for instance), a BadSubclassSelectorException exception will be thrown from the call to RecordStreamResult.getNextRecord(SubclassSelector).

All Packages  Class Hierarchy  This Package  Previous  Next  Index