KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > remote > hessian > DataRowDeserializer


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.remote.hessian;
21
22 import java.io.IOException JavaDoc;
23 import java.lang.reflect.Field JavaDoc;
24
25 import org.apache.cayenne.CayenneRuntimeException;
26 import org.apache.cayenne.DataRow;
27
28 import com.caucho.hessian.io.AbstractHessianInput;
29 import com.caucho.hessian.io.AbstractMapDeserializer;
30
31 /**
32  * Client side deserilaizer of DataRows.
33  *
34  * @author Andrus Adamchik
35  * @since 1.2
36  */

37 class DataRowDeserializer extends AbstractMapDeserializer {
38
39     protected Field JavaDoc versionField;
40
41     DataRowDeserializer() {
42         try {
43             versionField = DataRow.class.getDeclaredField("version");
44         }
45         catch (Exception JavaDoc e) {
46             throw new CayenneRuntimeException(
47                     "Error building deserializer for DataRow",
48                     e);
49         }
50
51         versionField.setAccessible(true);
52     }
53
54     public Class JavaDoc getType() {
55         return DataRow.class;
56     }
57
58     public Object JavaDoc readMap(AbstractHessianInput in) throws IOException JavaDoc {
59
60         int size = in.readInt();
61         DataRow row = new DataRow(size);
62         try {
63             versionField.set(row, new Long JavaDoc(in.readLong()));
64         }
65         catch (Exception JavaDoc e) {
66             throw new IOException JavaDoc("Error reading 'version' field");
67         }
68
69         row.setReplacesVersion(in.readLong());
70         in.addRef(row);
71
72         while (!in.isEnd()) {
73             row.put(in.readObject(), in.readObject());
74         }
75
76         in.readEnd();
77
78         return row;
79     }
80 }
81
Popular Tags