KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > hessian > io > AbstractHessianInput


1 /*
2  * Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
3  *
4  * The Apache Software License, Version 1.1
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution, if
19  * any, must include the following acknowlegement:
20  * "This product includes software developed by the
21  * Caucho Technology (http://www.caucho.com/)."
22  * Alternately, this acknowlegement may appear in the software itself,
23  * if and wherever such third-party acknowlegements normally appear.
24  *
25  * 4. The names "Burlap", "Resin", and "Caucho" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * info@caucho.com.
29  *
30  * 5. Products derived from this software may not be called "Resin"
31  * nor may "Resin" appear in their names without prior written
32  * permission of Caucho Technology.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37  * DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
38  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
39  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
40  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
43  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
44  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  * @author Scott Ferguson
47  */

48
49 package com.caucho.hessian.io;
50
51 import java.io.IOException JavaDoc;
52 import java.io.InputStream JavaDoc;
53 import java.io.Reader JavaDoc;
54
55 /**
56  * Abstract base class for Hessian requests. Hessian users should only
57  * need to use the methods in this class.
58  *
59  * <pre>
60  * AbstractHessianInput in = ...; // get input
61  * String value;
62  *
63  * in.startReply(); // read reply header
64  * value = in.readString(); // read string value
65  * in.completeReply(); // read reply footer
66  * </pre>
67  */

