DynamicImplementation.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* DynamicImplementation.java --
  2. Copyright (C) 2005, 2006 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package org.omg.CORBA;
  32. import gnu.CORBA.Unexpected;
  33. import gnu.CORBA.gnuAny;
  34. import gnu.CORBA.gnuNVList;
  35. import org.omg.CORBA.portable.ObjectImpl;
  36. import org.omg.CORBA.portable.OutputStream;
  37. /**
  38. * This class was probably originally thinked as a base of all CORBA
  39. * object implementations. However the code, generated by IDL to
  40. * java compilers almost never use it, preferring to derive the
  41. * object implementation bases directly from the {@link ObjectImpl}.
  42. * The class has become deprecated since the 1.4 release.
  43. *
  44. * @deprecated since 1.4.
  45. *
  46. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  47. */
  48. public class DynamicImplementation
  49. extends ObjectImpl
  50. {
  51. /**
  52. * Invoke the method of the CORBA object. After converting the parameters,
  53. * this method delegates call to the {@link ObjectImpl#_invoke}.
  54. *
  55. * @deprecated since 1.4.
  56. *
  57. * @param request the container for both passing and returing the parameters,
  58. * also contains the method name and thrown exceptions.
  59. */
  60. public void invoke(ServerRequest request)
  61. {
  62. Request r = _request(request.operation());
  63. // Copy the parameters.
  64. NVList args = new gnuNVList();
  65. request.arguments(args);
  66. NamedValue v;
  67. int i = 0;
  68. try
  69. {
  70. // Set the arguments.
  71. for (i = 0; i < args.count(); i++)
  72. {
  73. v = args.item(i);
  74. Any n;
  75. OutputStream out;
  76. switch (v.flags())
  77. {
  78. case ARG_IN.value:
  79. out = v.value().create_output_stream();
  80. v.value().write_value(out);
  81. n = r.add_named_in_arg(v.name());
  82. n.read_value(out.create_input_stream(), v.value().type());
  83. break;
  84. case ARG_INOUT.value:
  85. out = v.value().create_output_stream();
  86. v.value().write_value(out);
  87. n = r.add_named_inout_arg(v.name());
  88. n.read_value(out.create_input_stream(), v.value().type());
  89. break;
  90. case ARG_OUT.value:
  91. r.add_named_out_arg(v.name());
  92. break;
  93. default:
  94. throw new InternalError("Invalid flags " + v.flags());
  95. }
  96. }
  97. }
  98. catch (Bounds b)
  99. {
  100. throw new Unexpected(args.count() + "[" + i + "]", b);
  101. }
  102. // Set context.
  103. r.ctx(request.ctx());
  104. // Set the return type (expects that the ServerRequest will initialise
  105. // the passed Any.
  106. gnuAny g = new gnuAny();
  107. request.result(g);
  108. r.set_return_type(g.type());
  109. // Invoke the method.
  110. r.invoke();
  111. // Transfer the returned values.
  112. NVList r_args = r.arguments();
  113. try
  114. {
  115. // API states that the ServerRequest.arguments must be called only
  116. // once. Hence we assume we can just modify the previously returned
  117. // value <code>args</code>, and the ServerRequest will preserve the
  118. // reference.
  119. for (i = 0; i < args.count(); i++)
  120. {
  121. v = args.item(i);
  122. if (v.flags() == ARG_OUT.value || v.flags() == ARG_INOUT.value)
  123. {
  124. OutputStream out = r_args.item(i).value().create_output_stream();
  125. r_args.item(i).value().write_value(out);
  126. v.value().read_value(out.create_input_stream(),
  127. v.value().type());
  128. }
  129. }
  130. }
  131. catch (Bounds b)
  132. {
  133. throw new Unexpected(args.count() + "[" + i + "]", b);
  134. }
  135. // Set the returned result (if any).
  136. NamedValue returns = r.result();
  137. if (returns != null)
  138. request.set_result(returns.value());
  139. }
  140. /**
  141. * Returns the array of the repository ids, supported by this object.
  142. * In this implementation, the method must be overrridden to return
  143. * a sendible object-specific information. The default method returns
  144. * an empty array.
  145. *
  146. * @deprecated since 1.4.
  147. *
  148. * @return the empty array, always.
  149. */
  150. public String[] _ids()
  151. {
  152. return new String[ 0 ];
  153. }
  154. }