1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jdo.impl.model.jdo;
19
20 import org.apache.jdo.model.ModelException;
21 import org.apache.jdo.model.java.JavaField;
22 import org.apache.jdo.model.java.JavaProperty;
23 import org.apache.jdo.model.java.JavaType;
24 import org.apache.jdo.model.jdo.JDOArray;
25 import org.apache.jdo.model.jdo.JDOClass;
26 import org.apache.jdo.model.jdo.JDOCollection;
27 import org.apache.jdo.model.jdo.JDOField;
28 import org.apache.jdo.model.jdo.JDOMap;
29 import org.apache.jdo.model.jdo.JDOProperty;
30 import org.apache.jdo.model.jdo.JDOReference;
31 import org.apache.jdo.model.jdo.JDORelationship;
32 import org.apache.jdo.util.I18NHelper;
33
34 /***
35 * An instance of this class represents the JDO metadata of a managed property
36 * of a persistence capable class. This JDOProperty implementation is used for
37 * persistent properties with an associated JDOField. All JDOField getter
38 * methods delegate to the associated JDOField, except methods getName,
39 * getDeclaringClass and getJavaField. All JDOField setter method throw a
40 * ModelException to avoid changing the associated JDOField through this
41 * JDOProperty instance. This dynamic implementation only stores values
42 * explicitly set by setter method.
43 *
44 * @author Michael Bouschen
45 * @since 2.0
46 * @version 2.0
47 */
48 public class JDOAssociatedPropertyImplDynamic
49 extends JDOMemberImpl
50 implements JDOProperty
51 {
52 /*** The associated JDOField instance. */
53 private final JDOField associatedJDOField;
54
55 /*** The corresponding JavaProperty instance. */
56 protected JavaProperty javaProperty;
57
58 /*** I18N support. */
59 protected final static I18NHelper msg =
60 I18NHelper.getInstance(JDOAssociatedPropertyImplDynamic.class);
61
62 /*** Constrcutor. */
63 protected JDOAssociatedPropertyImplDynamic(
64 String name, JDOClass declaringClass, JDOField associatedJDOField)
65 throws ModelException {
66 super(name, declaringClass);
67 this.associatedJDOField = associatedJDOField;
68 if (associatedJDOField == null) {
69 throw new ModelException(
70 msg.msg("EXC_InvalidNullAssociatedJDOField"));
71 }
72 }
73
74
75
76 /***
77 * Get the corresponding JavaProperty representation for this JDOProperty.
78 * @return the corresponding JavaProperty representation
79 */
80 public JavaField getJavaField() {
81 if (javaProperty != null) {
82
83 return javaProperty;
84 }
85
86
87 JavaType javaType = getDeclaringClass().getJavaType();
88 return javaType.getJavaProperty(getName());
89 }
90
91 /***
92 * Sets the corresponding JavaProperty representation for this JDOProperty.
93 * @param javaField the corresponding JavaProperty representation
94 * @throws ModelException if impossible
95 */
96 public void setJavaField(JavaField javaField) throws ModelException {
97
98 if (javaField instanceof JavaProperty) {
99 this.javaProperty = (JavaProperty)javaField;
100 }
101 else {
102 throw new ModelException(msg.msg(
103 "EXC_InvalidJavaFieldForJDOProperty", javaField));
104 }
105 }
106
107 /***
108 * Convenience method to check whether this field represents a property.
109 * @return <code>true</code> if this field represents a property;
110 * <code>false</code> otherwise
111 */
112 public boolean isProperty() {
113 return true;
114 }
115
116
117
118 /*** Deletegate to associatedJDOField. */
119 public int getPersistenceModifier() {
120 return associatedJDOField.getPersistenceModifier();
121 }
122
123 /*** Throws ModelException. */
124 public void setPersistenceModifier (int persistenceModifier)
125 throws ModelException {
126 throw new ModelException(
127 msg.msg("EXC_CannotModifyJDOProperty"));
128 }
129
130 /*** Deletegate to associatedJDOField. */
131 public boolean isPrimaryKey() {
132 return associatedJDOField.isPrimaryKey();
133 }
134
135 /*** Throws ModelException. */
136 public void setPrimaryKey(boolean primaryKey)
137 throws ModelException {
138 throw new ModelException(
139 msg.msg("EXC_CannotModifyJDOProperty"));
140 }
141
142 /*** Deletegate to associatedJDOField. */
143 public int getNullValueTreatment() {
144 return associatedJDOField.getNullValueTreatment();
145 }
146
147 /*** Throws ModelException. */
148 public void setNullValueTreatment(int nullValueTreament)
149 throws ModelException {
150 throw new ModelException(
151 msg.msg("EXC_CannotModifyJDOProperty"));
152 }
153
154 /*** Deletegate to associatedJDOField. */
155 public boolean isDefaultFetchGroup() {
156 return associatedJDOField.isDefaultFetchGroup();
157 }
158
159 /*** Throws ModelException. */
160 public void setDefaultFetchGroup(boolean defaultFetchGroup)
161 throws ModelException {
162 throw new ModelException(
163 msg.msg("EXC_CannotModifyJDOProperty"));
164 }
165
166 /*** Deletegate to associatedJDOField. */
167 public boolean isEmbedded() {
168 return associatedJDOField.isEmbedded();
169 }
170
171 /*** Throws ModelException. */
172 public void setEmbedded(boolean embedded)
173 throws ModelException {
174 throw new ModelException(
175 msg.msg("EXC_CannotModifyJDOProperty"));
176 }
177
178 /*** Deletegate to associatedJDOField. */
179 public boolean isSerializable() {
180 return associatedJDOField.isSerializable();
181 }
182
183 /*** Throws ModelException. */
184 public void setSerializable(boolean serializable)
185 throws ModelException {
186 throw new ModelException(
187 msg.msg("EXC_CannotModifyJDOProperty"));
188 }
189
190 /*** Deletegate to associatedJDOField. */
191 public String getMappedByName() {
192 return associatedJDOField.getMappedByName();
193 }
194
195 /*** Throws ModelException. */
196 public void setMappedByName(String mappedByName)
197 throws ModelException {
198 throw new ModelException (
199 msg.msg("EXC_CannotModifyJDOProperty"));
200 }
201
202 /*** Deletegate to associatedJDOField. */
203 public JDORelationship getRelationship() {
204 return associatedJDOField.getRelationship();
205 }
206
207 /*** Throws ModelException. */
208 public void setRelationship(JDORelationship relationship)
209 throws ModelException {
210 throw new ModelException(
211 msg.msg("EXC_CannotModifyJDOProperty"));
212 }
213
214 /*** Throws ModelException. */
215 public JDOReference createJDOReference()
216 throws ModelException {
217 throw new ModelException(
218 msg.msg("EXC_CannotModifyJDOProperty"));
219 }
220
221 /*** Throws ModelException. */
222 public JDOCollection createJDOCollection()
223 throws ModelException {
224 throw new ModelException(
225 msg.msg("EXC_CannotModifyJDOProperty"));
226 }
227
228 /*** Throws ModelException. */
229 public JDOArray createJDOArray()
230 throws ModelException {
231 throw new ModelException(
232 msg.msg("EXC_CannotModifyJDOProperty"));
233 }
234
235 /*** Throws ModelException. */
236 public JDOMap createJDOMap()
237 throws ModelException {
238 throw new ModelException(
239 msg.msg("EXC_CannotModifyJDOProperty"));
240 }
241
242 /*** Deletegate to associatedJDOField. */
243 public boolean isPersistent() {
244 return associatedJDOField.isPersistent();
245 }
246
247 /*** Deletegate to associatedJDOField. */
248 public boolean isTransactional() {
249 return associatedJDOField.isTransactional();
250 }
251
252 /*** Deletegate to associatedJDOField. */
253 public boolean isManaged() {
254 return associatedJDOField.isManaged();
255 }
256
257 /*** Deletegate to associatedJDOField. */
258 public boolean isRelationship() {
259 return associatedJDOField.isRelationship();
260 }
261
262 /*** Deletegate to associatedJDOField. */
263 public JavaType getType() {
264 return associatedJDOField.getType();
265 }
266
267 /*** Deletegate to associatedJDOField. */
268 public int getFieldNumber() {
269 return associatedJDOField.getFieldNumber();
270 }
271
272 /*** Deletegate to associatedJDOField. */
273 public int getRelativeFieldNumber() {
274 return associatedJDOField.getRelativeFieldNumber();
275 }
276
277
278
279 /***
280 * Return the JDOField instance associated with this property, if
281 * available. If there is no JDOField instance associated, then the method
282 * returns <code>null</code>.
283 * @return associated JDOField instance or <code>null</code> if not
284 * available.
285 */
286 public JDOField getAssociatedJDOField() {
287 return associatedJDOField;
288 }
289 }