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.INTERNAL;
  29 import org.omg.CORBA.CompletionStatus;
  30 import org.omg.CORBA.SystemException;
  31 
  32 import com.sun.corba.se.spi.ior.IOR;
  33 import com.sun.corba.se.spi.ior.IORFactories;
  34 
  35 import com.sun.corba.se.spi.orb.ORB;
  36 
  37 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
  38 import com.sun.corba.se.impl.encoding.CDRInputStream;
  39 
  40 import com.sun.corba.se.spi.logging.CORBALogDomains ;
  41 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  42 
  43 /**
  44  * This implements the GIOP 1.1 LocateReply header.
  45  *
  46  * @author Ram Jeyaraman 05/14/2000
  47  */
  48 
  49 public final class LocateReplyMessage_1_1 extends Message_1_1
  50         implements LocateReplyMessage {
  51 
  52     // Instance variables
  53 
  54     private ORB orb = null;
  55     private int request_id = (int) 0;
  56     private int reply_status = (int) 0;
  57     private IOR ior = null;
  58 
  59     // Constructors
  60 
  61     LocateReplyMessage_1_1(ORB orb) {
  62         this.orb = orb;
  63     }
  64 
  65     LocateReplyMessage_1_1(ORB orb, int _request_id,
  66             int _reply_status, IOR _ior) {
  67         super(Message.GIOPBigMagic, GIOPVersion.V1_1, FLAG_NO_FRAG_BIG_ENDIAN,
  68             Message.GIOPLocateReply, 0);
  69         this.orb = orb;
  70         request_id = _request_id;
  71         reply_status = _reply_status;
  72         ior = _ior;
  73     }
  74 
  75     // Accessor methods
  76 
  77     public int getRequestId() {
  78         return this.request_id;
  79     }
  80 
  81     public int getReplyStatus() {
  82         return this.reply_status;
  83     }
  84 
  85     public short getAddrDisposition() {
  86         return KeyAddr.value;
  87     }
  88 
  89     public SystemException getSystemException(String message) {
  90         return null; // 1.0 LocateReply body does not contain SystemException
  91     }
  92 
  93     public IOR getIOR() {
  94         return this.ior;
  95     }
  96 
  97     // IO methods
  98 
  99     public void read(org.omg.CORBA.portable.InputStream istream) {
 100         super.read(istream);
 101         this.request_id = istream.read_ulong();
 102         this.reply_status = istream.read_long();
 103         isValidReplyStatus(this.reply_status); // raises exception on error
 104 
 105         // The code below reads the reply body if status is OBJECT_FORWARD
 106         if (this.reply_status == OBJECT_FORWARD) {
 107             CDRInputStream cdr = (CDRInputStream) istream;
 108             this.ior = IORFactories.makeIOR( cdr ) ;
 109         }
 110     }
 111 
 112     // Note, this writes only the header information. SystemException or
 113     // IOR may be written afterwards into the reply mesg body.
 114     public void write(org.omg.CORBA.portable.OutputStream ostream) {
 115         super.write(ostream);
 116         ostream.write_ulong(this.request_id);
 117         ostream.write_long(this.reply_status);
 118     }
 119 
 120     // Static methods
 121 
 122     public static void isValidReplyStatus(int replyStatus) {
 123         switch (replyStatus) {
 124         case UNKNOWN_OBJECT :
 125         case OBJECT_HERE :
 126         case OBJECT_FORWARD :
 127             break;
 128         default :
 129             ORBUtilSystemException localWrapper = ORBUtilSystemException.get(
 130                 CORBALogDomains.RPC_PROTOCOL ) ;
 131             throw localWrapper.illegalReplyStatus( CompletionStatus.COMPLETED_MAYBE);
 132         }
 133     }
 134 
 135     public void callback(MessageHandler handler)
 136         throws java.io.IOException
 137     {
 138         handler.handleInput(this);
 139     }
 140 } // class LocateReplyMessage_1_1