KickJava   Java API By Example, From Geeks To Geeks.

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


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

8
9 package collections.ship.marshal;
10
11 import java.io.Serializable JavaDoc;
12
13 import com.sleepycat.bind.tuple.TupleInput;
14 import com.sleepycat.bind.tuple.TupleOutput;
15
16 /**
17  * A Supplier represents the combined key/data pair for a supplier entity.
18  *
19  * <p> In this sample, Supplier is bound to the stored key/data entry by
20  * implementing the MarshalledEntity interface, which is called by {@link
21  * SampleViews.MarshalledEntityBinding}. </p>
22  *
23  * <p> The binding is "tricky" in that it uses this class for both the stored
24  * data entry and the combined entity object. To do this, the key field(s) are
25  * transient and are set by the binding after the data object has been
26  * deserialized. This avoids the use of a SupplierData class completely. </p>
27  *
28  * <p> Since this class is used directly for data storage, it must be
29  * Serializable. </p>
30  *
31  * @author Mark Hayes
32  */

33 public class Supplier implements Serializable JavaDoc, MarshalledEntity {
34
35     static final String JavaDoc CITY_KEY = "city";
36
37     private transient String JavaDoc number;
38     private String JavaDoc name;
39     private int status;
40     private String JavaDoc city;
41
42     public Supplier(String JavaDoc number, String JavaDoc name, int status, String JavaDoc city) {
43
44         this.number = number;
45         this.name = name;
46         this.status = status;
47         this.city = city;
48     }
49
50     /**
51      * Set the transient key fields after deserializing. This method is only
52      * called by data bindings.
53      */

54     void setKey(String JavaDoc number) {
55
56         this.number = number;
57     }
58
59     public final String JavaDoc getNumber() {
60
61         return number;
62     }
63
64     public final String JavaDoc getName() {
65
66         return name;
67     }
68
69     public final int getStatus() {
70
71         return status;
72     }
73
74     public final String JavaDoc getCity() {
75
76         return city;
77     }
78
79     public String JavaDoc toString() {
80
81         return "[Supplier: number=" + number +
82                " name=" + name +
83                " status=" + status +
84                " city=" + city + ']';
85     }
86
87     // --- MarshalledEntity implementation ---
88

89     Supplier() {
90
91         // A no-argument constructor is necessary only to allow the binding to
92
// instantiate objects of this class.
93
}
94
95     public void unmarshalPrimaryKey(TupleInput keyInput) {
96
97         this.number = keyInput.readString();
98     }
99
100     public void marshalPrimaryKey(TupleOutput keyOutput) {
101
102         keyOutput.writeString(this.number);
103     }
104
105     public boolean marshalSecondaryKey(String JavaDoc keyName, TupleOutput keyOutput) {
106
107         if (keyName.equals(CITY_KEY)) {
108             if (this.city != null) {
109                 keyOutput.writeString(this.city);
110                 return true;
111             } else {
112                 return false;
113             }
114         } else {
115             throw new UnsupportedOperationException JavaDoc(keyName);
116         }
117     }
118 }
119
Popular Tags