1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jdo.impl.enhancer.meta.prop;
18
19 import java.lang.reflect.Modifier;
20
21
22 /***
23 * A class to hold the properties of a field.
24 */
25 final class JDOField
26 {
27 /***
28 * The name of the field.
29 */
30 final private String name;
31
32 /***
33 * The type of the field.
34 */
35 private String type = null;
36
37 /***
38 * The access modifier of the field.
39 */
40 private int modifiers = Modifier.PRIVATE;
41
42 /***
43 * The JDO modifier of the field.
44 */
45 private String jdoModifier = null;
46
47 /***
48 * The annotation type.
49 */
50 private String annotationType = null;
51
52 /***
53 * Creates a new object with the given name.
54 *
55 * @param name The name of the field.
56 */
57 JDOField(String name)
58 {
59 this.name = name;
60 }
61
62 /***
63 * Returns the name of the field.
64 *
65 * @return The name of the field.
66 */
67 public String getName()
68 {
69 return name;
70 }
71
72 /***
73 * Sets the type of the field. The given classname should have a
74 * natural form(with dots) and is converted to a VM-similar
75 * notation(with slashes).
76 *
77 * @param type The natural classname.
78 */
79 public void setType(String type)
80 {
81 this.type = NameHelper.fromCanonicalClassName(type);
82 }
83
84 /***
85 * Returns the type of the field.
86 *
87 * @return The type of the field.
88 */
89 public String getType()
90 {
91 return type;
92 }
93
94 /***
95 * Returns the modifiers of the field.
96 *
97 * @param modifiers The modifiers of the field.
98 */
99 public void setModifiers(int modifiers)
100 {
101 this.modifiers = modifiers;
102 }
103
104 /***
105 * Returns the modifiers of the field.
106 *
107 * @return The modifiers of the field.
108 */
109 public int getModifiers()
110 {
111 return modifiers;
112 }
113
114 /***
115 * Sets the annotation type of the field.
116 *
117 * @param annotationType annotation type
118 */
119 public void setAnnotationType(String annotationType)
120 {
121 this.annotationType = annotationType;
122 }
123
124 /***
125 * Returns whether the field is annotated.
126 *
127 * @return true if annotated field
128 */
129 public boolean isAnnotated()
130 {
131 return annotationType != null;
132 }
133
134 /***
135 * Returns whether the field is a key primary.
136 *
137 * @return true if primary key.
138 */
139 public boolean isKey()
140 {
141 return (annotationType != null
142 && annotationType.equals(
143 MetaDataProperties.ANNOTATION_TYPE_KEY));
144 }
145
146 /***
147 * Is the field in the default fetch group?
148 *
149 * @return Is the field in the default fetch group?
150 */
151 public boolean isInDefaultFetchGroup()
152 {
153 return (annotationType != null
154 && annotationType.equals(
155 MetaDataProperties.ANNOTATION_TYPE_DFG));
156 }
157
158 /***
159 * Sets the modifiers of the field.
160 *
161 * @param jdoModifier the persistence modifier of the field
162 */
163 public void setJdoModifier(String jdoModifier)
164 {
165 this.jdoModifier = jdoModifier;
166 }
167
168 /***
169 * Returns whether the field is declared transient.
170 *
171 * @return true if declared transient field.
172 * @see #setJdoModifier
173 */
174 public boolean isKnownTransient()
175 {
176 return (jdoModifier != null
177 && jdoModifier.equals(MetaDataProperties.JDO_TRANSIENT));
178 }
179
180 /***
181 * Returns whether the field is persistent.
182 *
183 * @return true if persistent field.
184 * @see #setJdoModifier
185 */
186 public boolean isPersistent()
187 {
188 return (jdoModifier != null
189 && jdoModifier.equals(MetaDataProperties.JDO_PERSISTENT));
190 }
191
192 /***
193 * Returns whether the field is transactional.
194 *
195 * @return true if transactional field
196 * @see #setJdoModifier
197 */
198 public boolean isTransactional()
199 {
200 return (jdoModifier != null
201 && jdoModifier.equals(MetaDataProperties.JDO_TRANSACTIONAL));
202 }
203
204 /***
205 * Returns whether the field is managed.
206 *
207 * @return true if managed field
208 */
209 public boolean isManaged()
210 {
211 return (isPersistent() || isTransactional());
212 }
213
214 /***
215 * Creates a string-representation of the object.
216 *
217 * @return The string-representation of the object.
218 */
219 public String toString()
220 {
221 return ('<' + "name:" + name
222 + ',' + MetaDataProperties.PROPERTY_TYPE
223 + ':' + type
224 + ',' + MetaDataProperties.PROPERTY_ACCESS_MODIFIER
225 + ':' + Modifier.toString(modifiers)
226 + ',' + MetaDataProperties.PROPERTY_JDO_MODIFIER
227 + ':' + jdoModifier
228 + ',' + MetaDataProperties.PROPERTY_ANNOTATION_TYPE
229 + ':' + annotationType + '>');
230 }
231 }