1 /*
   2  * Copyright (c) 2000, 2003, 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 
  26 package com.sun.corba.se.impl.protocol.giopmsgheaders;
  27 
  28 import org.omg.CORBA.Principal;
  29 import com.sun.corba.se.spi.servicecontext.ServiceContexts;
  30 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
  31 import com.sun.corba.se.spi.orb.ORB;
  32 import com.sun.corba.se.spi.ior.ObjectKey;
  33 
  34 import com.sun.corba.se.spi.logging.CORBALogDomains ;
  35 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  36 
  37 /**
  38  * This implements the GIOP 1.1 Request header.
  39  *
  40  * @author Ram Jeyaraman 05/14/2000
  41  */
  42 
  43 public final class RequestMessage_1_1 extends Message_1_1
  44         implements RequestMessage {
  45 
  46     // Instance variables
  47 
  48     private ORB orb = null;
  49     private ORBUtilSystemException wrapper = null ;
  50     private ServiceContexts service_contexts = null;
  51     private int request_id = (int) 0;
  52     private boolean response_expected = false;
  53     private byte[] reserved = null; // Added in GIOP 1.1
  54     private byte[] object_key = null;
  55     private String operation = null;
  56     private Principal requesting_principal = null;
  57     private ObjectKey objectKey = null;
  58 
  59     // Constructors
  60 
  61     RequestMessage_1_1(ORB orb) {
  62         this.orb = orb;
  63         this.wrapper = ORBUtilSystemException.get( orb,
  64             CORBALogDomains.RPC_PROTOCOL ) ;
  65     }
  66 
  67     RequestMessage_1_1(ORB orb, ServiceContexts _service_contexts,
  68             int _request_id, boolean _response_expected, byte[] _reserved,
  69             byte[] _object_key, String _operation,
  70             Principal _requesting_principal) {
  71         super(Message.GIOPBigMagic, GIOPVersion.V1_1, FLAG_NO_FRAG_BIG_ENDIAN,
  72             Message.GIOPRequest, 0);
  73         this.orb = orb;
  74         this.wrapper = ORBUtilSystemException.get( orb,
  75             CORBALogDomains.RPC_PROTOCOL ) ;
  76         service_contexts = _service_contexts;
  77         request_id = _request_id;
  78         response_expected = _response_expected;
  79         reserved = _reserved;
  80         object_key = _object_key;
  81         operation = _operation;
  82         requesting_principal = _requesting_principal;
  83     }
  84 
  85     // Accessor methods (RequestMessage interface)
  86 
  87     public ServiceContexts getServiceContexts() {
  88         return this.service_contexts;
  89     }
  90 
  91     public int getRequestId() {
  92         return this.request_id;
  93     }
  94 
  95     public boolean isResponseExpected() {
  96         return this.response_expected;
  97     }
  98 
  99     public byte[] getReserved() {
 100         return this.reserved;
 101     }
 102 
 103     public ObjectKey getObjectKey() {
 104         if (this.objectKey == null) {
 105             // this will raise a MARSHAL exception upon errors.
 106             this.objectKey = MessageBase.extractObjectKey(object_key, orb);
 107         }
 108 
 109         return this.objectKey;
 110     }
 111 
 112     public String getOperation() {
 113         return this.operation;
 114     }
 115 
 116     public Principal getPrincipal() {
 117         return this.requesting_principal;
 118     }
 119 
 120     // IO methods
 121 
 122     public void read(org.omg.CORBA.portable.InputStream istream) {
 123         super.read(istream);
 124         this.service_contexts
 125             = new ServiceContexts((org.omg.CORBA_2_3.portable.InputStream) istream);
 126         this.request_id = istream.read_ulong();
 127         this.response_expected = istream.read_boolean();
 128         this.reserved = new byte[3];
 129         for (int _o0 = 0;_o0 < (3); ++_o0) {
 130             this.reserved[_o0] = istream.read_octet();
 131         }
 132         int _len1 = istream.read_long();
 133         this.object_key = new byte[_len1];
 134         istream.read_octet_array(this.object_key, 0, _len1);
 135         this.operation = istream.read_string();
 136         this.requesting_principal = istream.read_Principal();
 137     }
 138 
 139     public void write(org.omg.CORBA.portable.OutputStream ostream) {
 140         super.write(ostream);
 141         if (this.service_contexts != null) {
 142                 service_contexts.write(
 143                 (org.omg.CORBA_2_3.portable.OutputStream) ostream,
 144                 GIOPVersion.V1_1);
 145             } else {
 146                 ServiceContexts.writeNullServiceContext(
 147                 (org.omg.CORBA_2_3.portable.OutputStream) ostream);
 148         }
 149         ostream.write_ulong(this.request_id);
 150         ostream.write_boolean(this.response_expected);
 151         nullCheck(this.reserved);
 152         if (this.reserved.length != (3)) {
 153             throw wrapper.badReservedLength(
 154                 org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
 155         }
 156         for (int _i0 = 0;_i0 < (3); ++_i0) {
 157             ostream.write_octet(this.reserved[_i0]);
 158         }
 159         nullCheck(this.object_key);
 160         ostream.write_long(this.object_key.length);
 161         ostream.write_octet_array(this.object_key, 0, this.object_key.length);
 162         ostream.write_string(this.operation);
 163         if (this.requesting_principal != null) {
 164             ostream.write_Principal(this.requesting_principal);
 165         } else {
 166             ostream.write_long(0);
 167         }
 168     }
 169 
 170     public void callback(MessageHandler handler)
 171         throws java.io.IOException
 172     {
 173         handler.handleInput(this);
 174     }
 175 } // class RequestMessage_1_1