KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > protocol > giopmsgheaders > LocateReplyMessage_1_2


1 /*
2  * @(#)LocateReplyMessage_1_2.java 1.18 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.protocol.giopmsgheaders;
9
10 import org.omg.CORBA.INTERNAL JavaDoc;
11 import org.omg.CORBA.SystemException JavaDoc;
12 import org.omg.CORBA.CompletionStatus JavaDoc;
13
14 import com.sun.corba.se.spi.orb.ORB;
15
16 import com.sun.corba.se.spi.ior.IOR;
17 import com.sun.corba.se.spi.ior.IORFactories;
18
19 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
20
21 import com.sun.corba.se.impl.encoding.CDRInputStream;
22 import com.sun.corba.se.impl.encoding.CDROutputStream;
23
24 import com.sun.corba.se.impl.orbutil.ORBUtility;
25 import com.sun.corba.se.impl.orbutil.ORBConstants;
26 import com.sun.corba.se.impl.orbutil.ORBClassLoader;
27
28 import com.sun.corba.se.spi.logging.CORBALogDomains ;
29 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
30
31 /**
32  * This implements the GIOP 1.2 LocateReply header.
33  *
34  * @author Ram Jeyaraman 05/14/2000
35  * @version 1.0
36  */

37
38 public final class LocateReplyMessage_1_2 extends Message_1_2
39         implements LocateReplyMessage {
40
41     // Instance variables
42

43     private ORB orb = null;
44     private ORBUtilSystemException wrapper = null ;
45     private int reply_status = (int) 0;
46     private IOR ior = null;
47     private String JavaDoc exClassName = null;
48     private int minorCode = (int) 0;
49     private CompletionStatus JavaDoc completionStatus = null;
50     private short addrDisposition = KeyAddr.value; // default;
51

52     // Constructors
53

54     LocateReplyMessage_1_2(ORB orb) {
55         this.orb = orb;
56     this.wrapper = ORBUtilSystemException.get( orb,
57         CORBALogDomains.RPC_PROTOCOL ) ;
58     }
59
60     LocateReplyMessage_1_2(ORB orb, int _request_id,
61             int _reply_status, IOR _ior) {
62         super(Message.GIOPBigMagic, GIOPVersion.V1_2, FLAG_NO_FRAG_BIG_ENDIAN,
63             Message.GIOPLocateReply, 0);
64         this.orb = orb;
65     this.wrapper = ORBUtilSystemException.get( orb,
66         CORBALogDomains.RPC_PROTOCOL ) ;
67         request_id = _request_id;
68         reply_status = _reply_status;
69         ior = _ior;
70     }
71
72     // Accessor methods
73

74     public int getRequestId() {
75         return this.request_id;
76     }
77
78     public int getReplyStatus() {
79         return this.reply_status;
80     }
81
82     public short getAddrDisposition() {
83         return this.addrDisposition;
84     }
85
86     public SystemException JavaDoc getSystemException(String JavaDoc message) {
87     return MessageBase.getSystemException(
88             exClassName, minorCode, completionStatus, message, wrapper);
89     }
90
91     public IOR getIOR() {
92         return this.ior;
93     }
94
95     // IO methods
96

97     public void read(org.omg.CORBA.portable.InputStream JavaDoc istream) {
98         super.read(istream);
99         this.request_id = istream.read_ulong();
100         this.reply_status = istream.read_long();
101         isValidReplyStatus(this.reply_status); // raises exception on error
102

103         // GIOP 1.2 LocateReply message bodies are not aligned on
104
// 8 byte boundaries.
105

106         // The code below reads the reply body in some cases
107
// LOC_SYSTEM_EXCEPTION & OBJECT_FORWARD & OBJECT_FORWARD_PERM &
108
// LOC_NEEDS_ADDRESSING_MODE
109
if (this.reply_status == LOC_SYSTEM_EXCEPTION) {
110
111             String JavaDoc reposId = istream.read_string();
112             this.exClassName = ORBUtility.classNameOf(reposId);
113             this.minorCode = istream.read_long();
114             int status = istream.read_long();
115
116             switch (status) {
117             case CompletionStatus._COMPLETED_YES:
118                 this.completionStatus = CompletionStatus.COMPLETED_YES;
119                 break;
120             case CompletionStatus._COMPLETED_NO:
121                 this.completionStatus = CompletionStatus.COMPLETED_NO;
122                 break;
123             case CompletionStatus._COMPLETED_MAYBE:
124                 this.completionStatus = CompletionStatus.COMPLETED_MAYBE;
125                 break;
126             default:
127         throw wrapper.badCompletionStatusInLocateReply(
128             CompletionStatus.COMPLETED_MAYBE, new Integer JavaDoc(status) );
129             }
130         } else if ( (this.reply_status == OBJECT_FORWARD) ||
131                 (this.reply_status == OBJECT_FORWARD_PERM) ){
132             CDRInputStream cdr = (CDRInputStream) istream;
133         this.ior = IORFactories.makeIOR( cdr ) ;
134         } else if (this.reply_status == LOC_NEEDS_ADDRESSING_MODE) {
135             // read GIOP::AddressingDisposition from body and resend the
136
// original request using the requested addressing mode. The
137
// resending is transparent to the caller.
138
this.addrDisposition = AddressingDispositionHelper.read(istream);
139         }
140     }
141
142     // Note, this writes only the header information. SystemException or
143
// IOR or GIOP::AddressingDisposition may be written afterwards into the
144
// reply mesg body.
145
public void write(org.omg.CORBA.portable.OutputStream JavaDoc ostream) {
146         super.write(ostream);
147         ostream.write_ulong(this.request_id);
148         ostream.write_long(this.reply_status);
149
150
151         // GIOP 1.2 LocateReply message bodies are not aligned on
152
// 8 byte boundaries.
153
}
154
155     // Static methods
156

157     public static void isValidReplyStatus(int replyStatus) {
158         switch (replyStatus) {
159         case UNKNOWN_OBJECT :
160         case OBJECT_HERE :
161         case OBJECT_FORWARD :
162         case OBJECT_FORWARD_PERM :
163         case LOC_SYSTEM_EXCEPTION :
164         case LOC_NEEDS_ADDRESSING_MODE :
165             break;
166         default :
167         ORBUtilSystemException localWrapper = ORBUtilSystemException.get(
168         CORBALogDomains.RPC_PROTOCOL ) ;
169         throw localWrapper.illegalReplyStatus( CompletionStatus.COMPLETED_MAYBE);
170         }
171     }
172
173     public void callback(MessageHandler handler)
174         throws java.io.IOException JavaDoc
175     {
176         handler.handleInput(this);
177     }
178 } // class LocateReplyMessage_1_2
179
Popular Tags