View Javadoc

1   /*
2   Wotonomy: OpenStep design patterns for pure Java applications.
3   Copyright (C) 2001 Intersect Software Corporation
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, see http://www.gnu.org
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      // interface EOKeyValueCoding
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  * $Log$
134  * Revision 1.2  2006/02/16 16:47:14  cgruber
135  * Move some classes in to "internal" packages and re-work imports, etc.
136  *
137  * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions.
138  *
139  * Revision 1.1  2006/02/16 13:19:57  cgruber
140  * Check in all sources in eclipse-friendly maven-enabled packages.
141  *
142  * Revision 1.2  2003/08/06 23:07:52  chochos
143  * general code cleanup (mostly, removing unused imports)
144  *
145  * Revision 1.1  2001/11/18 18:57:10  mpowers
146  * Implemented EOGenericRecord.
147  *
148  *
149  */
150     
151