FileDocCategorySizeDatePackage
RequestImpl.javaAPI DocJava SE 5 API10016Fri Aug 26 14:54:20 BST 2005com.sun.corba.se.impl.corba

RequestImpl

public class RequestImpl extends Request

Fields Summary
protected Object
_target
protected String
_opName
protected NVList
_arguments
protected ExceptionList
_exceptions
private NamedValue
_result
protected Environment
_env
private Context
_ctx
private ContextList
_ctxList
protected ORB
_orb
private ORBUtilSystemException
_wrapper
protected boolean
_isOneWay
private int[]
_paramCodes
private long[]
_paramLongs
private Object[]
_paramObjects
protected boolean
gotResponse
Constructors Summary
public RequestImpl(ORB orb, Object targetObject, Context ctx, String operationName, NVList argumentList, NamedValue resultContainer, ExceptionList exceptionList, ContextList ctxList)


    ///////////////////////////////////////////////////////////////////////////
    // constructor

    // REVISIT - used to be protected.  Now public so it can be
    // accessed from xgiop.
       
			 
			 
			 
			 
			 
			 
			 
    

        // initialize the orb
        _orb 	= orb;
	_wrapper = ORBUtilSystemException.get( orb,
	    CORBALogDomains.OA_INVOCATION ) ;

        // initialize target, context and operation name
        _target     = targetObject;
        _ctx	= ctx;
        _opName	= operationName;

        // initialize argument list if not passed in
        if (argumentList == null)
            _arguments = new NVListImpl(_orb);
        else
            _arguments = argumentList;

        // set result container. 
        _result = resultContainer;

        // initialize exception list if not passed in
        if (exceptionList == null)
            _exceptions = new ExceptionListImpl();
        else
            _exceptions = exceptionList;

        // initialize context list if not passed in
        if (ctxList == null)
            _ctxList = new ContextListImpl(_orb);
        else
            _ctxList = ctxList;

        // initialize environment 
        _env	= new EnvironmentImpl();

    
Methods Summary
public synchronized voidadd_exception(org.omg.CORBA.TypeCode exceptionType)

        _exceptions.add(exceptionType);
    
public synchronized org.omg.CORBA.Anyadd_in_arg()

        return _arguments.add(org.omg.CORBA.ARG_IN.value).value();
    
public synchronized org.omg.CORBA.Anyadd_inout_arg()

        return _arguments.add(org.omg.CORBA.ARG_INOUT.value).value();
    
public synchronized org.omg.CORBA.Anyadd_named_in_arg(java.lang.String name)

        return _arguments.add_item(name, org.omg.CORBA.ARG_IN.value).value();
    
public synchronized org.omg.CORBA.Anyadd_named_inout_arg(java.lang.String name)

        return _arguments.add_item(name, org.omg.CORBA.ARG_INOUT.value).value();
    
public synchronized org.omg.CORBA.Anyadd_named_out_arg(java.lang.String name)

        return _arguments.add_item(name, org.omg.CORBA.ARG_OUT.value).value();
    
public synchronized org.omg.CORBA.Anyadd_out_arg()

        return _arguments.add(org.omg.CORBA.ARG_OUT.value).value();
    
public org.omg.CORBA.NVListarguments()

        return _arguments;
    
public org.omg.CORBA.ContextListcontexts()

        return _ctxList;
    
public synchronized voidctx(org.omg.CORBA.Context newCtx)

        _ctx = newCtx;
    
public synchronized org.omg.CORBA.Contextctx()

        if (_ctx == null)
            _ctx = new ContextImpl(_orb);
        return _ctx;
    
