View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

BOSS Basics

BOSS Basics by David Montarella

In our project, we had to be able to load and save information (in our case, dictionaries and ordered collections of users, projects, and permissions). To someone who has had little to no experience in the past with loading and saving external files, such as the case with me, getting started may seem a little daunting. Fortunately, smalltalk has a very easy way to handle this, Binary Object Storage (BOSS).

Before getting started, I should mention that the AppDevGuide in the doc folder (assuming you're still using visual works) has a good section on BOSS, so if you haven't gone over it in class yet, or have trouble with my case, it's a good help.

BOSS will let you save whole objects, and then load them back in later. This system is also useful aside from the ease, by the fact that they take up less space than some of the other storage methods (although you'll probably not be too worried about this).

Your first step should be installing the BOSS parcel. You can find it by going to the main visualworks window, then going to System, parcel manager, and then moving to the Application Development folder, and selecting the BOSS parcel. Load it in and you should be ready to go.

You may want to play around with BOSS before trying to implement it into your project. Creating a small easy program (or modifying your earlier individual assignments for the class) is a good way to get started without having to worry about some of the more complex issues that may come up on your more complex project.

Lets start with saving. The first step is to either start a data stream, or get a filename from the standard smalltalk dialogs. It is probably easiest to set this as a temporary variable, and most examples from the appdevguide and class do this as well. Next, you need to create the binary object storage. Again its good to set this as a temporary variable, then just set it to BinaryObjectStorage onNew: (data stream or filename here). There will be some other added on parts here depending on how you are going about it. If you're using a filename dialog (which I found the easiest to use), you'll have something that looks this

bos := BinaryObjectStorage onNew: filename(your temp variable from the filename dialog) asFilename writeStream.

The data stream typically has the asFilename writeStream part above where it is set to the variable, so when you create the binary object storage, you just have to have the onNew: message given the variable you set the data stream to.

Next use the nextPut: message on your binary object storage variable, and give it the object you want to save, like so
[bos nextPut: object] ensure: [bos close].
Make sure you don't forget the bos close portion.

Moving onto loading, it is similar in style to saving. Once again, if you're using the requestFileName dialog, set that to a temporary variable. Next you're going to create the binary object storage again, this time using the onOld: message rather than the onNew: from saving. Next, create another temporary variable and set this to your binary object storage contents.
ie if your binary object storage variable is bos, it should look like this
[temp := bos contents] ensure: [bos close].
then you can use this to get at your object. Assuming you only had one, you can just set your object to it like this
object := temp at: 1.
Obviously if you have more, you'll need to go through and set them where they are.

This is really the very basic and easy ways to save and load. If you need more advanced techniques, the appdevguide is always there, as well as google, although I've found googling very disappointing for smalltalk help in general.

Links to this Page