1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package javax.jdo.identity;
24
25 import java.io.IOException;
26 import java.io.ObjectInput;
27 import java.io.ObjectOutput;
28
29 /*** This class is for identity with a single String field.
30 * @version 2.0
31 */
32 public class StringIdentity extends SingleFieldIdentity {
33
34 /*** The key is stored in the superclass field keyAsObject.
35 */
36
37 /*** Constructor with class and key.
38 * @param pcClass the class
39 * @param key the key
40 */
41 public StringIdentity (Class pcClass, String key) {
42 super (pcClass);
43 setKeyAsObject(key);
44 hashCode = hashClassName() ^ key.hashCode();
45 }
46
47 /*** Constructor only for Externalizable.
48 */
49 public StringIdentity () {
50 }
51
52 /*** Return the key.
53 * @return the key
54 */
55 public String getKey () {
56 return (String)keyAsObject;
57 }
58
59 /*** Return the String form of the key.
60 * @return the String form of the key
61 */
62 public String toString () {
63 return (String)keyAsObject;
64 }
65
66 /*** Determine if the other object represents the same object id.
67 * @param obj the other object
68 * @return true if both objects represent the same object id
69 */
70 public boolean equals (Object obj) {
71 if (this == obj) {
72 return true;
73 } else if (!super.equals (obj)) {
74 return false;
75 } else {
76 StringIdentity other = (StringIdentity) obj;
77 return keyAsObject.equals(other.keyAsObject);
78 }
79 }
80
81 /*** Write this object. Write the superclass first.
82 * @param out the output
83 */
84 public void writeExternal(ObjectOutput out) throws IOException {
85 super.writeExternal (out);
86 out.writeObject(keyAsObject);
87 }
88
89 /*** Read this object. Read the superclass first.
90 * @param in the input
91 */
92 public void readExternal(ObjectInput in)
93 throws IOException, ClassNotFoundException {
94 super.readExternal (in);
95 keyAsObject = (String)in.readObject();
96 }
97 }