001/* DynamicImplementation.java -- 002 Copyright (C) 2005, 2006 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package org.omg.CORBA; 040 041import gnu.CORBA.Unexpected; 042import gnu.CORBA.gnuAny; 043import gnu.CORBA.gnuNVList; 044 045import org.omg.CORBA.portable.ObjectImpl; 046import org.omg.CORBA.portable.OutputStream; 047 048/** 049 * This class was probably originally thinked as a base of all CORBA 050 * object implementations. However the code, generated by IDL to 051 * java compilers almost never use it, preferring to derive the 052 * object implementation bases directly from the {@link ObjectImpl}. 053 * The class has become deprecated since the 1.4 release. 054 * 055 * @deprecated since 1.4. 056 * 057 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) 058 */ 059public class DynamicImplementation 060 extends ObjectImpl 061{ 062 /** 063 * Invoke the method of the CORBA object. After converting the parameters, 064 * this method delegates call to the {@link ObjectImpl#_invoke}. 065 * 066 * @deprecated since 1.4. 067 * 068 * @param request the container for both passing and returing the parameters, 069 * also contains the method name and thrown exceptions. 070 */ 071 public void invoke(ServerRequest request) 072 { 073 Request r = _request(request.operation()); 074 075 // Copy the parameters. 076 NVList args = new gnuNVList(); 077 request.arguments(args); 078 NamedValue v; 079 int i = 0; 080 081 try 082 { 083 // Set the arguments. 084 for (i = 0; i < args.count(); i++) 085 { 086 v = args.item(i); 087 Any n; 088 OutputStream out; 089 090 switch (v.flags()) 091 { 092 case ARG_IN.value: 093 out = v.value().create_output_stream(); 094 v.value().write_value(out); 095 n = r.add_named_in_arg(v.name()); 096 n.read_value(out.create_input_stream(), v.value().type()); 097 break; 098 case ARG_INOUT.value: 099 out = v.value().create_output_stream(); 100 v.value().write_value(out); 101 n = r.add_named_inout_arg(v.name()); 102 n.read_value(out.create_input_stream(), v.value().type()); 103 break; 104 case ARG_OUT.value: 105 r.add_named_out_arg(v.name()); 106 break; 107 108 default: 109 throw new InternalError("Invalid flags " + v.flags()); 110 } 111 } 112 } 113 catch (Bounds b) 114 { 115 throw new Unexpected(args.count() + "[" + i + "]", b); 116 } 117 118 // Set context. 119 r.ctx(request.ctx()); 120 121 // Set the return type (expects that the ServerRequest will initialise 122 // the passed Any. 123 124 gnuAny g = new gnuAny(); 125 request.result(g); 126 r.set_return_type(g.type()); 127 128 // Invoke the method. 129 r.invoke(); 130 131 // Transfer the returned values. 132 NVList r_args = r.arguments(); 133 134 try 135 { 136 // API states that the ServerRequest.arguments must be called only 137 // once. Hence we assume we can just modify the previously returned 138 // value <code>args</code>, and the ServerRequest will preserve the 139 // reference. 140 for (i = 0; i < args.count(); i++) 141 { 142 v = args.item(i); 143 144 if (v.flags() == ARG_OUT.value || v.flags() == ARG_INOUT.value) 145 { 146 OutputStream out = r_args.item(i).value().create_output_stream(); 147 r_args.item(i).value().write_value(out); 148 v.value().read_value(out.create_input_stream(), 149 v.value().type()); 150 } 151 } 152 } 153 catch (Bounds b) 154 { 155 throw new Unexpected(args.count() + "[" + i + "]", b); 156 } 157 158 // Set the returned result (if any). 159 NamedValue returns = r.result(); 160 if (returns != null) 161 request.set_result(returns.value()); 162 } 163 164 /** 165 * Returns the array of the repository ids, supported by this object. 166 * In this implementation, the method must be overrridden to return 167 * a sendible object-specific information. The default method returns 168 * an empty array. 169 * 170 * @deprecated since 1.4. 171 * 172 * @return the empty array, always. 173 */ 174 public String[] _ids() 175 { 176 return new String[ 0 ]; 177 } 178}