corba/src/share/classes/com/sun/corba/se/impl/protocol/oldlocal/LocalServerResponseImpl.sjava
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.iiop;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import org.omg.CORBA.SystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import com.sun.corba.se.impl.core.ServerResponse;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import com.sun.corba.se.impl.core.ORB;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import com.sun.corba.se.impl.corba.IOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import com.sun.corba.se.impl.core.ServiceContext;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import com.sun.corba.se.impl.core.ServiceContexts;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import com.sun.corba.se.impl.core.ClientResponse;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
class LocalServerResponseImpl
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
    extends     IIOPOutputStream
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
    implements  ServerResponse
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
    LocalServerResponseImpl(LocalServerRequestImpl request, ServiceContexts svc)
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
        this(request,
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
            MessageBase.createReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
                            (ORB)request.orb(),
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
                            request.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
                            request.getRequestId(), ReplyMessage.NO_EXCEPTION,
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
                            svc, null),
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
            null);
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
    LocalServerResponseImpl(LocalServerRequestImpl request, ServiceContexts svc,
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
            boolean user)
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
        this(request,
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
            MessageBase.createReply(
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
                            (ORB)request.orb(),
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
                            request.getGIOPVersion(), request.getRequestId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
                            user ? ReplyMessage.USER_EXCEPTION :
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
                                   ReplyMessage.SYSTEM_EXCEPTION,
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
                            svc, null),
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
            null);
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
    LocalServerResponseImpl( LocalServerRequestImpl request, ReplyMessage reply,
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
			     IOR ior)
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
        super(request.getGIOPVersion(),
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
              (ORB)request.orb(), 
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
              null, 
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
              BufferManagerFactory.newBufferManagerWrite(BufferManagerFactory.GROW),
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
              request.getStreamFormatVersionForReply());
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        setMessage(reply);
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
	ORB orb = (ORB)request.orb();
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
	ServerResponseImpl.runServantPostInvoke(orb, request);
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
	if( request.executePIInResponseConstructor() ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
	    // Invoke server request ending interception points (send_*):
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
	    // Note: this may end up with a SystemException or an internal
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
	    // Runtime ForwardRequest.
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
	    orb.getPIHandler().invokeServerPIEndingPoint( reply );
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
	    // Note this will be executed even if a ForwardRequest or
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
	    // SystemException is thrown by a Portable Interceptors ending 
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
	    // point since we end up in this constructor again anyway.
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
	    orb.getPIHandler().cleanupServerPIRequest();
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
	    // See (Local)ServerRequestImpl.createSystemExceptionResponse
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
	    // for why this is necesary.
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
	    request.setExecutePIInResponseConstructor(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
	}
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
	// Once you get here then the final reply is available (i.e.,
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
	// postinvoke and interceptors have completed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
	if (request.executeRemoveThreadInfoInResponseConstructor()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
	    ServerResponseImpl.removeThreadInfo(orb, request);
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
	}
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
        
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
	reply.write(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
	if (reply.getIOR() != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
	    reply.getIOR().write(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
        this.reply = reply;
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
        this.ior = reply.getIOR();
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    public boolean isSystemException() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        if (reply != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
            return reply.getReplyStatus() == ReplyMessage.SYSTEM_EXCEPTION;
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
    public boolean isUserException() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        if (reply != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
            return reply.getReplyStatus() == ReplyMessage.USER_EXCEPTION;
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
    public boolean isLocationForward() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        if (ior != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    public IOR getForwardedIOR() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    	return ior;
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    public int getRequestId() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
        if (reply != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
            return reply.getRequestId();
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
        return -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    public ServiceContexts getServiceContexts() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
        if (reply != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
            return reply.getServiceContexts();
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    public SystemException getSystemException() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        if (reply != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
            return reply.getSystemException();
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    public ReplyMessage getReply()
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
    	return reply ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
    public ClientResponse getClientResponse()
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
        // set the size of the marshalled data in the message header
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        getMessage().setSize(getByteBuffer(), getSize());
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
        // Construct a new ClientResponse out of the buffer in this ClientRequest
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
        LocalClientResponseImpl result =
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
            new LocalClientResponseImpl( (ORB)orb(), toByteArray(), reply);
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
        // NOTE (Ram J) (06/02/2000) if we set result.setIndex(bodyBegin) here
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        // then the LocalClientResponse does not need to read the headers anymore.
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
        // This will be an optimisation which is can be done to speed up the
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
        // local invocation by avoiding reading the headers in the local cases.
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
        // BUGFIX(Ram Jeyaraman) result.setOffset is now done in
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
        // LocalClientResponseImpl constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
        /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
          // Skip over all of the GIOP header information.  This positions
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
          // the offset in the buffer so that the skeleton can correctly read
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
          // the marshalled arguments.
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
          result.setOffset( bodyBegin ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
        */
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
        return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
     * Check to see if the response is local.
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
    public boolean isLocal(){
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    private ReplyMessage reply;
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    private IOR ior; // forwarded IOR
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
}