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 
39 import com.sun.corba.se.impl.encoding.CDRInputStream;
40 
41 import com.sun.corba.se.spi.logging.CORBALogDomains ;
42 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
43 
44 /**
45  * This implements the GIOP 1.0 LocateReply header.
46  *
47  * @author Ram Jeyaraman 05/14/2000
48  */
49 
50 public final class LocateReplyMessage_1_0 extends Message_1_0
51         implements LocateReplyMessage {
52 
53     // Instance variables
54 
55     private ORB orb = null;
56     private int request_id = (int) 0;
57     private int locate_status = (int) 0;
58     private IOR ior = null;
59 
60     // Constructors
61 
LocateReplyMessage_1_0(ORB orb)62     LocateReplyMessage_1_0(ORB orb) {
63         this.orb = orb;
64     }
65 
LocateReplyMessage_1_0(ORB orb, int _request_id, int _locate_status, IOR _ior)66     LocateReplyMessage_1_0(ORB orb, int _request_id,
67             int _locate_status, IOR _ior) {
68         super(Message.GIOPBigMagic, false, Message.GIOPLocateReply, 0);
69         this.orb = orb;
70         request_id = _request_id;
71         locate_status = _locate_status;
72         ior = _ior;
73     }
74 
75     // Accessor methods
76 
getRequestId()77     public int getRequestId() {
78         return this.request_id;
79     }
80 
getReplyStatus()81     public int getReplyStatus() {
82         return this.locate_status;
83     }
84 
getAddrDisposition()85     public short getAddrDisposition() {
86         return KeyAddr.value;
87     }
88 
getSystemException(String message)89     public SystemException getSystemException(String message) {
90         return null;  // 1.0 LocateReply body does not contain SystemException
91     }
92 
getIOR()93     public IOR getIOR() {
94         return this.ior;
95     }
96 
97     // IO methods
98 
read(org.omg.CORBA.portable.InputStream istream)99     public void read(org.omg.CORBA.portable.InputStream istream) {
100         super.read(istream);
101         this.request_id = istream.read_ulong();
102         this.locate_status = istream.read_long();
103         isValidReplyStatus(this.locate_status); // raises exception on error
104 
105         // The code below reads the reply body if status is OBJECT_FORWARD
106         if (this.locate_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.
113     // IOR may be written afterwards into the reply mesg body.
write(org.omg.CORBA.portable.OutputStream ostream)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.locate_status);
118     }
119 
120     // Static methods
121 
isValidReplyStatus(int replyStatus)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 
callback(MessageHandler handler)135     public void callback(MessageHandler handler)
136         throws java.io.IOException
137     {
138         handler.handleInput(this);
139     }
140 } // class LocateReplyMessage_1_0
141