• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/db-4.7.25.NC/examples_java/src/collections/ship/marshal/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002,2008 Oracle.  All rights reserved.
5 *
6 * $Id: Part.java,v 12.7 2008/01/08 20:58:30 bostic Exp $
7 */
8
9package collections.ship.marshal;
10
11import java.io.Serializable;
12
13import com.sleepycat.bind.tuple.TupleInput;
14import 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 MarshalledEnt 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 */
33public class Part implements Serializable, MarshalledEnt {
34
35    private transient String number;
36    private String name;
37    private String color;
38    private Weight weight;
39    private String city;
40
41    public Part(String number, String name, String color, Weight weight,
42                String 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 number) {
56
57        this.number = number;
58    }
59
60    public final String getNumber() {
61
62        return number;
63    }
64
65    public final String getName() {
66
67        return name;
68    }
69
70    public final String getColor() {
71
72        return color;
73    }
74
75    public final Weight getWeight() {
76
77        return weight;
78    }
79
80    public final String getCity() {
81
82        return city;
83    }
84
85    public String toString() {
86
87        return "[Part: number=" + number +
88               " name=" + name +
89               " color=" + color +
90               " weight=" + weight +
91               " city=" + city + ']';
92    }
93
94    // --- MarshalledEnt 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 keyName, TupleOutput keyOutput) {
113
114        throw new UnsupportedOperationException(keyName);
115    }
116}
117