01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: 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.internal.cs.messages;
22:
23: import com.db4o.internal.*;
24: import com.db4o.internal.slots.*;
25:
26: public class MsgObject extends MsgD {
27:
28: private static final int LENGTH_FOR_ALL = Const4.ID_LENGTH
29: + (Const4.INT_LENGTH * 2);
30: private static final int LENGTH_FOR_FIRST = LENGTH_FOR_ALL;
31:
32: private int _id;
33: private int _address;
34:
35: final MsgD getWriter(Transaction trans, Pointer4 pointer,
36: Buffer buffer, int[] prependInts) {
37: int lengthNeeded = buffer.length() + LENGTH_FOR_FIRST;
38: if (prependInts != null) {
39: lengthNeeded += (prependInts.length * Const4.INT_LENGTH);
40: }
41: MsgD message = getWriterForLength(trans, lengthNeeded);
42: if (prependInts != null) {
43: for (int i = 0; i < prependInts.length; i++) {
44: message._payLoad.writeInt(prependInts[i]);
45: }
46: }
47: message._payLoad.append(pointer, buffer);
48: return message;
49: }
50:
51: final public MsgD getWriter(StatefulBuffer buffer) {
52: return getWriter(buffer.getTransaction(), buffer.pointer(),
53: buffer, null);
54: }
55:
56: public final MsgD getWriter(Transaction trans, Pointer4 pointer,
57: ClassMetadata classMetadata, Buffer buffer) {
58: if (classMetadata == null) {
59: return getWriter(trans, pointer, buffer, new int[] { 0 });
60: }
61: return getWriter(trans, pointer, buffer,
62: new int[] { classMetadata.getID() });
63: }
64:
65: public final MsgD getWriter(Transaction trans, Pointer4 pointer,
66: ClassMetadata classMetadata, int param, Buffer buffer) {
67: return getWriter(trans, pointer, buffer, new int[] {
68: classMetadata.getID(), param });
69: }
70:
71: public final StatefulBuffer unmarshall() {
72: return unmarshall(0);
73: }
74:
75: public final StatefulBuffer unmarshall(int addLengthBeforeFirst) {
76: _payLoad.setTransaction(transaction());
77:
78: int length = _payLoad.readInt();
79: if (length == 0) {
80: return null; // does this happen ?
81: }
82: _id = _payLoad.readInt();
83: _address = _payLoad.readInt();
84: _payLoad.removeFirstBytes(LENGTH_FOR_FIRST
85: + addLengthBeforeFirst);
86: _payLoad.useSlot(_id, _address, length);
87: return _payLoad;
88: }
89:
90: public int getId() {
91: return _id;
92: }
93: }
|