KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)ReplyMessage_1_1.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.1 Reply header.
31  *
32  * @author Ram Jeyaraman 05/14/2000
33  * @version 1.0
34  */

35
36 public final class ReplyMessage_1_1 extends Message_1_1
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_1(ORB orb) {
54         this.orb = orb;
55     this.wrapper = ORBUtilSystemException.get( orb,
56         CORBALogDomains.RPC_PROTOCOL ) ;
57     }
58
59     ReplyMessage_1_1(ORB orb, ServiceContexts _service_contexts,
60             int _request_id, int _reply_status, IOR _ior) {
61         super(Message.GIOPBigMagic, GIOPVersion.V1_1, FLAG_NO_FRAG_BIG_ENDIAN,
62             Message.GIOPReply, 0);
63         this.orb = orb;
64     this.wrapper = ORBUtilSystemException.get( orb,
65         CORBALogDomains.RPC_PROTOCOL ) ;
66         service_contexts = _service_contexts;
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 KeyAddr.value;
84     }
85     
86     public ServiceContexts getServiceContexts() {
87         return this.service_contexts;
88     }
89
90     public void setServiceContexts( ServiceContexts sc ) {
91         this.service_contexts = sc;
92     }
93
94     public SystemException JavaDoc getSystemException(String JavaDoc message) {
95     return MessageBase.getSystemException(
96             exClassName, minorCode, completionStatus, message, wrapper);
97     }
98
99     public IOR getIOR() {
100         return this.ior;
101     }
102
103     public void setIOR( IOR ior ) {
104     this.ior = ior;
105     }
106
107     // IO methods
108

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

117         // The code below reads the reply body in some cases
118
// SYSTEM_EXCEPTION & LOCATION_FORWARD
119
if (this.reply_status == SYSTEM_EXCEPTION) {
120
121             String JavaDoc reposId = istream.read_string();
122             this.exClassName = ORBUtility.classNameOf(reposId);
123             this.minorCode = istream.read_long();
124             int status = istream.read_long();
125
126             switch (status) {
127             case CompletionStatus._COMPLETED_YES:
128                 this.completionStatus = CompletionStatus.COMPLETED_YES;
129                 break;
130             case CompletionStatus._COMPLETED_NO:
131                 this.completionStatus = CompletionStatus.COMPLETED_NO;
132                 break;
133             case CompletionStatus._COMPLETED_MAYBE:
134                 this.completionStatus = CompletionStatus.COMPLETED_MAYBE;
135                 break;
136             default:
137         throw wrapper.badCompletionStatusInReply(
138             CompletionStatus.COMPLETED_MAYBE, new Integer JavaDoc(status) );
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_1);
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