1 /* ServiceRequestConverter.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)
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
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
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. */
41 import gnu.CORBA.CDR.cdrBufOutput;
43 import org.omg.CORBA.ARG_IN;
44 import org.omg.CORBA.ARG_INOUT;
45 import org.omg.CORBA.ARG_OUT;
46 import org.omg.CORBA.Any;
47 import org.omg.CORBA.Bounds;
48 import org.omg.CORBA.ServerRequest;
49 import org.omg.CORBA.portable.InputStream;
50 import org.omg.CORBA.portable.InvokeHandler;
51 import org.omg.CORBA.portable.OutputStream;
52 import org.omg.CORBA.portable.ResponseHandler;
53 import org.omg.CORBA.portable.Streamable;
56 * This class exists to handle obsolete invocation style using
59 * @deprecated The method {@link ObjectImpl#_invoke} is much faster.
61 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
63 public class ServiceRequestAdapter
64 implements ResponseHandler
67 * A buffer for writing the response.
69 cdrBufOutput reply = new cdrBufOutput();
72 * If set to true, an exception has been thrown during the invocation.
76 public OutputStream createExceptionReply()
82 public OutputStream createReply()
89 * The old style invocation using the currently deprecated server
92 * @param request a server request, containg the invocation information.
93 * @param target the invocation target
94 * @param result the result holder with the set suitable streamable to read
95 * the result or null for void.
97 public static void invoke(ServerRequest request, InvokeHandler target,
103 int IN = ARG_IN.value;
104 int OUT = ARG_OUT.value;
106 // Write all arguments to the buffer output stream.
107 cdrBufOutput buffer = new cdrBufOutput();
108 gnuNVList args = new gnuNVList();
109 request.arguments(args);
111 for (int i = 0; i < args.count(); i++)
113 if ((args.item(i).flags() & IN) != 0)
115 args.item(i).value().write_value(buffer);
119 ServiceRequestAdapter h = new ServiceRequestAdapter();
121 target._invoke(request.operation(), buffer.create_input_stream(), h);
123 InputStream in = h.reply.create_input_stream();
127 // Write the exception information
128 gnuAny exc = new gnuAny();
129 universalHolder uku = new universalHolder(h.reply);
130 exc.insert_Streamable(uku);
131 request.set_exception(exc);
138 gnuAny r = new gnuAny();
139 r.insert_Streamable(result);
140 request.set_result(r);
143 // Unpack the arguments
144 for (int i = 0; i < args.count(); i++)
146 if ((args.item(i).flags() & OUT) != 0)
148 Any a = args.item(i).value();
149 a.read_value(in, a.type());
156 throw new InternalError();