Update concepts branch to revision 131834
[official-gcc.git] / libjava / classpath / gnu / CORBA / GIOP / v1_2 / RequestHeader.java
blob2afa4b3a1d5209907ba930d391f6c862823f7abb
1 /* RequestHeader.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.CORBA.GIOP.v1_2;
41 import gnu.CORBA.Minor;
42 import gnu.CORBA.CDR.AbstractCdrInput;
43 import gnu.CORBA.CDR.AbstractCdrOutput;
44 import gnu.CORBA.GIOP.ServiceContext;
45 import gnu.CORBA.GIOP.CodeSetServiceContext;
47 import java.io.IOException;
49 import org.omg.CORBA.MARSHAL;
50 import org.omg.CORBA.NO_IMPLEMENT;
52 /**
53 * The GIOP 1.2 request header. The GIOP 1.1 request header
54 * is the same as GIOP 1.0 request header, if taking the
55 * alignment into consideration.
57 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
59 public class RequestHeader
60 extends gnu.CORBA.GIOP.v1_0.RequestHeader
62 /**
63 * Use serialVersionUID for interoperability.
65 private static final long serialVersionUID = 1;
67 /**
68 * Indicates that the object is addressed by the object key.
70 public static final short KeyAddr = 0;
72 /**
73 * Indicates that the object is addressed by the IOP tagged profile.
75 public static final short ProfileAddr = 1;
77 /**
78 * Indicates that the objec is addressed by IOR addressing info.
80 public static final short ReferenceAddr = 2;
82 /**
83 * The response flags of the header. By default, the flags are initialised
84 * by value 0x3 (response expected).
86 public byte response_flags = 3;
88 /**
89 * The used addressing method.
91 public short AddressingDisposition;
93 /**
94 * Adds the standard encoding context.
96 public RequestHeader()
98 service_context = new ServiceContext[] { CodeSetServiceContext.STANDARD };
102 * Set if the sender expects any response to this message.
103 * Clears or sets the 2 lower bits of flags
104 * (0 - not expected, 0x3 - expected).
106 public void setResponseExpected(boolean expected)
108 response_expected = expected;
110 if (expected)
111 response_flags = (byte) (response_flags | 0x3);
112 else
113 response_flags = (byte) (response_flags & (~0x3));
117 * Return true if response is expected.
119 * @return true if the two lowest bits of the flags are set or
120 * the response expected is explicitly set to true.
122 public boolean isResponseExpected()
124 return response_expected || ((response_flags & 0x3) == 0x3);
128 * Read the header from the given stream.
130 * @param in a stream to read from.
132 public void read(AbstractCdrInput in)
136 request_id = in.read_ulong();
137 response_flags = (byte) in.read();
139 // Skip 3 reserved octets:
140 in.skip(3);
142 // Read target address.
143 AddressingDisposition = in.read_ushort();
145 switch (AddressingDisposition)
147 case KeyAddr :
148 object_key = in.read_sequence();
149 break;
151 // TODO FIXME add other addressing methods.
152 case ProfileAddr :
153 throw new NO_IMPLEMENT("Object addressing by IOP tagged profile");
155 case ReferenceAddr :
156 throw new NO_IMPLEMENT("Object addressing by IOR addressing info");
158 default :
159 MARSHAL m = new MARSHAL("Unknow addressing method in request, " +
160 AddressingDisposition
162 m.minor = Minor.UnsupportedAddressing;
163 throw m;
166 operation = in.read_string();
167 service_context = gnu.CORBA.GIOP.ServiceContext.readSequence(in);
169 // No requesting principal in this new format.
170 in.setCodeSet(CodeSetServiceContext.find(service_context));
172 catch (IOException ex)
174 MARSHAL t = new MARSHAL();
175 t.minor = Minor.Header;
176 t.initCause(ex);
177 throw t;
182 * Return a string representation.
184 public String toString()
186 return "Request " + request_id + ", call '" + operation + "' on " +
187 bytes(object_key) + ", " +
188 (response_expected ? "wait response" : "one way") +
189 " addressed by " + " method " + AddressingDisposition + "." +
190 contexts();
194 * Write the header to the given stream.
196 * @param out a stream to write into.
198 public void write(AbstractCdrOutput out)
200 out.write_ulong(request_id);
202 out.write(response_flags);
204 // Skip 3 reserved octets:
205 out.write(0);
206 out.write(0);
207 out.write(0);
209 // Write addressing disposition from IOR.
210 // TODO FIXME add other addressing methods.
211 out.write_ushort(KeyAddr);
213 out.write_sequence(object_key);
215 out.write_string(operation);
217 ServiceContext.writeSequence(out, service_context);
219 // No requesting principal in this new format.
220 out.setCodeSet(CodeSetServiceContext.find(service_context));