1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package net.wotonomy.access;
19
20 import net.wotonomy.control.EOClassDescription;
21 import net.wotonomy.control.EOEditingContext;
22 import net.wotonomy.control.EOFetchSpecification;
23 import net.wotonomy.control.EOGenericRecord;
24 import net.wotonomy.control.EOGlobalID;
25 import net.wotonomy.foundation.NSArray;
26 import net.wotonomy.foundation.NSMutableArray;
27
28 /***
29 * @author ezamudio@nasoft.com
30 * @author $Author: cgruber $
31 * @version $Revision: 894 $
32 */
33 public class EOEntityClassDescription extends EOClassDescription {
34
35 protected EOEntity _entity;
36
37 public EOEntityClassDescription() {
38 super();
39 }
40
41 public EOEntityClassDescription(EOEntity entity) {
42 this();
43 _entity = entity;
44 }
45
46 public NSArray allAttributeKeys() {
47 NSArray arr = entity().attributes();
48 NSMutableArray a = new NSMutableArray(arr.count());
49 for (int i = 0; i < arr.count(); i++) {
50 EOAttribute atrib = (EOAttribute)arr.objectAtIndex(i);
51 a.addObject(atrib);
52 }
53 return a;
54 }
55
56 public NSArray allPropertyKeys() {
57 return entity().classPropertyNames();
58 }
59
60 public NSArray allToManyRelationshipKeys() {
61 NSArray arr = entity().relationships();
62 NSMutableArray a = new NSMutableArray(arr.count());
63 for (int i = 0; i < arr.count(); i++) {
64 EORelationship r = (EORelationship)arr.objectAtIndex(i);
65 if (r.isToMany())
66 a.addObject(r);
67 }
68 return a;
69 }
70
71 public NSArray allToOneRelationshipKeys() {
72 NSArray arr = entity().relationships();
73 NSMutableArray a = new NSMutableArray(arr.count());
74 for (int i = 0; i < arr.count(); i++) {
75 EORelationship r = (EORelationship)arr.objectAtIndex(i);
76 if (!r.isToMany())
77 a.addObject(r);
78 }
79 return a;
80 }
81
82 /*** Returns all attributes that correspond to columns
83 * in a database table.
84 */
85 public NSArray attributeKeys() {
86 NSArray arr = entity().attributes();
87 NSMutableArray a = new NSMutableArray(arr.count());
88 for (int i = 0; i < arr.count(); i++) {
89 EOAttribute atrib = (EOAttribute)arr.objectAtIndex(i);
90 if (!atrib.isDerived())
91 a.addObject(atrib);
92 }
93 return a;
94 }
95
96 public EOClassDescription classDescriptionForDestinationKey(String key) {
97 EORelationship r = entity().relationshipNamed(key);
98 if (r == null)
99 return null;
100 return r.destinationEntity().classDescriptionForInstances();
101 }
102
103 public NSArray clientAttributeKeys() {
104 return null;
105 }
106
107 public NSArray clientToManyRelationshipKeys() {
108 return null;
109 }
110
111 public NSArray clientToOneRelationshipKeys() {
112 return null;
113 }
114
115 public EOEntity entity() {
116 return _entity;
117 }
118
119 public String entityName() {
120 return _entity.name();
121 }
122
123 public EOFetchSpecification fetchSpecificationNamed(String name) {
124 return entity().fetchSpecificationNamed(name);
125 }
126
127 public NSArray toManyRelationshipKeys() {
128 NSArray arr = entity().relationships();
129 NSMutableArray a = new NSMutableArray(arr.count());
130 for (int i = 0; i < arr.count(); i++) {
131 EORelationship r = (EORelationship)arr.objectAtIndex(i);
132 if (r.isToMany() && !r.isFlattened())
133 a.addObject(r);
134 }
135 return a;
136 }
137
138 public NSArray toOneRelationshipKeys() {
139 NSArray arr = entity().relationships();
140 NSMutableArray a = new NSMutableArray(arr.count());
141 for (int i = 0; i < arr.count(); i++) {
142 EORelationship r = (EORelationship)arr.objectAtIndex(i);
143 if (!r.isToMany() && !r.isFlattened())
144 a.addObject(r);
145 }
146 return a;
147 }
148
149 public Object createInstanceWithEditingContext(EOEditingContext ec, EOGlobalID gid) {
150 if (theClass == null) {
151 try {
152 theClass = Class.forName(entity().className());
153 } catch (ClassNotFoundException ex) {
154 if (entity().className().equals("net.wotonomy.control.EOGenericRecord"))
155 throw new IllegalArgumentException("Cannot find class " + entity().className());
156 theClass = EOGenericRecord.class;
157 }
158 }
159 return super.createInstanceWithEditingContext(ec, gid);
160 }
161
162 }
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185