KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)ReplyMessage_1_0.java 1.20 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.CompletionStatus JavaDoc;
12 import org.omg.CORBA.SystemException 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 import com.sun.corba.se.impl.orbutil.ORBUtility;
22 import com.sun.corba.se.impl.orbutil.ORBClassLoader;
23 import com.sun.corba.se.spi.ior.IOR;
24 import com.sun.corba.se.impl.encoding.CDRInputStream;
25
26 import com.sun.corba.se.spi.logging.CORBALogDomains ;
27 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
28
29 /**
30  * This implements the GIOP 1.0 Reply header.
31  *
32  * @author Ram Jeyaraman 05/14/2000
33  * @version 1.0
34  */

35
36 public final class ReplyMessage_1_0 extends Message_1_0
37         implements ReplyMessage {
38
39     // Instance variables
40

41     private ORB orb = null;
42     private ORBUtilSystemException wrapper = null ;
43     private ServiceContexts service_contexts = null;
44     private int request_id = (int) 0;
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
51     // Constructors
52

53     ReplyMessage_1_0(ORB orb) {
54         this.orb = orb;
55     this.wrapper = ORBUtilSystemException.get( orb,
56         CORBALogDomains.RPC_PROTOCOL ) ;
57     }
58
59     ReplyMessage_1_0(ORB orb, ServiceContexts _service_contexts,
60             int _request_id, int _reply_status, IOR _ior) {
61         super(Message.GIOPBigMagic, false, Message.GIOPReply, 0);
62         this.orb = orb;
63     this.wrapper = ORBUtilSystemException.get( orb,
64         CORBALogDomains.RPC_PROTOCOL ) ;
65         service_contexts = _service_contexts;
66         request_id = _request_id;
67         reply_status = _reply_status;
68         ior = _ior;
69     }
70
71     // Accessor methods
72

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

108     public void read(org.omg.CORBA.portable.InputStream JavaDoc istream) {
109         super.read(istream);
110         this.service_contexts
111             = new ServiceContexts((org.omg.CORBA_2_3.portable.InputStream JavaDoc) istream);
112         this.request_id = istream.read_ulong();
113         this.reply_status = istream.read_long();
114         isValidReplyStatus(this.reply_status); // raises exception on error
115

116         // The code below reads the reply body in some cases
117
// SYSTEM_EXCEPTION & LOCATION_FORWARD
118
if (this.reply_status == SYSTEM_EXCEPTION) {
119
120             String JavaDoc reposId = istream.read_string();
121             this.exClassName = ORBUtility.classNameOf(reposId);
122             this.minorCode = istream.read_long();
123             int status = istream.read_long();
124
125             switch (status) {
126             case CompletionStatus._COMPLETED_YES:
127                 this.completionStatus = CompletionStatus.COMPLETED_YES;
128                 break;
129             case CompletionStatus._COMPLETED_NO:
130                 this.completionStatus = CompletionStatus.COMPLETED_NO;
131                 break;
132             case CompletionStatus._COMPLETED_MAYBE:
133                 this.completionStatus = CompletionStatus.COMPLETED_MAYBE;
134                 break;
135             default:
136         throw wrapper.badCompletionStatusInReply(
137             CompletionStatus.COMPLETED_MAYBE, new Integer JavaDoc(status) );
138             }
139
140         } else if (this.reply_status == USER_EXCEPTION) {
141             // do nothing. The client stub will read the exception from body.
142
} else if (this.reply_status == LOCATION_FORWARD) {
143             CDRInputStream cdr = (CDRInputStream) istream;
144         this.ior = IORFactories.makeIOR( cdr ) ;
145         }
146     }
147
148     // Note, this writes only the header information. SystemException or
149
// IOR may be written afterwards into the reply mesg body.
150
public void write(org.omg.CORBA.portable.OutputStream JavaDoc ostream) {
151         super.write(ostream);
152         if (this.service_contexts != null) {
153             service_contexts.write(
154                 (org.omg.CORBA_2_3.portable.OutputStream JavaDoc) ostream,
155                 GIOPVersion.V1_0);
156         } else {
157             ServiceContexts.writeNullServiceContext(
158                 (org.omg.CORBA_2_3.portable.OutputStream JavaDoc) ostream);
159         }
160         ostream.write_ulong(this.request_id);
161         ostream.write_long(this.reply_status);
162     }
163
164     // Static methods
165

166     public static void isValidReplyStatus(int replyStatus) {
167         switch (replyStatus) {
168         case NO_EXCEPTION :
169         case USER_EXCEPTION :
170         case SYSTEM_EXCEPTION :
171         case LOCATION_FORWARD :
172             break;
173         default :
174         ORBUtilSystemException localWrapper = ORBUtilSystemException.get(
175         CORBALogDomains.RPC_PROTOCOL ) ;
176         throw localWrapper.illegalReplyStatus( CompletionStatus.COMPLETED_MAYBE);
177         }
178     }
179
180     public void callback(MessageHandler handler)
181         throws java.io.IOException JavaDoc
182     {
183         handler.handleInput(this);
184     }
185 } //
186
Popular Tags