KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > collections > ship > factory > 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.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 Supplier represents the combined key/data pair for a supplier entity.
19  *
20  * <p> In this sample, Supplier 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) 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, MarshalledTupleKeyEntity {
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     public final String JavaDoc getNumber() {
51
52         return number;
53     }
54
55     public final String JavaDoc getName() {
56
57         return name;
58     }
59
60     public final int getStatus() {
61
62         return status;
63     }
64
65     public final String JavaDoc getCity() {
66
67         return city;
68     }
69
70     public String JavaDoc toString() {
71
72         return "[Supplier: number=" + number +
73         " name=" + name +
74         " status=" + status +
75         " city=" + city + ']';
76     }
77
78     // --- MarshalledTupleKeyEntity implementation ---
79

80     public void marshalPrimaryKey(TupleOutput keyOutput) {
81
82         keyOutput.writeString(this.number);
83     }
84
85     public void unmarshalPrimaryKey(TupleInput keyInput) {
86
87         this.number = keyInput.readString();
88     }
89
90     public boolean marshalSecondaryKey(String JavaDoc keyName, TupleOutput keyOutput) {
91
92         if (keyName.equals(CITY_KEY)) {
93             if (this.city != null) {
94                 keyOutput.writeString(this.city);
95                 return true;
96             } else {
97                 return false;
98             }
99         } else {
100             throw new UnsupportedOperationException JavaDoc(keyName);
101         }
102     }
103
104     public boolean nullifyForeignKey(String JavaDoc keyName) {
105
106         throw new UnsupportedOperationException JavaDoc(keyName);
107     }
108 }
109
Popular Tags