1 7 package org.jboss.mq.il.oil2; 8 9 import java.io.IOException ; 10 11 import javax.jms.JMSException ; 12 13 19 public class OIL2Response 20 { 21 Integer correlationRequestId; 22 byte operation; 23 Object result; 24 Throwable exception; 25 26 public OIL2Response() {} 27 public OIL2Response(OIL2Request request) { 28 correlationRequestId = request.requestId; 29 operation = request.operation; 30 } 31 32 33 public Object evalThrowsJMSException() throws JMSException , IOException { 34 if( exception != null ) { 35 if( exception instanceof JMSException ) { 36 throw (JMSException )exception; 37 } else { 38 throw new IOException ("Protocol violation: unexpected exception found in response: "+exception); 39 } 40 } 41 return result; 42 } 43 44 public Object evalThrowsException() throws Exception { 45 if( exception != null ) { 46 if( exception instanceof Exception ) { 47 throw (Exception )exception; 48 } else { 49 throw new IOException ("Protocol violation: unexpected exception found in response: "+exception); 50 } 51 } 52 return result; 53 } 54 55 public Object evalThrowsThrowable() throws Throwable { 56 if( exception != null ) { 57 throw exception; 58 } 59 return result; 60 } 61 62 63 public void writeExternal(java.io.ObjectOutput out) throws IOException 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 in) throws IOException , ClassNotFoundException 93 { 94 operation = in.readByte(); 95 if( in.readByte() == 1) 96 correlationRequestId = new Integer (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 )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 ("Protocol Error: Bad response type code '"+responseType+"' "); 118 119 } 120 121 } 122 123 public String toString() { 124 return "[operation:"+operation+","+"correlationRequestId:"+correlationRequestId+",result:"+result+",exception:"+exception+"]"; 125 } 126 127 } 128 | Popular Tags |