KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)ReplyMessage_1_2.java 1.23 04/06/21
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.ior.IOR;
15 import com.sun.corba.se.spi.ior.IORFactories ;
16
17 import com.sun.corba.se.spi.orb.ORB;
18
19 import com.sun.corba.se.spi.servicecontext.ServiceContexts;
20 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
21
22 import com.sun.corba.se.impl.encoding.CDRInputStream;
23 import com.sun.corba.se.impl.encoding.CDROutputStream;
24 import com.sun.corba.se.impl.encoding.CDRInputStream_1_2;
25 import com.sun.corba.se.impl.encoding.CDROutputStream_1_2;
26
27 import com.sun.corba.se.impl.orbutil.ORBUtility;
28 import com.sun.corba.se.impl.orbutil.ORBConstants;
29
30 import com.sun.corba.se.spi.logging.CORBALogDomains ;
31 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
32
33 /**
34  * This implements the GIOP 1.2 Reply header.
35  *
36  * @author Ram Jeyaraman 05/14/2000
37  * @version 1.0
38  */

39
40 public final class ReplyMessage_1_2 extends Message_1_2
41         implements ReplyMessage {
42
43     // Instance variables
44

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

55     // Constructors
56

57     ReplyMessage_1_2(ORB orb) {
58         this.orb = orb;
59     this.wrapper = ORBUtilSystemException.get( orb,
60         CORBALogDomains.RPC_PROTOCOL ) ;
61     }
62
63     ReplyMessage_1_2(ORB orb, int _request_id, int _reply_status,
64             ServiceContexts _service_contexts, IOR _ior) {
65         super(Message.GIOPBigMagic, GIOPVersion.V1_2, FLAG_NO_FRAG_BIG_ENDIAN,
66             Message.GIOPReply, 0);
67         this.orb = orb;
68     this.wrapper = ORBUtilSystemException.get( orb,
69         CORBALogDomains.RPC_PROTOCOL ) ;
70         request_id = _request_id;
71         reply_status = _reply_status;
72         service_contexts = _service_contexts;
73         ior = _ior;
74     }
75
76     // Accessor methods
77

78     public int getRequestId() {
79         return this.request_id;
80     }
81
82     public int getReplyStatus() {
83         return this.reply_status;
84     }
85
86     public short getAddrDisposition() {
87         return this.addrDisposition;
88     }
89     
90     public ServiceContexts getServiceContexts() {
91         return this.service_contexts;
92     }
93
94     public void setServiceContexts( ServiceContexts sc ) {
95         this.service_contexts = sc;
96     }
97
98     public SystemException JavaDoc getSystemException(String JavaDoc message) {
99     return MessageBase.getSystemException(
100             exClassName, minorCode, completionStatus, message, wrapper);
101     }
102
103     public IOR getIOR() {
104         return this.ior;
105     }
106
107     public void setIOR( IOR ior ) {
108     this.ior = ior;
109     }
110
111     // IO methods
112

113     public void read(org.omg.CORBA.portable.InputStream JavaDoc 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
this.service_contexts
119             = new ServiceContexts((org.omg.CORBA_2_3.portable.InputStream JavaDoc) istream);
120
121         // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
122
// aligned on an 8 octet boundary.
123
// Ensures that the first read operation called from the stub code,
124
// during body deconstruction, would skip the header padding, that was
125
// inserted to ensure that the body was aligned on an 8-octet boundary.
126
((CDRInputStream)istream).setHeaderPadding(true);
127
128         // The code below reads the reply body in some cases
129
// SYSTEM_EXCEPTION & LOCATION_FORWARD & LOCATION_FORWARD_PERM &
130
// NEEDS_ADDRESSING_MODE
131
if (this.reply_status == SYSTEM_EXCEPTION) {
132
133             String JavaDoc reposId = istream.read_string();
134             this.exClassName = ORBUtility.classNameOf(reposId);
135             this.minorCode = istream.read_long();
136             int status = istream.read_long();
137
138             switch (status) {
139             case CompletionStatus._COMPLETED_YES:
140                 this.completionStatus = CompletionStatus.COMPLETED_YES;
141                 break;
142             case CompletionStatus._COMPLETED_NO:
143                 this.completionStatus = CompletionStatus.COMPLETED_NO;
144                 break;
145             case CompletionStatus._COMPLETED_MAYBE:
146                 this.completionStatus = CompletionStatus.COMPLETED_MAYBE;
147                 break;
148             default:
149         throw wrapper.badCompletionStatusInReply(
150             CompletionStatus.COMPLETED_MAYBE, new Integer JavaDoc(status) );
151             }
152
153         } else if (this.reply_status == USER_EXCEPTION) {
154             // do nothing. The client stub will read the exception from body.
155
} else if ( (this.reply_status == LOCATION_FORWARD) ||
156                 (this.reply_status == LOCATION_FORWARD_PERM) ){
157             CDRInputStream cdr = (CDRInputStream) istream;
158         this.ior = IORFactories.makeIOR( cdr ) ;
159         } else if (this.reply_status == NEEDS_ADDRESSING_MODE) {
160             // read GIOP::AddressingDisposition from body and resend the
161
// original request using the requested addressing mode. The
162
// resending is transparent to the client program.
163
this.addrDisposition = AddressingDispositionHelper.read(istream);
164         }
165     }
166
167     // Note, this writes only the header information. SystemException or
168
// IOR or GIOP::AddressingDisposition may be written afterwards into the
169
// reply mesg body.
170
public void write(org.omg.CORBA.portable.OutputStream JavaDoc ostream) {
171         super.write(ostream);
172         ostream.write_ulong(this.request_id);
173         ostream.write_long(this.reply_status);
174         if (this.service_contexts != null) {
175             service_contexts.write(
176                 (org.omg.CORBA_2_3.portable.OutputStream JavaDoc) ostream,
177                 GIOPVersion.V1_2);
178         } else {
179             ServiceContexts.writeNullServiceContext(
180                 (org.omg.CORBA_2_3.portable.OutputStream JavaDoc) ostream);
181         }
182
183         // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
184
// aligned on an 8 octet boundary.
185
// Ensures that the first write operation called from the stub code,
186
// during body construction, would insert a header padding, such that
187
// the body is aligned on an 8-octet boundary.
188
((CDROutputStream)ostream).setHeaderPadding(true);
189         
190     }
191
192     // Static methods
193

194     public static void isValidReplyStatus(int replyStatus) {
195         switch (replyStatus) {
196         case NO_EXCEPTION :
197         case USER_EXCEPTION :
198         case SYSTEM_EXCEPTION :
199         case LOCATION_FORWARD :
200         case LOCATION_FORWARD_PERM :
201         case NEEDS_ADDRESSING_MODE :
202             break;
203         default :
204         ORBUtilSystemException localWrapper = ORBUtilSystemException.get(
205         CORBALogDomains.RPC_PROTOCOL ) ;
206         throw localWrapper.illegalReplyStatus( CompletionStatus.COMPLETED_MAYBE);
207         }
208     }
209
210     public void callback(MessageHandler handler)
211         throws java.io.IOException JavaDoc
212     {
213         handler.handleInput(this);
214     }
215 } // class ReplyMessage_1_2
216
Popular Tags