1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.wotonomy.control;
20
21 import net.wotonomy.foundation.NSMutableDictionary;
22 import net.wotonomy.foundation.NSNull;
23
24 /***
25 * EOGenericRecord extends EOCustomObject to provide a
26 * general-purpose implementation, relying entirely on the
27 * class description for entity-specific behavior, and
28 * storing data in a dictionary.
29 *
30 * @author michael@mpowers.net
31 * @author $Author: cgruber $
32 * @version $Revision: 894 $
33 */
34 public class EOGenericRecord extends EOCustomObject
35 {
36 private EOClassDescription classDescription;
37 private NSMutableDictionary dataDictionary;
38
39 /***
40 * Default constructor.
41 */
42 protected EOGenericRecord()
43 {
44 classDescription = null;
45 dataDictionary = new NSMutableDictionary();
46 }
47
48 /***
49 * Preferred constructor.
50 */
51 public EOGenericRecord( EOClassDescription aDescription )
52 {
53 this();
54 classDescription = aDescription;
55 }
56
57 /***
58 * Overridden to return true so that deferred faults are used.
59 */
60 public static boolean usesDeferredFaultCreation()
61 {
62 return true;
63 }
64
65 /***
66 * Compatibility constructor: aContext and anID are ignored.
67 */
68 public EOGenericRecord(
69 EOEditingContext aContext, EOClassDescription aDescription, EOGlobalID anID )
70 {
71 this( aDescription );
72 }
73
74 /***
75 * Returns a class description for this object.
76 * Overridden to return the class description passed
77 * into the constructor.
78 */
79 public EOClassDescription classDescription()
80 {
81 return classDescription;
82 }
83
84
85
86 /***
87 * Calls storedValueForKey.
88 */
89 public Object valueForKey( String aKey )
90 {
91 return storedValueForKey( aKey );
92 }
93
94 /***
95 * Calls willChange and then calls takeStoredValueForKey.
96 */
97 public void takeValueForKey( Object aValue, String aKey )
98 {
99 willChange();
100 takeStoredValueForKey( aValue, aKey );
101 }
102
103 /***
104 * Calls willRead for the specified key,
105 * and returns the corresponding value from
106 * the data dictionary. Keys that do not
107 * exist will return null.
108 */
109 public Object storedValueForKey( String aKey )
110 {
111 willRead( aKey );
112 Object result = dataDictionary.objectForKey( aKey );
113 if ( NSNull.nullValue().equals( result ) ) result = null;
114 return result;
115 }
116
117 /***
118 * Writes the specified value into the data dictionary
119 * for the specified key. Nulls are stored as NSNulls
120 * in the dictionary.
121 * No checking is performed to determine whether the
122 * key is a valid attribute key.
123 */
124 public void takeStoredValueForKey( Object aValue, String aKey )
125 {
126 if ( aValue == null ) aValue = NSNull.nullValue();
127 dataDictionary.setObjectForKey( aValue, aKey );
128 }
129
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151