68 abstract public class AbstractHessianInput {
69   private HessianRemoteResolver resolver;
70   
71   /**
72    * Initialize the Hessian stream with the underlying input stream.
73    */

74   public void init(InputStream JavaDoc is)
75   {
76   }
77
78   /**
79    * Returns the call's method
80    */

81   abstract public String JavaDoc getMethod();
82
83   /**
84    * Sets the resolver used to lookup remote objects.
85    */

86   public void setRemoteResolver(HessianRemoteResolver resolver)
87   {
88     this.resolver = resolver;
89   }
90
91   /**
92    * Sets the resolver used to lookup remote objects.
93    */

94   public HessianRemoteResolver getRemoteResolver()
95   {
96     return resolver;
97   }
98
99   /**
100    * Sets the serializer factory.
101    */

102   public void setSerializerFactory(SerializerFactory ser)
103   {
104   }
105
106   /**
107    * Reads the call
108    *
109    * <pre>
110    * c major minor
111    * </pre>
112    */

113   abstract public int readCall()
114     throws IOException JavaDoc;
115
116   /**
117    * Reads a header, returning null if there are no headers.
118    *
119    * <pre>
120    * H b16 b8 value
121    * </pre>
122    */

123   abstract public String JavaDoc readHeader()
124     throws IOException JavaDoc;
125
126   /**
127    * Starts reading the call
128    *
129    * <p>A successful completion will have a single value:
130    *
131    * <pre>
132    * m b16 b8 method
133    * </pre>
134    */

135   abstract public String JavaDoc readMethod()
136     throws IOException JavaDoc;
137
138   /**
139    * Starts reading the call, including the headers.
140    *
141    * <p>The call expects the following protocol data
142    *
143    * <pre>
144    * c major minor
145    * m b16 b8 method
146    * </pre>
147    */

148   abstract public void startCall()
149     throws IOException JavaDoc;
150
151   /**
152    * Completes reading the call
153    *
154    * <p>The call expects the following protocol data
155    *
156    * <pre>
157    * Z
158    * </pre>
159    */

160   abstract public void completeCall()
161     throws IOException JavaDoc;
162
163   /**
164    * Reads a reply as an object.
165    * If the reply has a fault, throws the exception.
166    */

167   abstract public Object JavaDoc readReply(Class JavaDoc expectedClass)
168     throws Throwable JavaDoc;
169   
170   /**
171    * Starts reading the reply
172    *
173    * <p>A successful completion will have a single value:
174    *
175    * <pre>
176    * r
177    * v
178    * </pre>
179    */

180   abstract public void startReply()
181     throws Throwable JavaDoc;
182
183   /**
184    * Completes reading the call
185    *
186    * <p>A successful completion will have a single value:
187    *
188    * <pre>
189    * z
190    * </pre>
191    */

192   abstract public void completeReply()
193     throws IOException JavaDoc;
194
195   /**
196    * Reads a boolean
197    *
198    * <pre>
199    * T
200    * F
201    * </pre>
202    */

203   abstract public boolean readBoolean()
204     throws IOException JavaDoc;
205
206   /**
207    * Reads a null
208    *
209    * <pre>
210    * N
211    * </pre>
212    */

213   abstract public void readNull()
214     throws IOException JavaDoc;
215
216   /**
217    * Reads an integer
218    *
219    * <pre>
220    * I b32 b24 b16 b8
221    * </pre>
222    */

223   abstract public int readInt()
224     throws IOException JavaDoc;
225
226   /**
227    * Reads a long
228    *
229    * <pre>
230    * L b64 b56 b48 b40 b32 b24 b16 b8
231    * </pre>
232    */

233   abstract public long readLong()
234     throws IOException JavaDoc;
235
236   /**
237    * Reads a double.
238    *
239    * <pre>
240    * D b64 b56 b48 b40 b32 b24 b16 b8
241    * </pre>
242    */

243   abstract public double readDouble()
244     throws IOException JavaDoc;
245
246   /**
247    * Reads a date.
248    *
249    * <pre>
250    * T b64 b56 b48 b40 b32 b24 b16 b8
251    * </pre>
252    */

253   abstract public long readUTCDate()
254     throws IOException JavaDoc;
255
256   /**
257    * Reads a string encoded in UTF-8
258    *
259    * <pre>
260    * s b16 b8 non-final string chunk
261    * S b16 b8 final string chunk
262    * </pre>
263    */

264   abstract public String JavaDoc readString()
265     throws IOException JavaDoc;
266
267   /**
268    * Reads an XML node encoded in UTF-8
269    *
270    * <pre>
271    * x b16 b8 non-final xml chunk
272    * X b16 b8 final xml chunk
273    * </pre>
274    */

275   abstract public org.w3c.dom.Node JavaDoc readNode()
276     throws IOException JavaDoc;
277   
278   /**
279    * Starts reading a string. All the characters must be read before
280    * calling the next method. The actual characters will be read with
281    * the reader's read() or read(char [], int, int).
282    *
283    * <pre>
284    * s b16 b8 non-final string chunk
285    * S b16 b8 final string chunk
286    * </pre>
287    */

288   abstract public Reader JavaDoc getReader()
289     throws IOException JavaDoc;
290
291   /**
292    * Starts reading a byte array using an input stream. All the bytes
293    * must be read before calling the following method.
294    *
295    * <pre>
296    * b b16 b8 non-final binary chunk
297    * B b16 b8 final binary chunk
298    * </pre>
299    */

300   abstract public InputStream JavaDoc readInputStream()
301     throws IOException JavaDoc;
302
303   /**
304    * Reads a byte array.
305    *
306    * <pre>
307    * b b16 b8 non-final binary chunk
308    * B b16 b8 final binary chunk
309    * </pre>
310    */

311   abstract public byte []readBytes()
312     throws IOException JavaDoc;
313
314   /**
315    * Reads an arbitrary object from the input stream.
316    *
317    * @param expectedClass the expected class if the protocol doesn't supply it.
318    */

319   abstract public Object JavaDoc readObject(Class JavaDoc expectedClass)
320     throws IOException JavaDoc;
321
322   /**
323    * Reads an arbitrary object from the input stream.
324    */

325   abstract public Object JavaDoc readObject()
326     throws IOException JavaDoc;
327
328   /**
329    * Reads a remote object reference to the stream. The type is the
330    * type of the remote interface.
331    *
332    * <code><pre>
333    * 'r' 't' b16 b8 type url
334    * </pre></code>
335    */

336   abstract public Object JavaDoc readRemote()
337     throws IOException JavaDoc;
338
339   /**
340    * Reads a reference
341    *
342    * <pre>
343    * R b32 b24 b16 b8
344    * </pre>
345    */

346   abstract public Object JavaDoc readRef()
347     throws IOException JavaDoc;
348
349   /**
350    * Adds an object reference.
351    */

352   abstract public int addRef(Object JavaDoc obj)
353     throws IOException JavaDoc;
354
355   /**
356    * Sets an object reference.
357    */

358   abstract public void setRef(int i, Object JavaDoc obj)
359     throws IOException JavaDoc;
360
361   /**
362    * Reads the start of a list
363    */

364   abstract public int readListStart()
365     throws IOException JavaDoc;
366
367   /**
368    * Reads the length of a list.
369    */

370   abstract public int readLength()
371     throws IOException JavaDoc;
372
373   /**
374    * Reads the start of a map
375    */

376   abstract public int readMapStart()
377     throws IOException JavaDoc;
378
379   /**
380    * Reads an object type.
381    */

382   abstract public String JavaDoc readType()
383     throws IOException JavaDoc;
384
385   /**
386    * Returns true if the data has ended.
387    */

388   abstract public boolean isEnd()
389     throws IOException JavaDoc;
390
391   /**
392    * Read the end byte
393    */

394   abstract public void readEnd()
395     throws IOException JavaDoc;
396
397   /**
398    * Read the end byte
399    */

400   abstract public void readMapEnd()
401     throws IOException JavaDoc;
402
403   /**
404    * Read the end byte
405    */

406   abstract public void readListEnd()
407     throws IOException JavaDoc;
408 }
409
Popular Tags