KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > YapFieldTranslator


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.config.*;
24 import com.db4o.inside.marshall.*;
25
26 final class YapFieldTranslator extends YapField
27 {
28     private final ObjectTranslator i_translator;
29
30     YapFieldTranslator(YapClass a_yapClass, ObjectTranslator a_translator){
31         super(a_yapClass, a_translator);
32         i_translator = a_translator;
33         YapStream stream = a_yapClass.getStream();
34         configure(stream.reflector().forClass(a_translator.storedClass()), false);
35     }
36     
37     public boolean canUseNullBitmap(){
38         return false;
39     }
40
41     void deactivate(Transaction a_trans, Object JavaDoc a_onObject, int a_depth){
42         if(a_depth > 0){
43             cascadeActivation(a_trans, a_onObject, a_depth, false);
44         }
45         setOn(a_trans.stream(), a_onObject, null);
46     }
47
48     public Object JavaDoc getOn(Transaction a_trans, Object JavaDoc a_OnObject){
49         try{
50             return i_translator.onStore(a_trans.stream(), a_OnObject);
51         }catch(Throwable JavaDoc t){
52             return null;
53         }
54     }
55     
56     public Object JavaDoc getOrCreate(Transaction a_trans, Object JavaDoc a_OnObject) {
57         return getOn(a_trans, a_OnObject);
58     }
59
60     public void instantiate(MarshallerFamily mf, YapObject a_yapObject, Object JavaDoc a_onObject, YapWriter a_bytes) throws CorruptionException{
61         Object JavaDoc toSet = read(mf, a_bytes);
62
63         // Activation of members is necessary on purpose here.
64
// Classes like Hashtable need fully activated members
65
// to be able to calculate hashCode()
66

67         a_bytes.getStream().activate1(a_bytes.getTransaction(), toSet, a_bytes.getInstantiationDepth());
68
69         setOn(a_bytes.getStream(), a_onObject, toSet);
70     }
71     
72     void refresh() {
73         // do nothing
74
}
75     
76     private void setOn(YapStream a_stream, Object JavaDoc a_onObject, Object JavaDoc toSet){
77         try{
78             i_translator.onActivate(a_stream, a_onObject, toSet);
79         }catch(Throwable JavaDoc t){}
80     }
81 }
82
Popular Tags