KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > JDK_1_2


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o;
22
23 import java.lang.ref.*;
24
25 import com.db4o.config.*;
26 import com.db4o.foundation.*;
27 import com.db4o.reflect.generic.*;
28 import com.db4o.types.*;
29
30 class JDK_1_2 extends JDKReflect {
31     
32     JDK_1_2(){
33     }
34     
35     public static void link(){
36         // link standard translators, so they won't get deleted
37
// by deployment
38

39         Object JavaDoc obj = new TCollection();
40         obj = new TMap();
41         obj = new TSerializable();
42         obj = new TTreeMap();
43         obj = new TTreeSet();
44     }
45
46     Db4oCollections collections(YapStream a_stream){
47         return new P2Collections(a_stream);
48     }
49
50     Object JavaDoc createReferenceQueue() {
51         return new YapReferenceQueue();
52     }
53
54     public Object JavaDoc createWeakReference(Object JavaDoc obj){
55         return new WeakReference(obj);
56     }
57     
58     Object JavaDoc createYapRef(Object JavaDoc a_queue, YapObject a_yapObject, Object JavaDoc a_object) {
59         return new YapRef(a_queue, a_yapObject, a_object);
60     }
61
62     Object JavaDoc getContextClassLoader() {
63         return Thread.currentThread().getContextClassLoader();
64     }
65
66     void forEachCollectionElement(Object JavaDoc a_object, Visitor4 a_visitor) {
67         java.util.Iterator JavaDoc i = null;
68         if (a_object instanceof java.util.Collection JavaDoc) {
69             i = ((java.util.Collection JavaDoc) a_object).iterator();
70         } else if (a_object instanceof java.util.Map JavaDoc) {
71             i = ((java.util.Map JavaDoc) a_object).keySet().iterator();
72         }
73         if (i != null) {
74             while (i.hasNext()) {
75                 a_visitor.visit(i.next());
76             }
77         }
78     }
79
80     Object JavaDoc getYapRefObject(Object JavaDoc a_object) {
81         if (a_object instanceof YapRef) {
82             return ((YapRef) a_object).get();
83         }
84         return a_object;
85     }
86     
87     boolean isCollectionTranslator(Config4Class a_config) {
88         if (a_config != null) {
89             ObjectTranslator ot = a_config.getTranslator();
90             if (ot != null) {
91                 return ot instanceof TCollection || ot instanceof TMap || ot instanceof THashtable;
92             }
93         }
94         return false;
95     }
96     
97     public int ver(){
98         return 2;
99     }
100     
101     void killYapRef(Object JavaDoc obj){
102         if(obj instanceof YapRef){
103             ((YapRef)obj).i_yapObject = null;
104         }
105     }
106
107     void pollReferenceQueue(YapStream a_stream, Object JavaDoc a_referenceQueue) {
108         if (a_referenceQueue != null) {
109             YapReferenceQueue yrq = (YapReferenceQueue) a_referenceQueue;
110             YapRef ref;
111             synchronized(a_stream.lock()){
112                 while ((ref = yrq.yapPoll()) != null) {
113                     a_stream.purge1(ref.i_yapObject);
114                 }
115             }
116         }
117     }
118     
119     public void registerCollections(GenericReflector reflector) {
120         reflector.registerCollection(java.util.Collection JavaDoc.class);
121         reflector.registerCollection(java.util.Map JavaDoc.class);
122         reflector.registerCollectionUpdateDepth(java.util.Map JavaDoc.class, 3);
123     }
124
125     void setAccessible(Object JavaDoc a_accessible) {
126         ((java.lang.reflect.AccessibleObject JavaDoc) a_accessible).setAccessible(true);
127     }
128     
129     public Object JavaDoc weakReferenceTarget(Object JavaDoc weakRef){
130         if(weakRef instanceof WeakReference){
131             return ((WeakReference)weakRef).get();
132         }
133         return weakRef;
134     }
135
136 }
137
Popular Tags