/** * Copies or connects an object. Used by local stubs to copy an actual parameter, result object, * or exception. * * @param obj the object to copy. * @param orb the ORB. * @return the copy or connected object. * @exception RemoteException if the object could not be copied or connected. */ public Object copyObject(Object obj, org.omg.CORBA.ORB orb) throws RemoteException { if (orb instanceof ORB) { ORB lorb = (ORB) orb; try { try { // This gets the copier for the current invocation, which was // previously set by preinvoke. return lorb.peekInvocationInfo().getCopierFactory().make().copy(obj); } catch (java.util.EmptyStackException exc) { // copyObject was invoked outside of an invocation, probably by // a test. Get the default copier from the ORB. // XXX should we just make the default copier available directly // and avoid constructing one on each call? CopierManager cm = lorb.getCopierManager(); ObjectCopier copier = cm.getDefaultObjectCopierFactory().make(); return copier.copy(obj); } } catch (ReflectiveCopyException exc) { RemoteException rexc = new RemoteException(); rexc.initCause(exc); throw rexc; } } else { org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) orb.create_output_stream(); out.write_value((Serializable) obj); org.omg.CORBA_2_3.portable.InputStream in = (org.omg.CORBA_2_3.portable.InputStream) out.create_input_stream(); return in.read_value(); } }