KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > je > gettingStarted > InventoryBinding


1 // file InventoryBinding.java
2
// $Id: InventoryBinding.java,v 1.4 2005/06/09 17:20:54 mark Exp $
3

4 package je.gettingStarted;
5
6 import com.sleepycat.bind.tuple.TupleBinding;
7 import com.sleepycat.bind.tuple.TupleInput;
8 import com.sleepycat.bind.tuple.TupleOutput;
9
10 public class InventoryBinding extends TupleBinding {
11
12     // Implement this abstract method. Used to convert
13
// a DatabaseEntry to an Inventory object.
14
public Object JavaDoc entryToObject(TupleInput ti) {
15
16         String JavaDoc sku = ti.readString();
17         String JavaDoc itemName = ti.readString();
18         String JavaDoc category = ti.readString();
19         String JavaDoc vendor = ti.readString();
20         int vendorInventory = ti.readInt();
21         float vendorPrice = ti.readFloat();
22
23         Inventory inventory = new Inventory();
24         inventory.setSku(sku);
25         inventory.setItemName(itemName);
26         inventory.setCategory(category);
27         inventory.setVendor(vendor);
28         inventory.setVendorInventory(vendorInventory);
29         inventory.setVendorPrice(vendorPrice);
30
31         return inventory;
32     }
33
34     // Implement this abstract method. Used to convert a
35
// Inventory object to a DatabaseEntry object.
36
public void objectToEntry(Object JavaDoc object, TupleOutput to) {
37
38         Inventory inventory = (Inventory)object;
39
40         to.writeString(inventory.getSku());
41         to.writeString(inventory.getItemName());
42         to.writeString(inventory.getCategory());
43         to.writeString(inventory.getVendor());
44         to.writeInt(inventory.getVendorInventory());
45         to.writeFloat(inventory.getVendorPrice());
46     }
47 }
48
Popular Tags