LocateReplyMessage_1_2.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 2000, 2013, 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.INTERNAL;
29import org.omg.CORBA.SystemException;
30import org.omg.CORBA.CompletionStatus;
31
32import com.sun.corba.se.spi.orb.ORB;
33
34import com.sun.corba.se.spi.ior.IOR;
35import com.sun.corba.se.spi.ior.IORFactories;
36
37import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
38
39import com.sun.corba.se.impl.encoding.CDRInputStream;
40import com.sun.corba.se.impl.encoding.CDROutputStream;
41
42import com.sun.corba.se.impl.orbutil.ORBUtility;
43import com.sun.corba.se.impl.orbutil.ORBConstants;
44
45import com.sun.corba.se.spi.logging.CORBALogDomains ;
46import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
47
48/**
49 * This implements the GIOP 1.2 LocateReply header.
50 *
51 * @author Ram Jeyaraman 05/14/2000
52 */
53
54public final class LocateReplyMessage_1_2 extends Message_1_2
55        implements LocateReplyMessage {
56
57    // Instance variables
58
59    private ORB orb = null;
60    private ORBUtilSystemException wrapper = null ;
61    private int reply_status = (int) 0;
62    private IOR ior = null;
63    private String exClassName = null;
64    private int minorCode = (int) 0;
65    private CompletionStatus completionStatus = null;
66    private short addrDisposition = KeyAddr.value; // default;
67
68    // Constructors
69
70    LocateReplyMessage_1_2(ORB orb) {
71        this.orb = orb;
72        this.wrapper = ORBUtilSystemException.get( orb,
73            CORBALogDomains.RPC_PROTOCOL ) ;
74    }
75
76    LocateReplyMessage_1_2(ORB orb, int _request_id,
77            int _reply_status, IOR _ior) {
78        super(Message.GIOPBigMagic, GIOPVersion.V1_2, FLAG_NO_FRAG_BIG_ENDIAN,
79            Message.GIOPLocateReply, 0);
80        this.orb = orb;
81        this.wrapper = ORBUtilSystemException.get( orb,
82            CORBALogDomains.RPC_PROTOCOL ) ;
83        request_id = _request_id;
84        reply_status = _reply_status;
85        ior = _ior;
86    }
87
88    // Accessor methods
89
90    public int getRequestId() {
91        return this.request_id;
92    }
93
94    public int getReplyStatus() {
95        return this.reply_status;
96    }
97
98    public short getAddrDisposition() {
99        return this.addrDisposition;
100    }
101
102    public SystemException getSystemException(String message) {
103        return MessageBase.getSystemException(
104            exClassName, minorCode, completionStatus, message, wrapper);
105    }
106
107    public IOR getIOR() {
108        return this.ior;
109    }
110
111    // IO methods
112
113    public void read(org.omg.CORBA.portable.InputStream istream) {
114        super.read(istream);
115        this.request_id = istream.read_ulong();
116        this.reply_status = istream.read_long();
117        isValidReplyStatus(this.reply_status); // raises exception on error
118
119        // GIOP 1.2 LocateReply message bodies are not aligned on
120        // 8 byte boundaries.
121
122        // The code below reads the reply body in some cases
123        // LOC_SYSTEM_EXCEPTION & OBJECT_FORWARD & OBJECT_FORWARD_PERM &
124        // LOC_NEEDS_ADDRESSING_MODE
125        if (this.reply_status == LOC_SYSTEM_EXCEPTION) {
126
127            String reposId = istream.read_string();
128            this.exClassName = ORBUtility.classNameOf(reposId);
129            this.minorCode = istream.read_long();
130            int status = istream.read_long();
131
132            switch (status) {
133            case CompletionStatus._COMPLETED_YES:
134                this.completionStatus = CompletionStatus.COMPLETED_YES;
135                break;
136            case CompletionStatus._COMPLETED_NO:
137                this.completionStatus = CompletionStatus.COMPLETED_NO;
138                break;
139            case CompletionStatus._COMPLETED_MAYBE:
140                this.completionStatus = CompletionStatus.COMPLETED_MAYBE;
141                break;
142            default:
143                throw wrapper.badCompletionStatusInLocateReply(
144                    CompletionStatus.COMPLETED_MAYBE, new Integer(status) );
145            }
146        } else if ( (this.reply_status == OBJECT_FORWARD) ||
147                (this.reply_status == OBJECT_FORWARD_PERM) ){
148            CDRInputStream cdr = (CDRInputStream) istream;
149            this.ior = IORFactories.makeIOR( cdr ) ;
150        }  else if (this.reply_status == LOC_NEEDS_ADDRESSING_MODE) {
151            // read GIOP::AddressingDisposition from body and resend the
152            // original request using the requested addressing mode. The
153            // resending is transparent to the caller.
154            this.addrDisposition = AddressingDispositionHelper.read(istream);
155        }
156    }
157
158    // Note, this writes only the header information. SystemException or
159    // IOR or GIOP::AddressingDisposition may be written afterwards into the
160    // reply mesg body.
161    public void write(org.omg.CORBA.portable.OutputStream ostream) {
162        super.write(ostream);
163        ostream.write_ulong(this.request_id);
164        ostream.write_long(this.reply_status);
165
166
167        // GIOP 1.2 LocateReply message bodies are not aligned on
168        // 8 byte boundaries.
169    }
170
171    // Static methods
172
173    public static void isValidReplyStatus(int replyStatus) {
174        switch (replyStatus) {
175        case UNKNOWN_OBJECT :
176        case OBJECT_HERE :
177        case OBJECT_FORWARD :
178        case OBJECT_FORWARD_PERM :
179        case LOC_SYSTEM_EXCEPTION :
180        case LOC_NEEDS_ADDRESSING_MODE :
181            break;
182        default :
183            ORBUtilSystemException localWrapper = ORBUtilSystemException.get(
184                CORBALogDomains.RPC_PROTOCOL ) ;
185            throw localWrapper.illegalReplyStatus( CompletionStatus.COMPLETED_MAYBE);
186        }
187    }
188
189    public void callback(MessageHandler handler)
190        throws java.io.IOException
191    {
192        handler.handleInput(this);
193    }
194} // class LocateReplyMessage_1_2
195