Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## superwaba.ext.xplat.io
Class ObjectCatalog

    java.lang.Object
      |
      +--waba.io.Stream
            |
            +--waba.io.Catalog
                  |
                  +--superwaba.ext.xplat.io.ObjectCatalog

public class ObjectCatalog
extends Catalog

An extension to Catalog that allows storage and retrieval of objects that implement the Storable interface. Create an ObjectCatalog and use the addObject() method on the objects you want to store. If you want a particular object you can use loadObjectAt() to load the stored details into an object or to search through all records call resetSearch() and then loop with nextObject() until it returns false. The example below shows an example of it's use with a catalog of identical data:

>        ObjectCatalog oc=new ObjectCatalog("Test.DATA");
>        MyObject obj=new MyObject();
>        oc.resetSearch();
>        while (oc.nextObject(obj))
>        {
>          // do something with obj
>        }

Here's an example using unknown data. The two sections of code save a vector containing a number of Lines, Circles, and Squares (all implementing Storable) in no particular order, then loads it back in again.

>        // save data
>        ObjectCatalog oc=new ObjectCatalog("Test.DATA",ObjectCatalog.CREATE);
>        for(int i=0,size=objs.getCount();i++)
>          oc.addObject((Storable)objs.get(i));
>        oc.close();

>        // load data
>        ObjectCatalog oc=new ObjectCatalog("Test.DATA");
>        oc.registerClass(new Line());
>        oc.registerClass(new Circle());
>        oc.registerClass(new Square());
>        objs=new Vector();
>        oc.resetSearch();
>        Storable obj;
>        while ((obj=oc.nextObject())!=null)
>        {
>          objs.add(obj);
>        }
>        oc.close();

Field Summary
`protected BufferStream` | `bs`
`protected byte[]` | `buf`
`protected Vector` | `classes`
`protected int` | `cnt`
`protected DataStream` | `ds`

Fields inherited from class waba.io.Catalog
`bag, CREATE, DB_ATTR_APPINFODIRTY, DB_ATTR_BACKUP, DB_ATTR_COPY_PREVENTION, DB_ATTR_OK_TO_INSTALL_NEWER, DB_ATTR_READ_ONLY, DB_ATTR_RESET_AFTER_INSTALL, DB_ATTR_STREAM, READ_ONLY, READ_WRITE, REC_ATTR_DELETE, REC_ATTR_DIRTY, REC_ATTR_SECRET, WRITE_ONLY`

Constructor Summary
`ObjectCatalog(String name)` Construct a new ObjectCatalog
`ObjectCatalog(String name, int type)` Constructs a new ObjectCatalog

Method Summary
`boolean` | `addObject(Storable s)` Add an object to this catalog.
`boolean` | `deleteObjectAt(int i)` Delete an object from the catalog
`byte` | `getObjectAttribute(int i)` Get attributes of an object record from the catalog
`boolean` | `insertObjectAt(Storable s, int i)` Insert an object to this catalog.
`Storable` | `loadObjectAt(int i)` Loads an object from the catalog.
`boolean` | `loadObjectAt(Storable s, int i)` Load an object from the catalog into the given storable.
`Storable` | `nextObject()` Gets the next object in the catalog.
`boolean` | `nextObject(Storable s)` Gets the next object in the catalog and places it in the given storable.
`void` | `registerClass(Storable s)` Registers this class with the catalog.
`void` | `resetSearch()` Resets a counter for iterating through the catalog.
`boolean` | `setObjectAttribute(int i, byte a)` Set attributes of an object record from the catalog
`void` | `setSearchIndex(int i)` Sets the search counter at the given index in the catalog.
`int` | `size()` Get the size of this catalog

Methods inherited from class waba.io.Catalog
`addRecord, addRecord, close, delete, deleteRecord, getAttributes, getRecordAttributes, getRecordCount, getRecordPos, getRecordSize, inspectRecord, isOpen, listCatalogs, listCatalogs, readBytes, rename, resizeRecord, setAttributes, setRecordAttributes, setRecordPos, skipBytes, writeBytes`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, toString, wait, wait`

Field Detail

### classes

    protected Vector classes

### cnt

    protected int cnt

### buf

    protected byte[] buf

### bs

    protected BufferStream bs

### ds

    protected DataStream ds

Constructor Detail

### ObjectCatalog

    public ObjectCatalog(String name,
                         int type)

  Constructs a new ObjectCatalog
  Parameters:
    `name` - the name of the catalog
    `type` - the mode to open the catalog with

### ObjectCatalog

    public ObjectCatalog(String name)

  Construct a new ObjectCatalog
  Parameters:
    `name` - the name of the catalog

Method Detail

### registerClass

    public void registerClass(Storable s)

  Registers this class with the catalog. Classes must be registered before using the loadObjectAt(int) method.
  Parameters:
    `s` - an instance of the class to register. The contents are ignored.

### addObject

    public boolean addObject(Storable s)

  Add an object to this catalog.
  Parameters:
    `s` - the storable object to add

### insertObjectAt

    public boolean insertObjectAt(Storable s,
                                  int i)

  Insert an object to this catalog.
  Parameters:
    `s` - the storable object to add
    `i` - the index where to insert

### loadObjectAt

    public boolean loadObjectAt(Storable s,
                                int i)

  Load an object from the catalog into the given storable. Unpredictable results will occur if the object in the catalog is not of the same class as the storable given. Good for when you know what each record will contain.
  Parameters:
    `s` - the object to load the data into
    `i` - the index in the catalog to load from
  Returns:
    true if sucessful, false otherwise

### loadObjectAt

    public Storable loadObjectAt(int i)

  Loads an object from the catalog. Good for when you don't know which classes are going to be in records. Note that you must call the registerClass() with each storable class before this method will work properly.
  Parameters:
    `i` - the index in the catalog to load from
  Returns:
    the loaded object, or null if unsucessful

### deleteObjectAt

    public boolean deleteObjectAt(int i)

  Delete an object from the catalog
  Parameters:
    `i` - the index to delete from
  Returns:
    true if sucessful, false otherwise

### setObjectAttribute

    public boolean setObjectAttribute(int i,
                                      byte a)

  Set attributes of an object record from the catalog
  Parameters:
    `i` - the index to set the attribute
    `a` - the attribute to set, use the REC_ATTR_XXXX constants from Catalog class
  Returns:
    true if sucessful, false otherwise

### getObjectAttribute

    public byte getObjectAttribute(int i)

  Get attributes of an object record from the catalog
  Parameters:
    `i` - the index to get the attribute from
  Returns:
    the record attributes

### size

    public int size()

  Get the size of this catalog
  Returns:
    the number of records contained by it

### resetSearch

    public void resetSearch()

  Resets a counter for iterating through the catalog. Should be called before iterating with nextObject().

### setSearchIndex

    public void setSearchIndex(int i)

  Sets the search counter at the given index in the catalog.
  Parameters:
    `i` - the index to start

### nextObject

    public boolean nextObject(Storable s)

  Gets the next object in the catalog and places it in the given storable.
  Returns:
    true if sucessful, false if the end of the catalog has been reached

### nextObject

    public Storable nextObject()

  Gets the next object in the catalog.
  Returns:
    the next object, or null on error or if the end has been reached

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD