KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.db4o.inside.*;
25
26
27 /**
28  * @exclude
29  */

30 public class UntypedMarshaller0 extends UntypedMarshaller {
31     
32     public void deleteEmbedded(YapWriter parentBytes) {
33         int objectID = parentBytes.readInt();
34         if (objectID > 0) {
35             YapWriter reader =
36                 parentBytes.getStream().readWriterByID(parentBytes.getTransaction(), objectID);
37             if (reader != null) {
38                 reader.setCascadeDeletes(parentBytes.cascadeDeletes());
39                 ObjectHeader oh = new ObjectHeader(reader);
40                 if(oh.yapClass() != null){
41                     oh.yapClass().deleteEmbedded1(_family, reader, objectID);
42                 }
43             }
44         }
45     }
46     
47     public boolean useNormalClassRead(){
48         return true;
49     }
50
51
52     public Object JavaDoc read(YapWriter reader) {
53         throw Exceptions4.shouldNeverBeCalled();
54     }
55     
56     public Object JavaDoc readQuery(Transaction trans, YapReader reader, boolean toArray) throws CorruptionException{
57         throw Exceptions4.shouldNeverBeCalled();
58     }
59
60     
61     public TypeHandler4 readArrayHandler(Transaction a_trans, YapReader[] a_bytes) {
62         int id = 0;
63
64         int offset = a_bytes[0]._offset;
65         try {
66             id = a_bytes[0].readInt();
67         } catch (Exception JavaDoc e) {
68         }
69         a_bytes[0]._offset = offset;
70
71         if (id != 0) {
72             YapWriter reader =
73                 a_trans.stream().readWriterByID(a_trans, id);
74             if (reader != null) {
75                 ObjectHeader oh = new ObjectHeader(reader);
76                 try {
77                     if (oh.yapClass() != null) {
78                         a_bytes[0] = reader;
79                         return oh.yapClass().readArrayHandler1(a_bytes);
80                     }
81                 } catch (Exception JavaDoc e) {
82                     
83                     if(Debug.atHome){
84                         e.printStackTrace();
85                     }
86                     
87                     // TODO: Check Exception Types
88
// Errors typically occur, if classes don't match
89
}
90             }
91         }
92         return null;
93     }
94
95     public QCandidate readSubCandidate(YapReader reader, QCandidates candidates, boolean withIndirection) {
96         return null;
97     }
98
99     public Object JavaDoc writeNew(Object JavaDoc a_object, boolean restoreLinkOffset, YapWriter a_bytes) {
100         if (a_object == null) {
101             a_bytes.writeInt(0);
102             return new Integer JavaDoc(0);
103         }
104
105         int id = a_bytes.getStream().setInternal(
106                     a_bytes.getTransaction(),
107                     a_object,
108                     a_bytes.getUpdateDepth(), true);
109         
110         a_bytes.writeInt(id);
111         return new Integer JavaDoc(id);
112     }
113
114     public void defrag(ReaderPair readers) {
115         // TODO
116
}
117 }
118
Popular Tags