KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > PendingClassInits


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 com.db4o.foundation.*;
24
25 class PendingClassInits {
26     
27     private final Transaction _systemTransaction;
28     
29     private Collection4 _pending = new Collection4();
30
31     private Queue4 _members = new Queue4();
32     private Queue4 _statics = new Queue4();
33     private Queue4 _writes = new Queue4();
34     private Queue4 _inits = new Queue4();
35     
36     private boolean _running = false;
37     
38     PendingClassInits(Transaction systemTransaction){
39         _systemTransaction = systemTransaction;
40     }
41     
42     void process(YapClass newYapClass) {
43         
44         if(_pending.contains(newYapClass)) {
45             return;
46         }
47         
48         YapClass ancestor = newYapClass.getAncestor();
49         if (ancestor != null) {
50             process(ancestor);
51         }
52         
53         _pending.add(newYapClass);
54         
55         _members.add(newYapClass);
56         
57         
58         if(_running) {
59             return;
60         }
61         
62         _running = true;
63         
64         checkInits();
65         
66         _pending = new Collection4();
67         
68         _running = false;
69     }
70
71     
72     private void checkMembers() {
73         while(_members.hasNext()) {
74             YapClass yc = (YapClass)_members.next();
75             yc.addMembers(stream());
76             _statics.add(yc);
77         }
78     }
79
80     private YapStream stream() {
81         return _systemTransaction.stream();
82     }
83     
84     private void checkStatics() {
85         checkMembers();
86         while(_statics.hasNext()) {
87             YapClass yc = (YapClass)_statics.next();
88             yc.storeStaticFieldValues(_systemTransaction, true);
89             _writes.add(yc);
90             checkMembers();
91         }
92     }
93     
94     private void checkWrites() {
95         checkStatics();
96         while(_writes.hasNext()) {
97             YapClass yc = (YapClass)_writes.next();
98             yc.setStateDirty();
99             yc.write(_systemTransaction);
100             _inits.add(yc);
101             checkStatics();
102         }
103     }
104     
105     private void checkInits() {
106         checkWrites();
107         while(_inits.hasNext()) {
108             YapClass yc = (YapClass)_inits.next();
109             yc.initConfigOnUp(_systemTransaction);
110             checkWrites();
111         }
112     }
113
114
115 }
116
Popular Tags