001: /*
002: * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.iiop;
030:
031: import java.io.IOException;
032: import java.util.ArrayList;
033:
034: public class Iiop10Writer extends IiopWriter {
035: public Iiop10Writer() {
036: }
037:
038: public Iiop10Writer(IiopWriter parent, MessageWriter out) {
039: super (parent, out);
040: }
041:
042: /**
043: * Writes the header for a request
044: *
045: * @param operation the method to call
046: */
047: public void startRequest(byte[] oid, int off, int len,
048: String operation, int requestId,
049: ArrayList<ServiceContext> scl) throws IOException {
050: startMessage(IiopReader.MSG_REQUEST);
051:
052: writeRequestServiceControlList(); // service context list
053:
054: write_long(requestId); // request id
055: _out.write(1); // response expected
056:
057: writeBytes(oid, off, len); // object id
058: writeString(operation);
059: writeNull(); // principal
060: }
061:
062: /**
063: * Writes the header for a request
064: */
065: public void startReplyOk(int requestId) throws IOException {
066: startMessage(IiopReader.MSG_REPLY);
067:
068: write_long(0); // service control list
069: write_long(requestId); // request id
070: write_long(IiopReader.STATUS_NO_EXCEPTION); // okay
071: }
072:
073: /**
074: * Writes the header for a request
075: */
076: @Override
077: public void startReplySystemException(int requestId,
078: String exceptionId, int minorStatus, int completionStatus,
079: Throwable cause) throws IOException {
080: startMessage(IiopReader.MSG_REPLY);
081:
082: if (cause == null) {
083: write_long(0); // service control list
084: } else {
085: write_long(1);
086: write_long(IiopReader.SERVICE_UNKNOWN_EXCEPTION_INFO);
087:
088: EncapsulationMessageWriter out = new EncapsulationMessageWriter();
089: Iiop10Writer writer = new Iiop10Writer(this , out);
090: writer.init(out);
091: writer.write(0); // endian
092: writer.write_value(cause);
093: //writer.close();
094: out.close();
095:
096: int len = out.getOffset();
097: write_long(len);
098:
099: out.writeToWriter(this );
100: }
101:
102: write_long(requestId); // request id
103: write_long(IiopReader.STATUS_SYSTEM_EXCEPTION);
104:
105: writeString(exceptionId);
106: write_long(minorStatus);
107: write_long(completionStatus);
108: }
109:
110: /**
111: * Writes the header for a request
112: */
113: public void startReplyUserException(int requestId)
114: throws IOException {
115: startMessage(IiopReader.MSG_REPLY);
116:
117: write_long(0); // service control list
118: write_long(requestId); // request id
119: write_long(IiopReader.STATUS_USER_EXCEPTION);
120: }
121:
122: /**
123: * Starts the message.
124: */
125: protected void startMessage(int type) throws IOException {
126: _out.start10Message(type);
127: }
128:
129: /**
130: * Writes the header for a request
131: *
132: * @param operation the method to call
133: */
134: public void sendClose() throws IOException {
135: startMessage(IiopReader.MSG_CLOSE_CONNECTION);
136: }
137: }
|