1 7 15 16 package com.sun.corba.se.impl.corba; 17 18 import org.omg.CORBA.Any ; 19 import org.omg.CORBA.Context ; 20 import org.omg.CORBA.NamedValue ; 21 import org.omg.CORBA.NVList ; 22 import org.omg.CORBA.TypeCode ; 23 import org.omg.CORBA.TCKind ; 24 import org.omg.CORBA.ServerRequest ; 25 import org.omg.CORBA.Bounds ; 26 import org.omg.CORBA.portable.InputStream ; 27 import org.omg.CORBA.portable.OutputStream ; 28 import org.omg.CORBA.CompletionStatus ; 29 30 import com.sun.corba.se.spi.orb.ORB ; 31 import com.sun.corba.se.spi.protocol.CorbaMessageMediator; 32 33 import com.sun.corba.se.spi.logging.CORBALogDomains ; 34 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 35 36 public class ServerRequestImpl extends ServerRequest { 37 38 41 private ORB _orb = null; 42 private ORBUtilSystemException _wrapper = null; 43 private String _opName = null; 44 private NVList _arguments = null; 45 private Context _ctx = null; 46 private InputStream _ins = null; 47 48 private boolean _paramsCalled = false; 50 private boolean _resultSet = false; 51 private boolean _exceptionSet = false; 52 private Any _resultAny = null; 53 private Any _exception = null; 54 55 56 public ServerRequestImpl (CorbaMessageMediator req, ORB orb) { 57 _opName = req.getOperationName(); 58 _ins = (InputStream )req.getInputObject(); 59 _ctx = null; _orb = orb; 63 _wrapper = ORBUtilSystemException.get( orb, 64 CORBALogDomains.OA_INVOCATION ) ; 65 } 66 67 public String operation() { 68 return _opName; 69 } 70 71 public void arguments(NVList args) 72 { 73 if (_paramsCalled) 74 throw _wrapper.argumentsCalledMultiple() ; 75 76 if (_exceptionSet) 77 throw _wrapper.argumentsCalledAfterException() ; 78 79 if (args == null ) 80 throw _wrapper.argumentsCalledNullArgs() ; 81 82 _paramsCalled = true; 83 84 NamedValue arg = null; 85 for (int i=0; i < args.count() ; i++) { 86 try { 87 arg = args.item(i); 88 } catch (Bounds e) { 89 throw _wrapper.boundsCannotOccur(e) ; 90 } 91 92 try { 93 if ((arg.flags() == org.omg.CORBA.ARG_IN.value) || 94 (arg.flags() == org.omg.CORBA.ARG_INOUT.value)) { 95 arg.value().read_value(_ins, arg.value().type()); 97 } 98 } catch ( Exception ex ) { 99 throw _wrapper.badArgumentsNvlist( ex ) ; 100 } 101 } 102 103 _arguments = args; 105 106 _orb.getPIHandler().setServerPIInfo( _arguments ); 107 _orb.getPIHandler().invokeServerPIIntermediatePoint(); 108 } 109 110 public void set_result(Any res) { 111 if (!_paramsCalled) 113 throw _wrapper.argumentsNotCalled() ; 114 if (_resultSet) 115 throw _wrapper.setResultCalledMultiple() ; 116 if (_exceptionSet) 117 throw _wrapper.setResultAfterException() ; 118 if ( res == null ) 119 throw _wrapper.setResultCalledNullArgs() ; 120 121 _resultAny = res; 122 _resultSet = true; 123 124 _orb.getPIHandler().setServerPIInfo( _resultAny ); 127 128 } 131 132 public void set_exception(Any exc) 133 { 134 136 if ( exc == null ) 137 throw _wrapper.setExceptionCalledNullArgs() ; 138 139 TCKind kind = exc.type().kind(); 143 if ( kind != TCKind.tk_except ) 144 throw _wrapper.setExceptionCalledBadType() ; 145 146 _exception = exc; 147 148 _orb.getPIHandler().setServerPIExceptionInfo( _exception ); 151 152 if( !_exceptionSet && !_paramsCalled ) { 158 _orb.getPIHandler().invokeServerPIIntermediatePoint(); 160 } 161 162 _exceptionSet = true; 163 164 } 167 168 169 174 public Any checkResultCalled() 175 { 176 184 if ( _paramsCalled && _resultSet ) return null; 186 else if ( _paramsCalled && !_resultSet && !_exceptionSet ) { 187 try { 188 TypeCode result_tc = _orb.get_primitive_tc( 193 org.omg.CORBA.TCKind.tk_void); 194 _resultAny = _orb.create_any(); 195 _resultAny.type(result_tc); 196 _resultSet = true; 197 198 return null; 199 } catch ( Exception ex ) { 200 throw _wrapper.dsiResultException( 201 CompletionStatus.COMPLETED_MAYBE, ex ) ; 202 } 203 } else if ( _exceptionSet ) 204 return _exception; 205 else { 206 throw _wrapper.dsimethodNotcalled( 207 CompletionStatus.COMPLETED_MAYBE ) ; 208 } 209 } 210 211 214 public void marshalReplyParams(OutputStream os) 215 { 216 _resultAny.write_value(os); 218 219 NamedValue arg = null; 221 222 for (int i=0; i < _arguments.count() ; i++) { 223 try { 224 arg = _arguments.item(i); 225 } catch (Bounds e) {} 226 227 if ((arg.flags() == org.omg.CORBA.ARG_OUT.value) || 228 (arg.flags() == org.omg.CORBA.ARG_INOUT.value)) { 229 arg.value().write_value(os); 230 } 231 } 232 } 233 234 public Context ctx() 235 { 236 if ( !_paramsCalled || _resultSet || _exceptionSet ) 237 throw _wrapper.contextCalledOutOfOrder() ; 238 239 throw _wrapper.contextNotImplemented() ; 240 } 241 } 242 | Popular Tags |