KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: Part.java,v 1.15 2006/10/30 21:14:00 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 Part represents the combined key/data pair for a part entity.
18  *
19  * <p> In this sample, Part 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 PartData 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 Part implements Serializable JavaDoc, MarshalledEntity {
34
35     private transient String JavaDoc number;
36     private String JavaDoc name;
37     private String JavaDoc color;
38     private Weight weight;
39     private String JavaDoc city;
40
41     public Part(String JavaDoc number, String JavaDoc name, String JavaDoc color, Weight weight,
42                 String JavaDoc city) {
43
44         this.number = number;
45         this.name = name;
46         this.color = color;
47         this.weight = weight;
48         this.city = city;
49     }
50
51     /**
52      * Set the transient key fields after deserializing. This method is only
53      * called by data bindings.
54      */

55     final void setKey(String JavaDoc number) {
56
57         this.number = number;
58     }
59
60     public final String JavaDoc getNumber() {
61
62         return number;
63     }
64
65     public final String JavaDoc getName() {
66
67         return name;
68     }
69
70     public final String JavaDoc getColor() {
71
72         return color;
73     }
74
75     public final Weight getWeight() {
76
77         return weight;
78     }
79
80     public final String JavaDoc getCity() {
81
82         return city;
83     }
84
85     public String JavaDoc toString() {
86
87         return "[Part: number=" + number +
88                " name=" + name +
89                " color=" + color +
90                " weight=" + weight +
91                " city=" + city + ']';
92     }
93
94     // --- MarshalledEntity implementation ---
95

96     Part() {
97
98         // A no-argument constructor is necessary only to allow the binding to
99
// instantiate objects of this class.
100
}
101
102     public void unmarshalPrimaryKey(TupleInput keyInput) {
103
104         this.number = keyInput.readString();
105     }
106
107     public void marshalPrimaryKey(TupleOutput keyOutput) {
108
109         keyOutput.writeString(this.number);
110     }
111
112     public boolean marshalSecondaryKey(String JavaDoc keyName, TupleOutput keyOutput) {
113
114         throw new UnsupportedOperationException JavaDoc(keyName);
115     }
116 }
117
Popular Tags