41 |
import gnu.CORBA.CDR.cdrBufOutput; |
import gnu.CORBA.CDR.cdrBufOutput; |
42 |
import gnu.CORBA.GIOP.MessageHeader; |
import gnu.CORBA.GIOP.MessageHeader; |
43 |
import gnu.CORBA.GIOP.ReplyHeader; |
import gnu.CORBA.GIOP.ReplyHeader; |
44 |
|
import gnu.CORBA.GIOP.RequestHeader; |
45 |
import gnu.CORBA.GIOP.cxCodeSet; |
import gnu.CORBA.GIOP.cxCodeSet; |
46 |
|
|
47 |
import org.omg.CORBA.ORB; |
import org.omg.CORBA.ORB; |
49 |
import org.omg.CORBA.portable.ResponseHandler; |
import org.omg.CORBA.portable.ResponseHandler; |
50 |
|
|
51 |
/** |
/** |
52 |
* Provides the CDR output streams for writing the response to the given |
* Provides the CDR output streams for writing the response to the given buffer. |
|
* buffer. |
|
53 |
* |
* |
54 |
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
55 |
*/ |
*/ |
56 |
class bufferedResponseHandler |
public class bufferedResponseHandler |
57 |
implements ResponseHandler |
implements ResponseHandler |
58 |
{ |
{ |
59 |
/** |
/** |
60 |
* The message header. |
* The message header. This field is used to compute the size and alignments. |
|
* This field is used to compute the size and alignments. |
|
61 |
* It is, however, never directly written to the buffer stream. |
* It is, however, never directly written to the buffer stream. |
62 |
*/ |
*/ |
63 |
final MessageHeader message_header; |
public final MessageHeader message_header; |
64 |
|
|
65 |
/** |
/** |
66 |
* The associated orb. |
* The associated orb. |
67 |
*/ |
*/ |
68 |
final ORB orb; |
public final ORB orb; |
69 |
|
|
70 |
/** |
/** |
71 |
* The reply header. This field is used to compute the size and alignments. |
* The reply header. |
72 |
* It is, however, never directly written to the buffer stream. |
*/ |
73 |
|
public final ReplyHeader reply_header; |
74 |
|
|
75 |
|
/** |
76 |
|
* The request header. |
77 |
*/ |
*/ |
78 |
final ReplyHeader reply_header; |
public final RequestHeader request_header; |
79 |
|
|
80 |
/** |
/** |
81 |
* True if the stream was obtained by invoking {@link #createExceptionReply()}, |
* True if the stream was obtained by invoking {@link #createExceptionReply()}, |
89 |
private cdrBufOutput buffer; |
private cdrBufOutput buffer; |
90 |
|
|
91 |
/** |
/** |
92 |
* Create a new buffered response handler that uses the given message |
* Create a new buffered response handler that uses the given message headers. |
93 |
* headers. The headers are used to compute sizes and check the versions. |
* The headers are used to compute sizes and check the versions. They are not |
94 |
* They are not written into a stream inside this class. |
* written into a stream inside this class. |
95 |
* |
* |
96 |
* @param m_header a message header. |
* @param m_header a message header. |
97 |
* @param r_header a reply header. |
* @param r_header a reply header. |
98 |
*/ |
*/ |
99 |
bufferedResponseHandler(ORB an_orb, MessageHeader m_header, |
bufferedResponseHandler(ORB an_orb, MessageHeader m_header, |
100 |
ReplyHeader r_header |
ReplyHeader r_header, RequestHeader rq_header) |
|
) |
|
101 |
{ |
{ |
102 |
message_header = m_header; |
message_header = m_header; |
103 |
reply_header = r_header; |
reply_header = r_header; |
104 |
|
request_header = rq_header; |
105 |
orb = an_orb; |
orb = an_orb; |
106 |
prepareStream(); |
prepareStream(); |
107 |
} |
} |
108 |
|
|
109 |
/** |
/** |
110 |
* Get an output stream for providing details about the exception. |
* Get an output stream for providing details about the exception. Before |
111 |
* Before returning the stream, the handler automatically writes |
* returning the stream, the handler automatically writes the message header |
112 |
* the message header and the reply about exception header, |
* and the reply about exception header, but not the message header. |
|
* but not the message header. |
|
113 |
* |
* |
114 |
* @return the stream to write exception details into. |
* @return the stream to write exception details into. |
115 |
*/ |
*/ |
123 |
/** |
/** |
124 |
* Get an output stream for writing a regular reply (not an exception). |
* Get an output stream for writing a regular reply (not an exception). |
125 |
* |
* |
126 |
* Before returning the stream, the handler automatically writes |
* Before returning the stream, the handler automatically writes the regular |
127 |
* the regular reply header, but not the message header. |
* reply header, but not the message header. |
128 |
* |
* |
129 |
* @return the output stream for writing a regular reply. |
* @return the output stream for writing a regular reply. |
130 |
*/ |
*/ |
137 |
} |
} |
138 |
|
|
139 |
/** |
/** |
140 |
* Get the buffer, normally containing the written reply. |
* Get the buffer, normally containing the written reply. The reply includes |
141 |
* The reply includes the reply header (or the exception header) |
* the reply header (or the exception header) but does not include the message |
142 |
* but does not include the message header. |
* header. |
143 |
* |
* |
144 |
* The stream buffer can also be empty if no data have been written |
* The stream buffer can also be empty if no data have been written into |
145 |
* into streams, returned by {@link #createReply()} or |
* streams, returned by {@link #createReply()} or |
146 |
* {@link #createExceptionReply()}. |
* {@link #createExceptionReply()}. |
147 |
* |
* |
148 |
* @return the CDR output stream, containing the written output. |
* @return the CDR output stream, containing the written output. |
149 |
*/ |
*/ |
150 |
cdrBufOutput getBuffer() |
public cdrBufOutput getBuffer() |
151 |
{ |
{ |
152 |
return buffer; |
return buffer; |
153 |
} |
} |
154 |
|
|
155 |
/** |
/** |
156 |
* True if the stream was obtained by invoking |
* True if the stream was obtained by invoking {@link #createExceptionReply()}, |
157 |
* {@link #createExceptionReply()}, false otherwise |
* false otherwise (usually no-exception reply). |
|
* (usually no-exception reply). |
|
158 |
*/ |
*/ |
159 |
boolean isExceptionReply() |
public boolean isExceptionReply() |
160 |
{ |
{ |
161 |
return exceptionReply; |
return exceptionReply; |
162 |
} |
} |
168 |
{ |
{ |
169 |
buffer = new cdrBufOutput(); |
buffer = new cdrBufOutput(); |
170 |
buffer.setOrb(orb); |
buffer.setOrb(orb); |
|
buffer.setOffset(message_header.getHeaderSize()); |
|
|
|
|
|
// Get the position after the reply header would be written. |
|
|
reply_header.write(buffer); |
|
|
|
|
|
int new_offset = message_header.getHeaderSize() + buffer.buffer.size(); |
|
|
|
|
|
buffer.buffer.reset(); |
|
|
buffer.setOffset(new_offset); |
|
|
|
|
|
if (message_header.version.since_inclusive(1, 2)) |
|
|
buffer.align(8); |
|
|
|
|
171 |
buffer.setVersion(message_header.version); |
buffer.setVersion(message_header.version); |
|
|
|
172 |
buffer.setCodeSet(cxCodeSet.find(reply_header.service_context)); |
buffer.setCodeSet(cxCodeSet.find(reply_header.service_context)); |
173 |
|
|
174 |
|
// Since 1.2, the data section is always aligned on the 8 byte boundary. |
175 |
|
// In older versions, it is necessary to set the offset correctly. |
176 |
|
if (message_header.version.until_inclusive(1, 1)) |
177 |
|
{ |
178 |
|
buffer.setOffset(message_header.getHeaderSize()); |
179 |
|
|
180 |
|
// Get the position after the reply header would be written. |
181 |
|
reply_header.write(buffer); |
182 |
|
|
183 |
|
int new_offset = message_header.getHeaderSize() + buffer.buffer.size(); |
184 |
|
|
185 |
|
buffer.buffer.reset(); |
186 |
|
buffer.setOffset(new_offset); |
187 |
|
} |
188 |
} |
} |
189 |
} |
} |