|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--waba.io.Stream | +--waba.io.Catalog | +--superwaba.ext.xplat.io.ObjectCatalog
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 |
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,
getRecordAttributes,
getRecordCount,
getRecordOffset,
getRecordPos,
getRecordSize,
inspectRecord,
isOpen,
listCatalogs,
listCatalogs,
readBytes,
rename,
resizeRecord,
setAttributes,
setRecordAttributes,
setRecordAttributes,
setRecordPos,
skipBytes,
writeBytes |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
toString,
wait,
wait |
Field Detail |
protected Vector classes
protected int cnt
protected byte[] buf
protected BufferStream bs
protected DataStream ds
Constructor Detail |
public ObjectCatalog(String name, int type)
name
- the name of the catalogtype
- the mode to open the catalog withpublic ObjectCatalog(String name)
name
- the name of the catalogMethod Detail |
public void registerClass(Storable s)
s
- an instance of the class to register. The contents are
ignored.public boolean addObject(Storable s)
s
- the storable object to addpublic boolean insertObjectAt(Storable s, int i)
s
- the storable object to addi
- the index where to insertpublic boolean loadObjectAt(Storable s, int i)
s
- the object to load the data intoi
- the index in the catalog to load frompublic Storable loadObjectAt(int i)
i
- the index in the catalog to load frompublic boolean deleteObjectAt(int i)
i
- the index to delete frompublic boolean setObjectAttribute(int i, byte a)
i
- the index to set the attributea
- the attribute to set, use the REC_ATTR_XXXX constants from Catalog classpublic byte getObjectAttribute(int i)
i
- the index to get the attribute frompublic int size()
public void resetSearch()
public void setSearchIndex(int i)
i
- the index to startpublic boolean nextObject(Storable s)
public Storable nextObject()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |