KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)RequestMessage_1_2.java 1.18 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.Principal JavaDoc;
11 import com.sun.corba.se.spi.servicecontext.ServiceContexts;
12 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
13 import com.sun.corba.se.spi.orb.ORB;
14 import com.sun.corba.se.spi.ior.ObjectKey;
15 import com.sun.corba.se.impl.encoding.CDRInputStream;
16 import com.sun.corba.se.impl.encoding.CDROutputStream;
17 import com.sun.corba.se.impl.orbutil.ORBConstants;
18 import com.sun.corba.se.impl.encoding.CDRInputStream_1_2;
19 import com.sun.corba.se.impl.encoding.CDROutputStream_1_2;
20
21 import com.sun.corba.se.spi.logging.CORBALogDomains ;
22 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
23
24 /**
25  * This implements the GIOP 1.2 Request header.
26  *
27  * @author Ram Jeyaraman 05/14/2000
28  * @version 1.0
29  */

30
31 public final class RequestMessage_1_2 extends Message_1_2
32         implements RequestMessage {
33
34     // Instance variables
35

36     private ORB orb = null;
37     private ORBUtilSystemException wrapper = null ;
38     private byte response_flags = (byte) 0;
39     private byte reserved[] = null;
40     private TargetAddress target = null;
41     private String JavaDoc operation = null;
42     private ServiceContexts service_contexts = null;
43     private ObjectKey objectKey = null;
44
45     // Constructors
46

47     RequestMessage_1_2(ORB orb) {
48         this.orb = orb;
49     this.wrapper = ORBUtilSystemException.get( orb,
50         CORBALogDomains.RPC_PROTOCOL ) ;
51     }
52
53     RequestMessage_1_2(ORB orb, int _request_id, byte _response_flags,
54             byte[] _reserved, TargetAddress _target,
55             String JavaDoc _operation, ServiceContexts _service_contexts) {
56         super(Message.GIOPBigMagic, GIOPVersion.V1_2, FLAG_NO_FRAG_BIG_ENDIAN,
57             Message.GIOPRequest, 0);
58         this.orb = orb;
59     this.wrapper = ORBUtilSystemException.get( orb,
60         CORBALogDomains.RPC_PROTOCOL ) ;
61         request_id = _request_id;
62         response_flags = _response_flags;
63         reserved = _reserved;
64         target = _target;
65         operation = _operation;
66         service_contexts = _service_contexts;
67     }
68
69     // Accessor methods (RequestMessage interface)
70

71     public int getRequestId() {
72         return this.request_id;
73     }
74
75     public boolean isResponseExpected() {
76         /*
77         case 1: LSBit[1] == 1
78             not a oneway call (DII flag INV_NO_RESPONSE is false) // Ox03
79             LSBit[0] must be 1.
80         case 2: LSBit[1] == 0
81             if (LSB[0] == 0) // Ox00
82                 oneway call
83             else if (LSB[0] == 1) // 0x01
84                 oneway call; but server may provide
85                 a location forward response or system exception response.
86         */

87
88         if ( (this.response_flags & RESPONSE_EXPECTED_BIT) == RESPONSE_EXPECTED_BIT ) {
89             return true;
90         }
91
92         return false;
93     }
94
95     public byte[] getReserved() {
96         return this.reserved;
97     }
98
99     public ObjectKey getObjectKey() {
100         if (this.objectKey == null) {
101         // this will raise a MARSHAL exception upon errors.
102
this.objectKey = MessageBase.extractObjectKey(target, orb);
103         }
104
105     return this.objectKey;
106     }
107
108     public String JavaDoc getOperation() {
109         return this.operation;
110     }
111
112     public Principal JavaDoc getPrincipal() {
113         // REVISIT Should we throw an exception or return null ?
114
return null;
115     }
116
117     public ServiceContexts getServiceContexts() {
118         return this.service_contexts;
119     }
120
121     // IO methods
122

123     public void read(org.omg.CORBA.portable.InputStream JavaDoc istream) {
124         super.read(istream);
125         this.request_id = istream.read_ulong();
126         this.response_flags = istream.read_octet();
127         this.reserved = new byte[3];
128         for (int _o0 = 0;_o0 < (3); ++_o0) {
129             this.reserved[_o0] = istream.read_octet();
130         }
131         this.target = TargetAddressHelper.read(istream);
132         getObjectKey(); // this does AddressingDisposition check
133
this.operation = istream.read_string();
134         this.service_contexts
135             = new ServiceContexts((org.omg.CORBA_2_3.portable.InputStream JavaDoc) istream);
136
137         // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
138
// aligned on an 8 octet boundary.
139
// Ensures that the first read operation called from the stub code,
140
// during body deconstruction, would skip the header padding, that was
141
// inserted to ensure that the body was aligned on an 8-octet boundary.
142
((CDRInputStream)istream).setHeaderPadding(true);
143         
144     }
145
146     public void write(org.omg.CORBA.portable.OutputStream JavaDoc ostream) {
147         super.write(ostream);
148         ostream.write_ulong(this.request_id);
149         ostream.write_octet(this.response_flags);
150         nullCheck(this.reserved);
151         if (this.reserved.length != (3)) {
152         throw wrapper.badReservedLength(
153                 org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
154         }
155         for (int _i0 = 0;_i0 < (3); ++_i0) {
156             ostream.write_octet(this.reserved[_i0]);
157         }
158         nullCheck(this.target);
159         TargetAddressHelper.write(ostream, this.target);
160         ostream.write_string(this.operation);
161         if (this.service_contexts != null) {
162             service_contexts.write(
163                 (org.omg.CORBA_2_3.portable.OutputStream JavaDoc) ostream,
164                 GIOPVersion.V1_2);
165         } else {
166             ServiceContexts.writeNullServiceContext(
167                 (org.omg.CORBA_2_3.portable.OutputStream JavaDoc) ostream);
168         }
169
170         // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
171
// aligned on an 8 octet boundary.
172
// Ensures that the first write operation called from the stub code,
173
// during body construction, would insert a header padding, such that
174
// the body is aligned on an 8-octet boundary.
175
((CDROutputStream)ostream).setHeaderPadding(true);
176     }
177
178     public void callback(MessageHandler handler)
179         throws java.io.IOException JavaDoc
180     {
181         handler.handleInput(this);
182     }
183 } // class RequestMessage_1_2
184
Popular Tags