KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > rpc > impl > ClientSerializationStreamReader


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.user.client.rpc.impl;
17
18 import com.google.gwt.core.client.JavaScriptObject;
19 import com.google.gwt.user.client.rpc.SerializationException;
20
21 /**
22  * For internal use only. Used for server call serialization.
23  */

24 public final class ClientSerializationStreamReader extends
25     AbstractSerializationStreamReader {
26
27   private static native JavaScriptObject eval(String JavaDoc encoded) /*-{
28     return eval(encoded);
29   }-*/
;
30
31   private static native int getLength(JavaScriptObject array) /*-{
32     return array.length;
33   }-*/
;
34
35   int index;
36
37   JavaScriptObject results;
38
39   JavaScriptObject stringTable;
40
41   private Serializer serializer;
42
43   public ClientSerializationStreamReader(Serializer serializer) {
44     this.serializer = serializer;
45   }
46
47   public void prepareToRead(String JavaDoc encoded) throws SerializationException {
48     results = eval(encoded);
49     index = getLength(results);
50     super.prepareToRead(encoded);
51     stringTable = readJavaScriptObject();
52   }
53
54   public native boolean readBoolean() /*-{
55     return !!this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::results[--this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::index];
56   }-*/
;
57
58   public native byte readByte() /*-{
59     return this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::results[--this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::index];
60   }-*/
;
61
62   public native char readChar() /*-{
63     return this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::results[--this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::index];
64   }-*/
;
65
66   public native double readDouble() /*-{
67     return this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::results[--this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::index];
68   }-*/
;
69
70   public native float readFloat() /*-{
71     return this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::results[--this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::index];
72   }-*/
;
73
74   public native int readInt() /*-{
75     return this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::results[--this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::index];
76   }-*/
;
77
78   public native long readLong() /*-{
79     return this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::results[--this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::index];
80   }-*/
;
81
82   public native short readShort() /*-{
83     return this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::results[--this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::index];
84   }-*/
;
85
86   public String JavaDoc readString() throws SerializationException {
87     return getString(readInt());
88   }
89
90   protected Object JavaDoc deserialize(String JavaDoc typeSignature)
91       throws SerializationException {
92     Object JavaDoc instance = serializer.instantiate(this, typeSignature);
93     rememberDecodedObject(instance);
94     serializer.deserialize(this, instance, typeSignature);
95     return instance;
96   }
97
98   protected native String JavaDoc getString(int index) /*-{
99     // index is 1-based
100     if (!index) {
101       return null;
102     }
103     return this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::stringTable[index - 1];
104   }-*/
;
105
106   private native JavaScriptObject readJavaScriptObject() /*-{
107     return this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::results[--this.@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::index];
108   }-*/
;
109
110 }
111
Popular Tags