KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > inside > marshall > UntypedMarshaller1


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.inside.marshall;
22
23 import com.db4o.*;
24
25 /**
26  * @exclude
27  */

28 public class UntypedMarshaller1 extends UntypedMarshaller{
29     
30     public boolean useNormalClassRead(){
31         return false;
32     }
33     
34     public void deleteEmbedded(YapWriter reader) {
35         int payLoadOffset = reader.readInt();
36         if (payLoadOffset > 0) {
37             int linkOffset = reader._offset;
38             reader._offset = payLoadOffset;
39             int yapClassID = reader.readInt();
40             YapClass yc = reader.getStream().getYapClass(yapClassID);
41             if(yc != null){
42                 yc.deleteEmbedded(_family, reader);
43             }
44             reader._offset = linkOffset;
45         }
46     }
47     
48     public Object JavaDoc read(YapWriter reader) throws CorruptionException{
49         
50         Object JavaDoc ret = null;
51         
52         int payLoadOffSet = reader.readInt();
53         if(payLoadOffSet == 0){
54             return null;
55         }
56         
57         int linkOffSet = reader._offset;
58         reader._offset = payLoadOffSet;
59         
60         int yapClassID = reader.readInt();
61         
62         YapClass yc = reader.getStream().getYapClass(yapClassID);
63         if(yc != null){
64             ret = yc.read(_family, reader, true);
65         }
66         
67         reader._offset = linkOffSet;
68         
69         return ret;
70     }
71     
72     public Object JavaDoc readQuery(Transaction trans, YapReader reader, boolean toArray) throws CorruptionException{
73         
74         Object JavaDoc ret = null;
75         
76         int payLoadOffSet = reader.readInt();
77         if(payLoadOffSet == 0){
78             return null;
79         }
80         
81         int linkOffSet = reader._offset;
82         reader._offset = payLoadOffSet;
83         
84         int yapClassID = reader.readInt();
85         
86         YapClass yc = trans.stream().getYapClass(yapClassID);
87         if(yc != null){
88             ret = yc.readQuery(trans, _family, false, reader, toArray);
89         }
90         
91         reader._offset = linkOffSet;
92         
93         return ret;
94     }
95
96     
97     public TypeHandler4 readArrayHandler(Transaction trans, YapReader[] reader) {
98         
99         int payLoadOffSet = reader[0].readInt();
100         if(payLoadOffSet == 0){
101             return null;
102         }
103
104         TypeHandler4 ret = null;
105
106         reader[0]._offset = payLoadOffSet;
107         
108         int yapClassID = reader[0].readInt();
109         
110         YapClass yc = trans.stream().getYapClass(yapClassID);
111         if(yc != null){
112             ret = yc.readArrayHandler(trans, _family, reader);
113         }
114         return ret;
115     }
116     
117     public QCandidate readSubCandidate(YapReader reader, QCandidates candidates, boolean withIndirection) {
118         int payLoadOffSet = reader.readInt();
119         if(payLoadOffSet == 0){
120             return null;
121         }
122         
123         QCandidate ret = null;
124
125         int linkOffSet = reader._offset;
126         reader._offset = payLoadOffSet;
127         
128         int yapClassID = reader.readInt();
129         
130         YapClass yc = candidates.i_trans.stream().getYapClass(yapClassID);
131         if(yc != null){
132             ret = yc.readSubCandidate(_family, reader, candidates, false);
133         }
134         reader._offset = linkOffSet;
135         
136         return ret;
137     }
138
139     
140     public Object JavaDoc writeNew(Object JavaDoc obj, boolean restoreLinkOffset, YapWriter writer) {
141         if (obj == null) {
142             writer.writeInt(0);
143             return new Integer JavaDoc(0);
144         }
145         
146         YapClass yc = YapClass.forObject(writer.getTransaction(), obj, false);
147         
148         if(yc == null){
149             writer.writeInt(0);
150             return new Integer JavaDoc(0);
151         }
152         
153         
154         writer.writeInt(writer._payloadOffset);
155         int linkOffset = writer._offset;
156         writer._offset = writer._payloadOffset;
157         
158         
159         writer.writeInt(yc.getID());
160         
161         yc.writeNew(_family, obj, false, writer, false, false);
162         
163         if(writer._payloadOffset < writer._offset){
164             writer._payloadOffset = writer._offset;
165         }
166         
167         if(restoreLinkOffset){
168             writer._offset = linkOffset;
169         }
170         
171         return obj;
172     }
173
174     public void defrag(ReaderPair readers) {
175         int payLoadOffSet = readers.readInt();
176         if(payLoadOffSet == 0){
177             return;
178         }
179         int linkOffSet = readers.offset();
180         readers.offset(payLoadOffSet);
181         
182         int yapClassID = readers.copyIDAndRetrieveMapping().orig();
183         
184         YapClass yc = readers.context().yapClass(yapClassID);
185         if(yc != null){
186             yc.defrag(_family, readers, false);
187         }
188         
189         readers.offset(linkOffSet);
190     }
191 }
192
Popular Tags