KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > iiop > Iiop12Writer


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.iiop;
31
32 import java.io.IOException JavaDoc;
33
34 public class Iiop12Writer extends Iiop10Writer {
35   private final static int KEY_ADDR = 0;
36   private final static int PROFILE_ADDR = 1;
37   private final static int REFERENCE_ADDR = 2;
38   /**
39    * Writes the header for a request
40    *
41    * @param operation the method to call
42    */

43   public void startRequest(byte []oid, int off, int len,
44                String JavaDoc operation, int requestId)
45     throws IOException JavaDoc
46   {
47     _out.start12Message(IiopReader.MSG_REQUEST, requestId);
48     
49     int flags = 0;
50
51     _out.write(1); // response expected
52
_out.write(0);
53     _out.write(0);
54     _out.write(0);
55
56     write_short((short) KEY_ADDR); // target
57
writeBytes(oid, off, len); // object id
58

59     writeString(operation);
60     
61     write_long(0); // service context list
62
}
63   /**
64    * Writes the header for a request
65    */

66   public void startReplyOk(int requestId)
67     throws IOException JavaDoc
68   {
69     _out.start12Message(IiopReader.MSG_REPLY, requestId);
70     
71     write_long(IiopReader.STATUS_NO_EXCEPTION); // okay
72
write_long(0); // service control list
73
}
74   
75   /**
76    * Writes the header for a request
77    */

78   public void startReplySystemException(int requestId,
79                                         String JavaDoc exceptionId,
80                                         int minorStatus,
81                                         int completionStatus)
82     throws IOException JavaDoc
83   {
84     _out.start12Message(IiopReader.MSG_REPLY, requestId);
85     
86     write_long(IiopReader.STATUS_SYSTEM_EXCEPTION);
87     write_long(0); // service control list
88

89     writeString(exceptionId);
90     write_long(minorStatus);
91     write_long(completionStatus);
92   }
93   
94   /**
95    * Writes the header for a request
96    */

97   public void startReplyUserException(int requestId)
98     throws IOException JavaDoc
99   {
100     _out.start12Message(IiopReader.MSG_REPLY, requestId);
101     
102     write_long(IiopReader.STATUS_USER_EXCEPTION);
103     write_long(0); // service control list
104
}
105
106   /**
107    * Writes a 16-bit char.
108    */

109   public void write_wchar(char v)
110   {
111     _out.write(2);
112     _out.write(v >> 8);
113     _out.write(v);
114   }
115
116   /**
117    * Writes a sequence of 16-bit characters to the output stream.
118    */

119   public void write_wstring(String JavaDoc a)
120   {
121     if (a == null) {
122       write_long(0);
123       return;
124     }
125     
126     int length = a.length();
127     write_long(2 * length);
128     for (int i = 0; i < length; i++)
129       _out.writeShort((int) a.charAt(i));
130   }
131 }
132
Popular Tags