KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > collections > ship > marshal > ShipmentKey


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: ShipmentKey.java,v 1.12 2006/10/30 21:14:01 bostic Exp $
7  */

8
9 package collections.ship.marshal;
10
11 import com.sleepycat.bind.tuple.TupleInput;
12 import 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  */

23 public class ShipmentKey implements MarshalledKey {
24
25     private String JavaDoc partNumber;
26     private String JavaDoc supplierNumber;
27
28     public ShipmentKey(String JavaDoc partNumber, String JavaDoc supplierNumber) {
29
30         this.partNumber = partNumber;
31         this.supplierNumber = supplierNumber;
32     }
33
34     public final String JavaDoc getPartNumber() {
35
36         return partNumber;
37     }
38
39     public final String JavaDoc getSupplierNumber() {
40
41         return supplierNumber;
42     }
43
44     public String JavaDoc 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
Popular Tags