1 package org.jacorb.orb.giop; 2 3 22 23 import org.jacorb.orb.SystemExceptionHelper; 24 import org.jacorb.util.*; 25 26 import org.omg.GIOP.*; 27 import org.omg.IOP.*; 28 import org.omg.CORBA.MARSHAL ; 29 import org.omg.CORBA.portable.ApplicationException ; 30 import org.omg.PortableServer.ForwardRequest ; 31 32 37 38 public class ReplyInputStream 39 extends ServiceContextTransportingInputStream 40 { 41 public ReplyHeader_1_2 rep_hdr = null; 42 private int body_start; 43 44 public ReplyInputStream( org.omg.CORBA.ORB orb, byte[] buffer ) 45 { 46 super( orb, buffer ); 47 48 if( Messages.getMsgType( buffer ) != MsgType_1_1._Reply ) 50 { 51 throw new MARSHAL ("Not a reply!"); 52 } 53 54 switch( giop_minor ) 55 { 56 case 0 : 57 { 58 } 60 case 1 : 61 { 62 ReplyHeader_1_0 hdr = 64 ReplyHeader_1_0Helper.read( this ); 65 66 body_start = pos; 67 68 rep_hdr = 69 new ReplyHeader_1_2( hdr.request_id, 70 ReplyStatusType_1_2.from_int( hdr.reply_status.value() ), 71 hdr.service_context ); 72 break; 73 } 74 case 2 : 75 { 76 rep_hdr = ReplyHeader_1_2Helper.read( this ); 78 79 skipHeaderPadding(); 80 81 body_start = pos; 82 83 break; 84 } 85 default : { 86 throw new MARSHAL ("Unknown GIOP minor version: " + giop_minor); 87 } 88 } 89 } 90 91 94 public ReplyStatusType_1_2 getStatus() 95 { 96 return rep_hdr.reply_status; 97 } 98 99 105 public synchronized Exception getException() 106 { 107 switch( rep_hdr.reply_status.value() ) 108 { 109 case ReplyStatusType_1_2._USER_EXCEPTION : 110 { 111 mark( 0 ); 112 String id = read_string(); 113 114 try 115 { 116 reset(); 117 } 118 catch( java.io.IOException ioe ) 119 { 120 } 123 return new ApplicationException ( id, this ); 124 } 125 case ReplyStatusType_1_2._SYSTEM_EXCEPTION: 126 { 127 return SystemExceptionHelper.read( this ); 128 } 129 case ReplyStatusType_1_2._LOCATION_FORWARD: 130 case ReplyStatusType_1_2._LOCATION_FORWARD_PERM: 131 { 132 return new ForwardRequest ( read_Object() ); 133 } 134 default: 135 { 136 return null; 137 } 138 } 139 } 140 141 145 public ServiceContext getServiceContext(int id) 146 { 147 if (rep_hdr.service_context != null) 148 { 149 for (int i=0; i<rep_hdr.service_context.length; i++) 150 { 151 if (rep_hdr.service_context[i].context_id == id) 152 return rep_hdr.service_context[i]; 153 } 154 } 155 return null; 156 } 157 158 162 public byte[] getBody() 163 { 164 int body_length = msg_size - (body_start - Messages.MSG_HEADER_SIZE); 165 byte[] body = new byte[body_length]; 166 System.arraycopy (buffer, body_start, body, 0, body_length); 167 return body; 168 } 169 170 protected void finalize() throws Throwable 171 { 172 try 173 { 174 close(); 175 } 176 catch( java.io.IOException iox ) 177 { 178 } 180 finally 181 { 182 super.finalize(); 183 } 184 } 185 } 186 | Popular Tags |