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 
  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 /**
  35  * This implements the GIOP 1.0 Request header.
  36  *
  37  * @author Ram Jeyaraman 05/14/2000
  38  */
  39 
  40 public final class RequestMessage_1_0 extends Message_1_0
  41         implements RequestMessage {
  42 
  43     // Instance variables
  44 
  45     private ORB orb = null;
  46     private ServiceContexts service_contexts = null;
  47     private int request_id = (int) 0;
  48     private boolean response_expected = false;
  49     private byte[] object_key = null;
  50     private String operation = null;
  51     private Principal requesting_principal = null;
  52     private ObjectKey objectKey = null;
  53 
  54     // Constructor
  55 
  56     RequestMessage_1_0(ORB orb) {
  57         this.orb = orb;
  58     }
  59 
  60     RequestMessage_1_0(ORB orb, ServiceContexts _service_contexts,
  61             int _request_id, boolean _response_expected, byte[] _object_key,
  62             String _operation, Principal _requesting_principal) {
  63         super(Message.GIOPBigMagic, false, Message.GIOPRequest, 0);
  64         this.orb = orb;
  65         service_contexts = _service_contexts;
  66         request_id = _request_id;
  67         response_expected = _response_expected;
  68         object_key = _object_key;
  69         operation = _operation;
  70         requesting_principal = _requesting_principal;
  71     }
  72 
  73     // Accessor methods (RequestMessage interface)
  74 
  75     public ServiceContexts getServiceContexts() {
  76         return this.service_contexts;
  77     }
  78 
  79     public int getRequestId() {
  80         return this.request_id;
  81     }
  82 
  83     public boolean isResponseExpected() {
  84         return this.response_expected;
  85     }
  86 
  87     public byte[] getReserved() {
  88         // REVISIT Should we throw an exception or return null ?
  89         return null;
  90     }
  91 
  92     public ObjectKey getObjectKey() {
  93         if (this.objectKey == null) {
  94             // this will raise a MARSHAL exception upon errors.
  95             this.objectKey = MessageBase.extractObjectKey(object_key, orb);
  96         }
  97 
  98         return this.objectKey;
  99     }
 100 
 101     public String getOperation() {
 102         return this.operation;
 103     }
 104 
 105     public Principal getPrincipal() {
 106         return this.requesting_principal;
 107     }
 108 
 109 
 110     // Mutators
 111 
 112     public void setThreadPoolToUse(int poolToUse) {
 113         // No-op, must be GIOP Version 1.1 or greater
 114         // to support this SUN PROPRIETARY EXTENSION.
 115     }
 116 
 117 
 118     // IO methods
 119 
 120     public void read(org.omg.CORBA.portable.InputStream istream) {
 121         super.read(istream);
 122         this.service_contexts
 123             = new ServiceContexts((org.omg.CORBA_2_3.portable.InputStream) istream);
 124         this.request_id = istream.read_ulong();
 125         this.response_expected = istream.read_boolean();
 126         int _len0 = istream.read_long();
 127         this.object_key = new byte[_len0];
 128         istream.read_octet_array(this.object_key, 0, _len0);
 129         this.operation = istream.read_string();
 130         this.requesting_principal = istream.read_Principal();
 131     }
 132 
 133     public void write(org.omg.CORBA.portable.OutputStream ostream) {
 134         super.write(ostream);
 135         if (this.service_contexts != null) {
 136                 service_contexts.write(
 137                 (org.omg.CORBA_2_3.portable.OutputStream) ostream,
 138                 GIOPVersion.V1_0);
 139             } else {
 140                 ServiceContexts.writeNullServiceContext(
 141                 (org.omg.CORBA_2_3.portable.OutputStream) ostream);
 142         }
 143         ostream.write_ulong(this.request_id);
 144         ostream.write_boolean(this.response_expected);
 145         nullCheck(this.object_key);
 146         ostream.write_long(this.object_key.length);
 147         ostream.write_octet_array(this.object_key, 0, this.object_key.length);
 148         ostream.write_string(this.operation);
 149         if (this.requesting_principal != null) {
 150             ostream.write_Principal(this.requesting_principal);
 151         } else {
 152             ostream.write_long(0);
 153         }
 154     }
 155 
 156     public void callback(MessageHandler handler)
 157         throws java.io.IOException
 158     {
 159         handler.handleInput(this);
 160     }
 161 } // class RequestMessage_1_0