KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > il > oil2 > OIL2Response


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.mq.il.oil2;
8
9 import java.io.IOException JavaDoc;
10
11 import javax.jms.JMSException JavaDoc;
12
13 /**
14  *
15  *
16  * @author <a HREF="mailto:hiram.chirino@jboss.org">Hiram Chirino</a>
17  * @version $Revision: 1.2 $
18  */

19 public class OIL2Response
20 {
21    Integer JavaDoc correlationRequestId;
22    byte operation;
23    Object JavaDoc result;
24    Throwable JavaDoc exception;
25    
26    public OIL2Response() {}
27    public OIL2Response(OIL2Request request) {
28       correlationRequestId = request.requestId;
29       operation = request.operation;
30    }
31    
32    
33    public Object JavaDoc evalThrowsJMSException() throws JMSException JavaDoc, IOException JavaDoc {
34       if( exception != null ) {
35          if( exception instanceof JMSException JavaDoc ) {
36             throw (JMSException JavaDoc)exception;
37          } else {
38             throw new IOException JavaDoc("Protocol violation: unexpected exception found in response: "+exception);
39          }
40       }
41       return result;
42    }
43    
44    public Object JavaDoc evalThrowsException() throws Exception JavaDoc {
45       if( exception != null ) {
46          if( exception instanceof Exception JavaDoc ) {
47             throw (Exception JavaDoc)exception;
48          } else {
49             throw new IOException JavaDoc("Protocol violation: unexpected exception found in response: "+exception);
50          }
51       }
52       return result;
53    }
54    
55    public Object JavaDoc evalThrowsThrowable() throws Throwable JavaDoc {
56       if( exception != null ) {
57          throw exception;
58       }
59       return result;
60    }
61    
62
63    public void writeExternal(java.io.ObjectOutput JavaDoc out) throws IOException JavaDoc
64    {
65       out.writeByte(operation);
66       
67       if( correlationRequestId == null ) {
68          out.writeByte(0);
69       } else {
70          out.writeByte(1);
71          out.writeInt(correlationRequestId.intValue());
72       }
73       
74       if( exception != null ) {
75          out.writeByte(OIL2Constants.RESULT_EXCEPTION);
76          out.writeObject(exception);
77          return;
78       }
79       if( result == null ) {
80          out.writeByte(OIL2Constants.RESULT_VOID);
81          return;
82       }
83       switch (operation)
84       {
85          default :
86             out.writeByte(OIL2Constants.RESULT_OBJECT);
87             out.writeObject(result);
88             return;
89       }
90    }
91
92    public void readExternal(java.io.ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
93    {
94       operation = in.readByte();
95       if( in.readByte() == 1)
96           correlationRequestId = new Integer JavaDoc(in.readInt());
97           
98       byte responseType = in.readByte();
99       switch( responseType ) {
100          case OIL2Constants.RESULT_VOID:
101             result=null;
102             exception=null;
103             break;
104          case OIL2Constants.RESULT_EXCEPTION:
105             result=null;
106             exception=(Throwable JavaDoc)in.readObject();
107             break;
108          case OIL2Constants.RESULT_OBJECT:
109             exception=null;
110             switch (operation)
111             {
112                default :
113                result=in.readObject();
114             }
115             break;
116          default :
117             throw new IOException JavaDoc("Protocol Error: Bad response type code '"+responseType+"' ");
118          
119       }
120      
121    }
122    
123    public String JavaDoc toString() {
124       return "[operation:"+operation+","+"correlationRequestId:"+correlationRequestId+",result:"+result+",exception:"+exception+"]";
125    }
126
127 }
128
Popular Tags