1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jdo.impl.model.jdo.caching;
18
19 import org.apache.jdo.model.ModelException;
20 import org.apache.jdo.model.java.JavaField;
21 import org.apache.jdo.model.java.JavaProperty;
22 import org.apache.jdo.model.java.JavaType;
23 import org.apache.jdo.model.jdo.JDOClass;
24 import org.apache.jdo.model.jdo.JDOField;
25 import org.apache.jdo.model.jdo.JDOProperty;
26
27 /***
28 * An instance of this class represents the JDO metadata of a managed field
29 * of a persistence capable class. This dynamic implementation only
30 * stores property values explicitly set by setter method.
31 * <p>
32 * Please note, you cannot rely on the Java identity of the
33 * JDORelationship instance returned by {@link #getRelationship}.
34 * The getter will always return a new Java Instance, unless the
35 * relationship is explicitly set by the setter
36 * {@link #setRelationship(JDORelationship relationship)}.
37 *
38 * @author Michael Bouschen
39 * @since 2.0
40 * @version 2.0
41 */
42 public class JDOPropertyImplCaching
43 extends JDOFieldImplCaching
44 implements JDOProperty
45 {
46 /*** */
47 protected JDOPropertyImplCaching(String name, JDOClass declaringClass) {
48 super(name, declaringClass);
49 }
50
51 /***
52 * Get the corresponding JavaField representation for this JDOProperty.
53 * @return the corresponding JavaProperty representation
54 */
55 public JavaField getJavaField() {
56 if (javaField == null) {
57
58
59
60 JavaType javaType = getDeclaringClass().getJavaType();
61 javaField = javaType.getJavaProperty(getName());
62 }
63 return javaField;
64 }
65
66 /***
67 * Sets the corresponding JavaProperty representation for this JDOProperty.
68 * @param javaField the corresponding JavaProperty representation
69 * @throws ModelException if impossible
70 */
71 public void setJavaField(JavaField javaField) throws ModelException {
72 if (javaField instanceof JavaProperty) {
73 this.javaField = javaField;
74 }
75 else {
76 throw new ModelException(msg.msg(
77 "EXC_InvalidJavaFieldForJDOProperty", javaField));
78 }
79 }
80
81 /***
82 * Convenience method to check whether this field represents a property.
83 * @return <code>true</code> if this field represents a property;
84 * <code>false</code> otherwise
85 */
86 public boolean isProperty() {
87 return true;
88 }
89
90 /***
91 * Return the JDOField instance associated with this property, if
92 * available. If there is no JDOField instance associated, then the method
93 * returns <code>null</code>.
94 * <p>
95 * This implementation always retruns <code>null</code>.
96 * @return associated JDOField instance or <code>null</code> if not
97 * available.
98 */
99 public JDOField getAssociatedJDOField() {
100 return null;
101 }
102 }