KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > collections > ship > factory > 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.16 2006/10/30 21:13:59 bostic Exp $
7  */

8
9 package collections.ship.factory;
10
11 import java.io.Serializable JavaDoc;
12
13 import com.sleepycat.bind.tuple.MarshalledTupleKeyEntity;
14 import com.sleepycat.bind.tuple.TupleInput;
15 import com.sleepycat.bind.tuple.TupleOutput;
16
17 /**
18  * A Part represents the combined key/data pair for a part entity.
19  *
20  * <p> In this sample, Part is bound to the stored key/data entry by
21  * implementing the MarshalledTupleKeyEntity interface. </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)
25  * are 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, MarshalledTupleKeyEntity {
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     public final String JavaDoc getNumber() {
52
53         return number;
54     }
55
56     public final String JavaDoc getName() {
57
58         return name;
59     }
60
61     public final String JavaDoc getColor() {
62
63         return color;
64     }
65
66     public final Weight getWeight() {
67
68         return weight;
69     }
70
71     public final String JavaDoc getCity() {
72
73         return city;
74     }
75
76     public String JavaDoc toString() {
77
78         return "[Part: number=" + number +
79         " name=" + name +
80         " color=" + color +
81         " weight=" + weight +
82         " city=" + city + ']';
83     }
84
85     // --- MarshalledTupleKeyEntity implementation ---
86

87     public void marshalPrimaryKey(TupleOutput keyOutput) {
88
89         keyOutput.writeString(this.number);
90     }
91
92     public void unmarshalPrimaryKey(TupleInput keyInput) {
93
94         this.number = keyInput.readString();
95     }
96
97     public boolean marshalSecondaryKey(String JavaDoc keyName, TupleOutput keyOutput) {
98
99         throw new UnsupportedOperationException JavaDoc(keyName);
100     }
101
102     public boolean nullifyForeignKey(String JavaDoc keyName) {
103
104         throw new UnsupportedOperationException JavaDoc(keyName);
105     }
106 }
107
Popular Tags