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;
19
20 import java.util.*;
21 import java.math.*;
22
23 import org.apache.jdo.model.java.JavaType;
24
25
26 /***
27 * Instances of this class represent a type that is not a persistence
28 * capable class, but is known by JDO. All JavaModel implementation will
29 * use this implementation to represnet predefined types. Predefined types
30 * include:
31 * <ul>
32 * <li> java.lang.Object
33 * <li> void
34 * <li> primitive types
35 * <li> Java wrapper class types
36 * <li> immutable and mutable value types, such as java.lang.String,
37 * java.util.Date, etc.
38 * <li> JDO supported collection types, including their superclasses.
39 * <li> JDO supported map types, including their superclasses.
40 * </ul>
41 * This class provides public static fields for all predefined types. These
42 * constants are convenience for direct access of a JavaType instance
43 * representing a predefined type. The class also manages a map of
44 * predefined types using the type name as key. The constructors
45 * automatically add the new created instance to this map. Please use
46 * method {@link #getPredefinedType(String name)} to lookup a predefined
47 * type by name. Method {@link #getPredefinedTypes()} returns a view of the
48 * map of predefined types.
49 *
50 * @author Michael Bouschen
51 * @since JDO 1.0.1
52 */
53 public class PredefinedType
54 extends BaseReflectionJavaType
55 {
56 /*** Map of all predefined types. */
57 private static final Map predefinedTypes = new HashMap();
58
59
60
61 /*** The JavaType instance for the class java.lang.Object. */
62 public static final PredefinedType objectType = new PredefinedType(Object.class);
63
64
65
66 /*** The JavaType instance for the type void. */
67 public static final PredefinedType voidType = new PredefinedType(void.class);
68
69
70
71 /*** The JavaType instance for the primitive type boolean. */
72 public static final PrimitiveType booleanType = new PrimitiveType(boolean.class);
73 /*** The JavaType instance for the integral type byte. */
74 public static final IntegralType byteType = new IntegralType(byte.class);
75 /*** The JavaType instance for the integral type short. */
76 public static final IntegralType shortType = new IntegralType(short.class);
77 /*** The JavaType instance for the integral type int. */
78 public static final IntegralType intType = new IntegralType(int.class);
79 /*** The JavaType instance for the integral type long. */
80 public static final IntegralType longType = new IntegralType(long.class);
81 /*** The JavaType instance for the integral type char. */
82 public static final IntegralType charType = new IntegralType(char.class);
83 /*** The JavaType instance for the floating point type float. */
84 public static final FloatingPointType floatType = new FloatingPointType(float.class);
85 /*** The JavaType instance for the floating point type double. */
86 public static final FloatingPointType doubleType = new FloatingPointType(double.class);
87
88
89
90 /*** The JavaType instance for the class java.lang.Numer. */
91 public static final ValueClassType numberType = new ValueClassType(Number.class, objectType, false);
92 /*** The JavaType instance for the class java.lang.String. */
93 public static final ValueClassType stringType = new ValueClassType(String.class, objectType, true);
94 /*** The JavaType instance for the class java.lang.Locale. */
95 public static final ValueClassType localeType = new ValueClassType(Locale.class, objectType, false);
96 /*** The JavaType instance for the class java.math.BigDecimal. */
97 public static final ValueClassType bigDecimalType = new ValueClassType(BigDecimal.class, numberType, true);
98 /*** The JavaType instance for the class java.math.BigInteger. */
99 public static final ValueClassType bigIntegerType = new ValueClassType(BigInteger.class, numberType, true);
100
101
102
103 /*** The JavaType instance for the class java.lang.Boolean. */
104 public static final WrapperClassType booleanClassType = new WrapperClassType(Boolean.class, objectType, false);
105 /*** The JavaType instance for the class java.lang.Byte. */
106 public static final WrapperClassType byteClassType = new WrapperClassType(Byte.class, numberType, true);
107 /*** The JavaType instance for the class java.lang.Short. */
108 public static final WrapperClassType shortClassType = new WrapperClassType(Short.class, numberType, true);
109 /*** The JavaType instance for the class java.lang.Integer. */
110 public static final WrapperClassType integerClassType = new WrapperClassType(Integer.class, numberType, true);
111 /*** The JavaType instance for the class java.lang.Long. */
112 public static final WrapperClassType longClassType = new WrapperClassType(Long.class, numberType, true);
113 /*** The JavaType instance for the class java.lang.Character. */
114 public static final WrapperClassType characterClassType = new WrapperClassType(Character.class, numberType, true);
115 /*** The JavaType instance for the class java.lang.Float. */
116 public static final WrapperClassType floatClassType = new WrapperClassType(Float.class, numberType, true);
117 /*** The JavaType instance for the class java.lang.Double. */
118 public static final WrapperClassType doubleClassType = new WrapperClassType(Double.class, numberType, true);
119
120
121
122 /*** The JavaType instance for the class java.util.Date. */
123 public static final MutableValueClassType dateType = new MutableValueClassType(Date.class, objectType, true);
124 /*** The JavaType instance for the class java.sql.Date. */
125 public static final MutableValueClassType sqlDateType = new MutableValueClassType(java.sql.Date.class, dateType, true);
126 /*** The JavaType instance for the class java.sql.Time. */
127 public static final MutableValueClassType sqlTimeType = new MutableValueClassType(java.sql.Time.class, dateType, true);
128 /*** The JavaType instance for the class java.sql.Timestamp. */
129 public static final MutableValueClassType sqlTimestampType = new MutableValueClassType(java.sql.Timestamp.class, dateType, true);
130 /*** The JavaType instance for the class java.util.BitSet. */
131 public static final MutableValueClassType bitsetType = new MutableValueClassType(BitSet.class, objectType, false);
132
133
134
135 /*** The JavaType instance for the interface java.util.Collection. */
136 public static final JDOSupportedCollectionType collectionType = new JDOSupportedCollectionType(Collection.class);
137 /*** The JavaType instance for the interface java.util.Set. */
138 public static final JDOSupportedCollectionType setType = new JDOSupportedCollectionType(Set.class);
139 /*** The JavaType instance for the interface java.util.List. */
140 public static final JDOSupportedCollectionType listType = new JDOSupportedCollectionType(List.class);
141 /*** The JavaType instance for the class java.util.AbstractCollection. */
142 public static final PredefinedType abstractCollectionType = new PredefinedType(AbstractCollection.class, objectType);
143 /*** The JavaType instance for the class java.util.AbstractSet. */
144 public static final PredefinedType abstractSetType = new PredefinedType(AbstractSet.class, abstractCollectionType);
145 /*** The JavaType instance for the class java.util.HashSet. */
146 public static final JDOSupportedCollectionType hashSetType = new JDOSupportedCollectionType(HashSet.class, abstractSetType);
147 /*** The JavaType instance for the class java.util.TreeSet. */
148 public static final JDOSupportedCollectionType treeSetType = new JDOSupportedCollectionType(TreeSet.class, abstractSetType);
149 /*** The JavaType instance for the class java.util.AbstractList. */
150 public static final PredefinedType abstractListType = new PredefinedType(AbstractList.class, abstractCollectionType);
151 /*** The JavaType instance for the class java.util.ArrayList. */
152 public static final JDOSupportedCollectionType arrayListType = new JDOSupportedCollectionType(ArrayList.class, abstractListType);
153 /*** The JavaType instance for the class java.util.LinkedList. */
154 public static final JDOSupportedCollectionType linkedListType = new JDOSupportedCollectionType(LinkedList.class, abstractListType);
155 /*** The JavaType instance for the class java.util.Vector. */
156 public static final JDOSupportedCollectionType vectorType = new JDOSupportedCollectionType(Vector.class, abstractListType);
157 /*** The JavaType instance for the class java.util.Stack. */
158 public static final JDOSupportedCollectionType stackType = new JDOSupportedCollectionType(Stack.class, vectorType);
159
160
161
162 /*** The JavaType instance for the interface java.util.Map. */
163 public static final JDOSupportedMapType mapType = new JDOSupportedMapType(Map.class);
164 /*** The JavaType instance for the class java.util.AbstractMap. */
165 public static final PredefinedType abstractMapType = new PredefinedType(AbstractMap.class, objectType);
166 /*** The JavaType instance for the class java.util.HashMap. */
167 public static final JDOSupportedMapType hashMapType = new JDOSupportedMapType(HashMap.class, abstractMapType);
168 /*** The JavaType instance for the class java.util.Dictionary. */
169 public static final PredefinedType dictionaryType = new PredefinedType(Dictionary.class, objectType);
170 /*** The JavaType instance for the class java.util.Hashtable. */
171 public static final JDOSupportedMapType hashtableType = new JDOSupportedMapType(Hashtable.class, dictionaryType);
172 /*** The JavaType instance for the class java.util.Properties. */
173 public static final JDOSupportedMapType propertiesType = new JDOSupportedMapType(Properties.class, hashtableType);
174 /*** The JavaType instance for the class java.util.TreeMap. */
175 public static final JDOSupportedMapType treeMapType = new JDOSupportedMapType(TreeMap.class, abstractMapType);
176
177 /***
178 * The static block sets references between the JavaType instances for
179 * primitives types and the JavaType instances for the corresponding
180 * wrapper class.
181 */
182 static
183 {
184 booleanType.setWrapperClassType(booleanClassType);
185 booleanClassType.setWrappedPrimitiveType(booleanType);
186 byteType.setWrapperClassType(byteClassType);
187 byteClassType.setWrappedPrimitiveType(byteType);
188 shortType.setWrapperClassType(shortClassType);
189 shortClassType.setWrappedPrimitiveType(shortType);
190 intType.setWrapperClassType(integerClassType);
191 integerClassType.setWrappedPrimitiveType(intType);
192 longType.setWrapperClassType(longClassType);
193 longClassType.setWrappedPrimitiveType(longType);
194 charType.setWrapperClassType(characterClassType);
195 characterClassType.setWrappedPrimitiveType(charType);
196 floatType.setWrapperClassType(floatClassType);
197 floatClassType.setWrappedPrimitiveType(floatType);
198 doubleType.setWrapperClassType(doubleClassType);
199 doubleClassType.setWrappedPrimitiveType(doubleType);
200 }
201
202 /***
203 * Constructor taking a Class instance.
204 * It automatically adds a predefined type to the static map of all
205 * predefined types.
206 * @param clazz the Class instance for this JavaType
207 */
208 protected PredefinedType(Class clazz)
209 {
210 this(clazz, null);
211 }
212
213 /***
214 * Constructor taking a Class instance and a JavaType representing the
215 * superclass of the new JavaType instance.
216 * It automatically adds a predefined type to the static
217 * map of all predefined types.
218 * @param clazz the Class instance for this JavaType
219 * @param superclass the JavaType representing the superclass or
220 * <code>null</code> if there is no superclass.
221 */
222 protected PredefinedType(Class clazz, JavaType superclass)
223 {
224 super(clazz, superclass);
225 predefinedTypes.put(clazz.getName(), this);
226 }
227
228 /***
229 * Returns the JavaType instance for a predefined type with the
230 * specified name. The method return <code>null</code> if the specified
231 * name does not denote a predefined type.
232 * @param name the name of the predefined type.
233 * @return the JavaType instance for the specified predefined type.
234 */
235 public static JavaType getPredefinedType(String name)
236 {
237 return (JavaType)predefinedTypes.get(name);
238 }
239
240 /***
241 * Returns an unmodifiable view of the predefined types map. This map
242 * maps type names to JavaType instances.
243 * @return an unmodifiable view of the predefined types map.
244 */
245 public static Map getPredefinedTypes()
246 {
247 return Collections.unmodifiableMap(predefinedTypes);
248 }
249
250 }