Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
EOEntityClassDescription |
|
| 2.0;2 |
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 | 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 | 0 | super(); |
39 | 0 | } |
40 | ||
41 | public EOEntityClassDescription(EOEntity entity) { |
|
42 | 0 | this(); |
43 | 0 | _entity = entity; |
44 | 0 | } |
45 | ||
46 | public NSArray allAttributeKeys() { |
|
47 | 0 | NSArray arr = entity().attributes(); |
48 | 0 | NSMutableArray a = new NSMutableArray(arr.count()); |
49 | 0 | for (int i = 0; i < arr.count(); i++) { |
50 | 0 | EOAttribute atrib = (EOAttribute)arr.objectAtIndex(i); |
51 | 0 | a.addObject(atrib); |
52 | } |
|
53 | 0 | return a; |
54 | } |
|
55 | ||
56 | public NSArray allPropertyKeys() { |
|
57 | 0 | return entity().classPropertyNames(); |
58 | } |
|
59 | ||
60 | public NSArray allToManyRelationshipKeys() { |
|
61 | 0 | NSArray arr = entity().relationships(); |
62 | 0 | NSMutableArray a = new NSMutableArray(arr.count()); |
63 | 0 | for (int i = 0; i < arr.count(); i++) { |
64 | 0 | EORelationship r = (EORelationship)arr.objectAtIndex(i); |
65 | 0 | if (r.isToMany()) |
66 | 0 | a.addObject(r); |
67 | } |
|
68 | 0 | return a; |
69 | } |
|
70 | ||
71 | public NSArray allToOneRelationshipKeys() { |
|
72 | 0 | NSArray arr = entity().relationships(); |
73 | 0 | NSMutableArray a = new NSMutableArray(arr.count()); |
74 | 0 | for (int i = 0; i < arr.count(); i++) { |
75 | 0 | EORelationship r = (EORelationship)arr.objectAtIndex(i); |
76 | 0 | if (!r.isToMany()) |
77 | 0 | a.addObject(r); |
78 | } |
|
79 | 0 | return a; |
80 | } |
|
81 | ||
82 | /** Returns all attributes that correspond to columns |
|
83 | * in a database table. |
|
84 | */ |
|
85 | public NSArray attributeKeys() { |
|
86 | 0 | NSArray arr = entity().attributes(); |
87 | 0 | NSMutableArray a = new NSMutableArray(arr.count()); |
88 | 0 | for (int i = 0; i < arr.count(); i++) { |
89 | 0 | EOAttribute atrib = (EOAttribute)arr.objectAtIndex(i); |
90 | 0 | if (!atrib.isDerived()) |
91 | 0 | a.addObject(atrib); |
92 | } |
|
93 | 0 | return a; |
94 | } |
|
95 | ||
96 | public EOClassDescription classDescriptionForDestinationKey(String key) { |
|
97 | 0 | EORelationship r = entity().relationshipNamed(key); |
98 | 0 | if (r == null) |
99 | 0 | return null; |
100 | 0 | return r.destinationEntity().classDescriptionForInstances(); |
101 | } |
|
102 | ||
103 | public NSArray clientAttributeKeys() { |
|
104 | 0 | return null; |
105 | } |
|
106 | ||
107 | public NSArray clientToManyRelationshipKeys() { |
|
108 | 0 | return null; |
109 | } |
|
110 | ||
111 | public NSArray clientToOneRelationshipKeys() { |
|
112 | 0 | return null; |
113 | } |
|
114 | ||
115 | public EOEntity entity() { |
|
116 | 0 | return _entity; |
117 | } |
|
118 | ||
119 | public String entityName() { |
|
120 | 0 | return _entity.name(); |
121 | } |
|
122 | ||
123 | public EOFetchSpecification fetchSpecificationNamed(String name) { |
|
124 | 0 | return entity().fetchSpecificationNamed(name); |
125 | } |
|
126 | ||
127 | public NSArray toManyRelationshipKeys() { |
|
128 | 0 | NSArray arr = entity().relationships(); |
129 | 0 | NSMutableArray a = new NSMutableArray(arr.count()); |
130 | 0 | for (int i = 0; i < arr.count(); i++) { |
131 | 0 | EORelationship r = (EORelationship)arr.objectAtIndex(i); |
132 | 0 | if (r.isToMany() && !r.isFlattened()) |
133 | 0 | a.addObject(r); |
134 | } |
|
135 | 0 | return a; |
136 | } |
|
137 | ||
138 | public NSArray toOneRelationshipKeys() { |
|
139 | 0 | NSArray arr = entity().relationships(); |
140 | 0 | NSMutableArray a = new NSMutableArray(arr.count()); |
141 | 0 | for (int i = 0; i < arr.count(); i++) { |
142 | 0 | EORelationship r = (EORelationship)arr.objectAtIndex(i); |
143 | 0 | if (!r.isToMany() && !r.isFlattened()) |
144 | 0 | a.addObject(r); |
145 | } |
|
146 | 0 | return a; |
147 | } |
|
148 | ||
149 | public Object createInstanceWithEditingContext(EOEditingContext ec, EOGlobalID gid) { |
|
150 | 0 | if (theClass == null) { |
151 | try { |
|
152 | 0 | theClass = Class.forName(entity().className()); |
153 | 0 | } catch (ClassNotFoundException ex) { |
154 | 0 | if (entity().className().equals("net.wotonomy.control.EOGenericRecord")) |
155 | 0 | throw new IllegalArgumentException("Cannot find class " + entity().className()); |
156 | 0 | theClass = EOGenericRecord.class; |
157 | 0 | } |
158 | } |
|
159 | 0 | return super.createInstanceWithEditingContext(ec, gid); |
160 | } |
|
161 | ||
162 | } |
|
163 | /* |
|
164 | * $Log$ |
|
165 | * Revision 1.2 2006/02/16 16:47:13 cgruber |
|
166 | * Move some classes in to "internal" packages and re-work imports, etc. |
|
167 | * |
|
168 | * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions. |
|
169 | * |
|
170 | * Revision 1.1 2006/02/16 13:19:57 cgruber |
|
171 | * Check in all sources in eclipse-friendly maven-enabled packages. |
|
172 | * |
|
173 | * Revision 1.4 2003/08/19 01:55:54 chochos |
|
174 | * the behavior is now more consistent with its Apple counterpart. |
|
175 | * |
|
176 | * Revision 1.3 2003/08/09 01:40:31 chochos |
|
177 | * use EOClassDescription's methods to get a destination entity's class description. |
|
178 | * |
|
179 | * Revision 1.2 2003/08/08 05:51:59 chochos |
|
180 | * createInstanceWithEditingContext now works. It sets theClass with the class from the entity className() before calling super. |
|
181 | * |
|
182 | * Revision 1.1 2003/08/08 00:36:19 chochos |
|
183 | * concrete implementation of EOClassDescription that uses an EOEntity |
|
184 | * |
|
185 | */ |