1 22 package org.jboss.proxy.ejb; 23 24 import javax.rmi.CORBA.Util ; 25 import org.omg.CORBA_2_3.portable.InputStream ; 26 import org.omg.CORBA_2_3.portable.OutputStream ; 27 import org.omg.CORBA.portable.ApplicationException ; 28 import org.omg.CORBA.portable.RemarshalException ; 29 import org.omg.CORBA.SystemException ; 30 31 import org.jboss.iiop.rmi.marshal.strategy.StubStrategy; 32 import org.jboss.logging.Logger; 33 import org.jboss.proxy.ejb.HandleImplIIOP; 34 import org.jboss.proxy.ejb.HomeHandleImplIIOP; 35 36 52 public abstract class DynamicIIOPStub 53 extends javax.rmi.CORBA.Stub 54 { 55 56 58 61 private Object handle = null; 62 63 65 private static final Logger logger = 66 Logger.getLogger(DynamicIIOPStub.class); 67 68 private static void trace(String msg) 69 { 70 if (logger.isTraceEnabled()) 71 logger.trace(msg); 72 } 73 74 76 79 public DynamicIIOPStub() 80 { 81 super(); 82 } 83 84 86 90 public Object invoke(String operationName, 91 StubStrategy stubStrategy, Object [] params) 92 throws Throwable 93 { 94 if (operationName.equals("_get_handle") 95 && this instanceof javax.ejb.EJBObject ) { 96 if (handle == null) { 97 handle = new HandleImplIIOP(this); 98 } 99 return handle; 100 } 101 else if (operationName.equals("_get_homeHandle") 102 && this instanceof javax.ejb.EJBHome ) { 103 if (handle == null) { 104 handle = new HomeHandleImplIIOP(this); 105 } 106 return handle; 107 } 108 else if (!_is_local()) { 109 111 116 InputStream in = null; 117 try { 118 try { 119 OutputStream out = 120 (OutputStream )_request(operationName, true); 121 stubStrategy.writeParams(out, params); 122 trace("sent request: " + operationName); 123 in = (InputStream )_invoke(out); 124 if (stubStrategy.isNonVoid()) { 125 trace("received reply"); 126 return stubStrategy.readRetval(in); 127 } 131 else 132 return null; 133 } 134 catch (ApplicationException ex) { 135 trace("got application exception"); 136 in =(InputStream )ex.getInputStream(); 137 throw stubStrategy.readException(ex.getId(), in); 138 } 139 catch (RemarshalException ex) { 140 trace("got remarshal exception"); 141 return invoke(operationName, stubStrategy, params); 142 } 143 } 144 catch (SystemException ex) { 145 if (logger.isTraceEnabled()) { 146 logger.trace("CORBA system exception in IIOP stub", ex); 147 } 148 throw Util.mapSystemException(ex); 149 } 150 finally { 151 _releaseReply(in); 152 } 153 } 154 else { 155 org.omg.CORBA.portable.ServantObject so = 157 _servant_preinvoke(operationName, java.lang.Object .class); 158 if (so == null) 159 return invoke(operationName, stubStrategy, params); 160 try { 161 Object retval = 163 ((LocalIIOPInvoker)so.servant).invoke(operationName, 164 params, 165 null, 166 null, 167 null ); 168 return stubStrategy.convertLocalRetval(retval); 169 } 172 catch(Throwable e) { 173 Throwable ex = e; 175 if (stubStrategy.isDeclaredException(ex)) 176 throw ex; 177 else 178 throw Util.wrapException(ex); 179 } 180 finally { 181 _servant_postinvoke(so); 182 } 183 } 184 } 185 186 190 public boolean invokeBoolean(String operationName, 191 StubStrategy stubStrategy, Object [] params) 192 throws Throwable 193 { 194 return ((Boolean )invoke(operationName, 195 stubStrategy, params)).booleanValue(); 196 } 197 198 202 public byte invokeByte(String operationName, 203 StubStrategy stubStrategy, Object [] params) 204 throws Throwable 205 { 206 return ((Number )invoke(operationName, 207 stubStrategy, params)).byteValue(); 208 } 209 210 214 public char invokeChar(String operationName, 215 StubStrategy stubStrategy, Object [] params) 216 throws Throwable 217 { 218 return ((Character )invoke(operationName, 219 stubStrategy, params)).charValue(); 220 } 221 222 226 public short invokeShort(String operationName, 227 StubStrategy stubStrategy, Object [] params) 228 throws Throwable 229 { 230 return ((Number )invoke(operationName, 231 stubStrategy, params)).shortValue(); 232 } 233 234 238 public int invokeInt(String operationName, 239 StubStrategy stubStrategy, Object [] params) 240 throws Throwable 241 { 242 return ((Number )invoke(operationName, stubStrategy, params)).intValue(); 243 } 244 245 249 public long invokeLong(String operationName, 250 StubStrategy stubStrategy, Object [] params) 251 throws Throwable 252 { 253 return ((Number )invoke(operationName, stubStrategy, params)).longValue(); 254 } 255 256 260 public float invokeFloat(String operationName, 261 StubStrategy stubStrategy, Object [] params) 262 throws Throwable 263 { 264 return ((Number )invoke(operationName, 265 stubStrategy, params)).floatValue(); 266 } 267 268 272 public double invokeDouble(String operationName, 273 StubStrategy stubStrategy, Object [] params) 274 throws Throwable 275 { 276 return ((Number )invoke(operationName, 277 stubStrategy, params)).doubleValue(); 278 } 279 280 } 281 | Popular Tags |