1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002-2009 Oracle. All rights reserved. 5 * 6 * $Id$ 7 */ 8 9package collections.ship.marshal; 10 11import com.sleepycat.bind.tuple.TupleInput; 12import com.sleepycat.bind.tuple.TupleOutput; 13 14/** 15 * A ShipmentKey serves as the key in the key/data pair for a shipment entity. 16 * 17 * <p> In this sample, ShipmentKey is bound to the stored key tuple entry by 18 * implementing the MarshalledKey interface, which is called by {@link 19 * SampleViews.MarshalledKeyBinding}. </p> 20 * 21 * @author Mark Hayes 22 */ 23public class ShipmentKey implements MarshalledKey { 24 25 private String partNumber; 26 private String supplierNumber; 27 28 public ShipmentKey(String partNumber, String supplierNumber) { 29 30 this.partNumber = partNumber; 31 this.supplierNumber = supplierNumber; 32 } 33 34 public final String getPartNumber() { 35 36 return partNumber; 37 } 38 39 public final String getSupplierNumber() { 40 41 return supplierNumber; 42 } 43 44 public String toString() { 45 46 return "[ShipmentKey: supplier=" + supplierNumber + 47 " part=" + partNumber + ']'; 48 } 49 50 // --- MarshalledKey implementation --- 51 52 ShipmentKey() { 53 54 // A no-argument constructor is necessary only to allow the binding to 55 // instantiate objects of this class. 56 } 57 58 public void unmarshalKey(TupleInput keyInput) { 59 60 this.partNumber = keyInput.readString(); 61 this.supplierNumber = keyInput.readString(); 62 } 63 64 public void marshalKey(TupleOutput keyOutput) { 65 66 keyOutput.writeString(this.partNumber); 67 keyOutput.writeString(this.supplierNumber); 68 } 69} 70