📄 responsehandlerimpl.java
字号:
/* ResponseHandlerImpl.java -- Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package gnu.CORBA;import gnu.CORBA.CDR.BufferedCdrOutput;import gnu.CORBA.GIOP.MessageHeader;import gnu.CORBA.GIOP.ReplyHeader;import gnu.CORBA.GIOP.RequestHeader;import gnu.CORBA.GIOP.CodeSetServiceContext;import org.omg.CORBA.ORB;import org.omg.CORBA.portable.OutputStream;import org.omg.CORBA.portable.ResponseHandler;/** * Provides the CDR output streams for writing the response to the given buffer. * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */public class ResponseHandlerImpl implements ResponseHandler{ /** * The message header. This field is used to compute the size and alignments. * It is, however, never directly written to the buffer stream. */ public final MessageHeader message_header; /** * The associated orb. */ public final ORB orb; /** * The reply header. */ public final ReplyHeader reply_header; /** * The request header. */ public final RequestHeader request_header; /** * True if the stream was obtained by invoking {@link #createExceptionReply()}, * false otherwise. */ private boolean exceptionReply; /** * The buffer to write into. */ private BufferedCdrOutput buffer; /** * Create a new buffered response handler that uses the given message headers. * The headers are used to compute sizes and check the versions. They are not * written into a stream inside this class. * * @param m_header a message header. * @param r_header a reply header. */ ResponseHandlerImpl(ORB an_orb, MessageHeader m_header, ReplyHeader r_header, RequestHeader rq_header) { message_header = m_header; reply_header = r_header; request_header = rq_header; orb = an_orb; prepareStream(); } /** * Get an output stream for providing details about the exception. Before * returning the stream, the handler automatically writes the message header * and the reply about exception header, but not the message header. * * @return the stream to write exception details into. */ public OutputStream createExceptionReply() { exceptionReply = true; prepareStream(); return buffer; } /** * Get an output stream for writing a regular reply (not an exception). * * Before returning the stream, the handler automatically writes the regular * reply header, but not the message header. * * @return the output stream for writing a regular reply. */ public OutputStream createReply() { exceptionReply = false; prepareStream(); reply_header.reply_status = ReplyHeader.NO_EXCEPTION; return buffer; } /** * Get the buffer, normally containing the written reply. The reply includes * the reply header (or the exception header) but does not include the message * header. * * The stream buffer can also be empty if no data have been written into * streams, returned by {@link #createReply()} or * {@link #createExceptionReply()}. * * @return the CDR output stream, containing the written output. */ public BufferedCdrOutput getBuffer() { return buffer; } /** * True if the stream was obtained by invoking {@link #createExceptionReply()}, * false otherwise (usually no-exception reply). */ public boolean isExceptionReply() { return exceptionReply; } /** * Compute the header offset, set the correct version number and codeset. */ private void prepareStream() { buffer = new BufferedCdrOutput(); buffer.setOrb(orb); buffer.setVersion(message_header.version); buffer.setCodeSet(CodeSetServiceContext.find(reply_header.service_context)); // Since 1.2, the data section is always aligned on the 8 byte boundary. // In older versions, it is necessary to set the offset correctly. if (message_header.version.until_inclusive(1, 1)) { 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); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -