1/*
2 * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.corba.se.impl.protocol.giopmsgheaders;
27
28import org.omg.CORBA.Principal;
29import com.sun.corba.se.spi.servicecontext.ServiceContexts;
30import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
31import com.sun.corba.se.spi.orb.ORB;
32import com.sun.corba.se.spi.ior.ObjectKey;
33import com.sun.corba.se.impl.encoding.CDRInputStream;
34import com.sun.corba.se.impl.encoding.CDROutputStream;
35import com.sun.corba.se.impl.orbutil.ORBConstants;
36import com.sun.corba.se.impl.encoding.CDRInputStream_1_2;
37import com.sun.corba.se.impl.encoding.CDROutputStream_1_2;
38
39import com.sun.corba.se.spi.logging.CORBALogDomains ;
40import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
41
42/**
43 * This implements the GIOP 1.2 Request header.
44 *
45 * @author Ram Jeyaraman 05/14/2000
46 */
47
48public final class RequestMessage_1_2 extends Message_1_2
49        implements RequestMessage {
50
51    // Instance variables
52
53    private ORB orb = null;
54    private ORBUtilSystemException wrapper = null ;
55    private byte response_flags = (byte) 0;
56    private byte reserved[] = null;
57    private TargetAddress target = null;
58    private String operation = null;
59    private ServiceContexts service_contexts = null;
60    private ObjectKey objectKey = null;
61
62    // Constructors
63
64    RequestMessage_1_2(ORB orb) {
65        this.orb = orb;
66        this.wrapper = ORBUtilSystemException.get( orb,
67            CORBALogDomains.RPC_PROTOCOL ) ;
68    }
69
70    RequestMessage_1_2(ORB orb, int _request_id, byte _response_flags,
71            byte[] _reserved, TargetAddress _target,
72            String _operation, ServiceContexts _service_contexts) {
73        super(Message.GIOPBigMagic, GIOPVersion.V1_2, FLAG_NO_FRAG_BIG_ENDIAN,
74            Message.GIOPRequest, 0);
75        this.orb = orb;
76        this.wrapper = ORBUtilSystemException.get( orb,
77            CORBALogDomains.RPC_PROTOCOL ) ;
78        request_id = _request_id;
79        response_flags = _response_flags;
80        reserved = _reserved;
81        target = _target;
82        operation = _operation;
83        service_contexts = _service_contexts;
84    }
85
86    // Accessor methods (RequestMessage interface)
87
88    public int getRequestId() {
89        return this.request_id;
90    }
91
92    public boolean isResponseExpected() {
93        /*
94        case 1: LSBit[1] == 1
95            not a oneway call (DII flag INV_NO_RESPONSE is false)  // Ox03
96            LSBit[0] must be 1.
97        case 2: LSBit[1] == 0
98            if (LSB[0] == 0) // Ox00
99                oneway call
100            else if (LSB[0] == 1) // 0x01
101                oneway call; but server may provide
102                a location forward response or system exception response.
103        */
104
105        if ( (this.response_flags & RESPONSE_EXPECTED_BIT) == RESPONSE_EXPECTED_BIT ) {
106            return true;
107        }
108
109        return false;
110    }
111
112    public byte[] getReserved() {
113        return this.reserved;
114    }
115
116    public ObjectKey getObjectKey() {
117        if (this.objectKey == null) {
118            // this will raise a MARSHAL exception upon errors.
119            this.objectKey = MessageBase.extractObjectKey(target, orb);
120        }
121
122        return this.objectKey;
123    }
124
125    public String getOperation() {
126        return this.operation;
127    }
128
129    public Principal getPrincipal() {
130        // REVISIT Should we throw an exception or return null ?
131        return null;
132    }
133
134    public ServiceContexts getServiceContexts() {
135        return this.service_contexts;
136    }
137
138    // IO methods
139
140    public void read(org.omg.CORBA.portable.InputStream istream) {
141        super.read(istream);
142        this.request_id = istream.read_ulong();
143        this.response_flags = istream.read_octet();
144        this.reserved = new byte[3];
145        for (int _o0 = 0;_o0 < (3); ++_o0) {
146            this.reserved[_o0] = istream.read_octet();
147        }
148        this.target = TargetAddressHelper.read(istream);
149        getObjectKey(); // this does AddressingDisposition check
150        this.operation = istream.read_string();
151        this.service_contexts
152            = new ServiceContexts((org.omg.CORBA_2_3.portable.InputStream) istream);
153
154        // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
155        // aligned on an 8 octet boundary.
156        // Ensures that the first read operation called from the stub code,
157        // during body deconstruction, would skip the header padding, that was
158        // inserted to ensure that the body was aligned on an 8-octet boundary.
159        ((CDRInputStream)istream).setHeaderPadding(true);
160
161    }
162
163    public void write(org.omg.CORBA.portable.OutputStream ostream) {
164        super.write(ostream);
165        ostream.write_ulong(this.request_id);
166        ostream.write_octet(this.response_flags);
167        nullCheck(this.reserved);
168        if (this.reserved.length != (3)) {
169            throw wrapper.badReservedLength(
170                org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
171        }
172        for (int _i0 = 0;_i0 < (3); ++_i0) {
173            ostream.write_octet(this.reserved[_i0]);
174        }
175        nullCheck(this.target);
176        TargetAddressHelper.write(ostream, this.target);
177        ostream.write_string(this.operation);
178        if (this.service_contexts != null) {
179                service_contexts.write(
180                (org.omg.CORBA_2_3.portable.OutputStream) ostream,
181                GIOPVersion.V1_2);
182            } else {
183                ServiceContexts.writeNullServiceContext(
184                (org.omg.CORBA_2_3.portable.OutputStream) ostream);
185        }
186
187        // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
188        // aligned on an 8 octet boundary.
189        // Ensures that the first write operation called from the stub code,
190        // during body construction, would insert a header padding, such that
191        // the body is aligned on an 8-octet boundary.
192        ((CDROutputStream)ostream).setHeaderPadding(true);
193    }
194
195    public void callback(MessageHandler handler)
196        throws java.io.IOException
197    {
198        handler.handleInput(this);
199    }
200} // class RequestMessage_1_2
201