protected voiddoInvocation()

        org.omg.CORBA.portable.Delegate delegate = StubAdapter.getDelegate( 
	    _target ) ;

	// Initiate Client Portable Interceptors.  Inform the PIHandler that 
        // this is a DII request so that it knows to ignore the second 
        // inevitable call to initiateClientPIRequest in createRequest. 
        // Also, save the RequestImpl object for later use. 
	_orb.getPIHandler().initiateClientPIRequest( true );
	_orb.getPIHandler().setClientPIInfo( this );

	InputStream $in = null;
	try {
	    OutputStream $out = delegate.request(null, _opName, !_isOneWay);
	    // Marshal args
	    try {
		for (int i=0; i<_arguments.count() ; i++) {
		    NamedValue nv = _arguments.item(i);
		    switch (nv.flags()) {
		    case ARG_IN.value:
			nv.value().write_value($out);
			break;
		    case ARG_OUT.value:
			break;
		    case ARG_INOUT.value:
			nv.value().write_value($out);
			break;
	            }
		}
	    } catch ( org.omg.CORBA.Bounds ex ) {
		throw _wrapper.boundsErrorInDiiRequest( ex ) ;
	    }

	    $in = delegate.invoke(null, $out);
	} catch (ApplicationException e) {
	    // REVISIT - minor code.
	    // This is already handled in subcontract.
	    // REVISIT - uncomment.
	    //throw new INTERNAL();
	} catch (RemarshalException e) {
	    doInvocation();
	} catch( SystemException ex ) {
	    _env.exception(ex);
	    // NOTE: The exception should not be thrown.
	    // However, JDK 1.4 and earlier threw the exception,
	    // so we keep the behavior to be compatible.
	    throw ex;
	} finally {
	    delegate.releaseReply(null, $in);
        }
    
public org.omg.CORBA.Environmentenv()

        return _env;
    
public org.omg.CORBA.ExceptionListexceptions()

        return _exceptions;
    
public synchronized voidget_response()

        while (gotResponse == false) {
            // release the lock. wait to be notified by the thread that is
            // doing the asynchronous invocation.
            try {
	        wait();
            } 
	    catch (InterruptedException e) {}
        }
    
public synchronized voidinvoke()

        doInvocation();
    
public java.lang.Stringoperation()

        return _opName;
    
public synchronized booleanpoll_response()

        // this method has to be synchronized even though it seems
        // "readonly" since the thread object doing the asynchronous
        // invocation can potentially update this variable in parallel.
        // updates are currently simply synchronized againt the request
        // object. 
        return gotResponse;
    
public org.omg.CORBA.NamedValueresult()

        return _result;
    
public synchronized org.omg.CORBA.Anyreturn_value()

        if (_result == null)
            _result = new NamedValueImpl(_orb);
        return _result.value();
    
public synchronized voidsend_deferred()

        AsynchInvoke invokeObject = new AsynchInvoke(_orb, this, false);
        new Thread(invokeObject).start();
    
public synchronized voidsend_oneway()

        _isOneWay = true;
        doInvocation();
    
public synchronized voidset_return_type(org.omg.CORBA.TypeCode tc)

        if (_result == null)
            _result = new NamedValueImpl(_orb);
        _result.value().type(tc);
    
public org.omg.CORBA.Objecttarget()

        return _target;
    
public voidunmarshalReply(org.omg.CORBA.portable.InputStream is)

        // First unmarshal the return value if it is not void
        if ( _result != null ) {
            Any returnAny = _result.value();
            TypeCode returnType = returnAny.type();
            if ( returnType.kind().value() != TCKind._tk_void )
                returnAny.read_value(is, returnType);
        }
        
        // Now unmarshal the out/inout args
        try {
            for ( int i=0; i<_arguments.count() ; i++) {
                NamedValue nv = _arguments.item(i);
                switch( nv.flags() ) {
		case ARG_IN.value:
		    break;
		case ARG_OUT.value:
		case ARG_INOUT.value:
		    Any any = nv.value();	
		    any.read_value(is, any.type());
		    break;
                }
            }
        } 
	catch ( org.omg.CORBA.Bounds ex ) {
	    // Cannot happen since we only iterate till _arguments.count()
        }