KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > model > Types


1 /*
2  * Copyright 2004 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: Types.java,v 1.6 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.model;
12
13 import com.triactive.jdo.sco.SCOProcessor;
14 import java.util.HashMap JavaDoc;
15 import java.util.HashSet JavaDoc;
16
17
18 public final class Types
19 {
20     private static final HashSet JavaDoc defaultFetchGroupTypes = new HashSet JavaDoc();
21     private static final HashSet JavaDoc defaultPersistentTypes = new HashSet JavaDoc();
22
23     static
24     {
25         defaultFetchGroupTypes.add(boolean.class);
26         defaultFetchGroupTypes.add(byte.class);
27         defaultFetchGroupTypes.add(char.class);
28         defaultFetchGroupTypes.add(short.class);
29         defaultFetchGroupTypes.add(int.class);
30         defaultFetchGroupTypes.add(long.class);
31         defaultFetchGroupTypes.add(float.class);
32         defaultFetchGroupTypes.add(double.class);
33         defaultFetchGroupTypes.add(Boolean JavaDoc.class);
34         defaultFetchGroupTypes.add(Byte JavaDoc.class);
35         defaultFetchGroupTypes.add(Character JavaDoc.class);
36         defaultFetchGroupTypes.add(Short JavaDoc.class);
37         defaultFetchGroupTypes.add(Integer JavaDoc.class);
38         defaultFetchGroupTypes.add(Long JavaDoc.class);
39         defaultFetchGroupTypes.add(Float JavaDoc.class);
40         defaultFetchGroupTypes.add(Double JavaDoc.class);
41         defaultFetchGroupTypes.add(Number JavaDoc.class);
42         defaultFetchGroupTypes.add(String JavaDoc.class);
43         defaultFetchGroupTypes.add(java.math.BigDecimal JavaDoc.class);
44         defaultFetchGroupTypes.add(java.math.BigInteger JavaDoc.class);
45         defaultFetchGroupTypes.add(java.util.Date JavaDoc.class);
46         defaultFetchGroupTypes.add(java.util.Locale JavaDoc.class);
47
48         defaultPersistentTypes.add(java.util.ArrayList JavaDoc.class);
49         defaultPersistentTypes.add(java.util.Collection JavaDoc.class);
50         defaultPersistentTypes.add(java.util.HashMap JavaDoc.class);
51         defaultPersistentTypes.add(java.util.HashSet JavaDoc.class);
52         defaultPersistentTypes.add(java.util.Hashtable JavaDoc.class);
53         defaultPersistentTypes.add(java.util.LinkedList JavaDoc.class);
54         defaultPersistentTypes.add(java.util.List JavaDoc.class);
55         defaultPersistentTypes.add(java.util.Map JavaDoc.class);
56         defaultPersistentTypes.add(java.util.Set JavaDoc.class);
57         defaultPersistentTypes.add(java.util.TreeMap JavaDoc.class);
58         defaultPersistentTypes.add(java.util.TreeSet JavaDoc.class);
59         defaultPersistentTypes.add(java.util.Vector JavaDoc.class);
60     }
61
62     public static boolean isDefaultFetchGroupType(Class JavaDoc c)
63     {
64         return defaultFetchGroupTypes.contains(c);
65     }
66
67     public static boolean isDefaultEmbeddedType(Class JavaDoc c)
68     {
69         if (c == null)
70             return false;
71
72         if (isDefaultFetchGroupType(c))
73             return true;
74
75         if (isDefaultEmbeddedType(c.getComponentType()))
76             return true;
77
78         return false;
79     }
80
81     public static boolean isDefaultPersistentType(Class JavaDoc c)
82     {
83         if (c == null)
84             return false;
85
86         if (isDefaultEmbeddedType(c))
87             return true;
88
89         if (defaultPersistentTypes.contains(c))
90             return true;
91
92         if (isEnhancedClass(c))
93             return true;
94
95         if (isDefaultPersistentType(c.getComponentType()))
96             return true;
97
98         return false;
99     }
100
101     public static boolean isEnhancedClass(Class JavaDoc c)
102     {
103         if (c.isInterface())
104             return false;
105
106         /*
107          * At this point we used to test for the presence of PersistenceCapable
108          * in the list of declared interfaces. That turns out to be unreliable
109          * because an enhancer may legitimately enhance a class but NOT add
110          * PersistenceCapable to the list if its superclass is (or will be)
111          * enhanced.
112          *
113          * But checking its superclass(es) wouldn't do us any good because we
114          * need to determine whether or not THIS class has been enhanced. So
115          * instead we look for the presence of a jdoProvideField(int) method.
116          */

117         try
118         {
119             c.getDeclaredMethod("jdoProvideField", new Class JavaDoc[] { int.class });
120         }
121         catch (NoSuchMethodException JavaDoc e)
122         {
123             return false;
124         }
125
126         return true;
127     }
128
129     public static boolean isSecondClassMutableType(Class JavaDoc c)
130     {
131         return SCOProcessor.isSecondClassMutableType(c);
132     }
133 }
134
Popular Tags