1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jdo.impl.model.java.reflection;
19
20 import java.lang.reflect.Field;
21
22 import org.apache.jdo.impl.model.java.BaseReflectionJavaField;
23 import org.apache.jdo.model.ModelFatalException;
24 import org.apache.jdo.model.java.JavaField;
25 import org.apache.jdo.model.java.JavaType;
26 import org.apache.jdo.model.jdo.JDOField;
27 import org.apache.jdo.util.I18NHelper;
28
29 /***
30 * A reflection based JavaField implementation used at runtime.
31 * The implementation takes <code>java.lang.reflect.Field</code> instances
32 * to get Java related metadata about fields.
33 *
34 * @author Michael Bouschen
35 * @since JDO 1.1
36 * @version JDO 2.0
37 */
38 public class ReflectionJavaField
39 extends BaseReflectionJavaField
40 {
41 /*** I18N support */
42 private final static I18NHelper msg =
43 I18NHelper.getInstance("org.apache.jdo.impl.model.java.Bundle");
44
45 /***
46 * Constructor for fields w/o JDO metadata.
47 * @param field the reflection field representation.
48 * @param declaringClass the JavaType of the class that declares the field.
49 */
50 public ReflectionJavaField(Field field, JavaType declaringClass)
51 {
52 super(field, declaringClass);
53 this.type = getJavaTypeForClass(field.getType());
54 }
55
56 /***
57 * Constructor for fields having JDO metadata.
58 * @param fieldName the name of the field.
59 * @param type the field type.
60 * @param declaringClass the JavaType of the class that declares the field.
61 */
62 public ReflectionJavaField(String fieldName, JavaType type,
63 JavaType declaringClass)
64 {
65 super(fieldName, declaringClass);
66 this.type = type;
67 }
68
69 /***
70 * Returns the JavaType representation of the field type.
71 * @return field type
72 */
73 public JavaType getType()
74 {
75 if (type == null) {
76 type = getJavaTypeForClass(getField().getType());
77 }
78 return type;
79 }
80
81
82
83 /***
84 * Returns a JavaType instance for the specified Class object.
85 * This method provides a hook such that ReflectionJavaField subclasses can
86 * implement their own mapping of Class objects to JavaType instances.
87 */
88 public JavaType getJavaTypeForClass(Class clazz)
89 {
90 return ((ReflectionJavaType)getDeclaringClass()).getJavaTypeForClass(clazz);
91 }
92 }