DynAnyFactoryHelper.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* DynAnyFactoryHelper.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.DynamicAny;
  32. import gnu.CORBA.Minor;
  33. import gnu.CORBA.OrbRestricted;
  34. import org.omg.CORBA.BAD_OPERATION;
  35. import org.omg.CORBA.BAD_PARAM;
  36. import org.omg.CORBA.TypeCode;
  37. import org.omg.CORBA.Any;
  38. import org.omg.CORBA.portable.InputStream;
  39. import org.omg.CORBA.MARSHAL;
  40. import org.omg.CORBA.portable.OutputStream;
  41. /**
  42. * The helper operations for {@link DynAnyFactory}. Following the 1.5 JDK
  43. * specifications, DynAnyFactory is always a local object, so the two methods of
  44. * this helper ({@link #read} and {@link #write} are not in use, always
  45. * throwing {@link MARSHAL}.
  46. *
  47. * @specnote always throwing MARSHAL in read and write ensures compatibility
  48. * with other popular implementations like Sun's.
  49. *
  50. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  51. */
  52. public abstract class DynAnyFactoryHelper
  53. {
  54. /**
  55. * Cast the passed object into the DynAnyFactory. As DynAnyFactory is a local
  56. * object, the method just uses java final_type cast.
  57. *
  58. * @param obj the object to narrow.
  59. * @return narrowed instance.
  60. * @throws BAD_PARAM if the passed object is not a DynAnyFactory.
  61. */
  62. public static DynAnyFactory narrow(org.omg.CORBA.Object obj)
  63. {
  64. try
  65. {
  66. return (DynAnyFactory) obj;
  67. }
  68. catch (ClassCastException cex)
  69. {
  70. throw new BAD_PARAM(obj.getClass().getName()
  71. + " is not a DynAnyFactory");
  72. }
  73. }
  74. /**
  75. * Narrow the given object to the DynAnyFactory. For the objects that are
  76. * always local, this operation does not differ from the ordinary
  77. * {@link #narrow} (ClassCastException will be thrown if narrowing something
  78. * different). See also OMG issue 4158.
  79. *
  80. * @param obj the object to cast.
  81. *
  82. * @return the casted DynAnyFactory.
  83. *
  84. * @since 1.5
  85. */
  86. public static DynAnyFactory unchecked_narrow(org.omg.CORBA.Object obj)
  87. {
  88. return narrow(obj);
  89. }
  90. /**
  91. * Get the final_type code of the {@link DynAnyFactory}.
  92. */
  93. public static TypeCode type()
  94. {
  95. return OrbRestricted.Singleton.create_interface_tc(id(), "DynAnyFactory");
  96. }
  97. /**
  98. * Insert the DynAnyFactory into the given Any.
  99. *
  100. * @param any the Any to insert into.
  101. *
  102. * @param that the DynAnyFactory to insert.
  103. */
  104. public static void insert(Any any, DynAnyFactory that)
  105. {
  106. any.insert_Object(that);
  107. }
  108. /**
  109. * Extract the DynAnyFactory from given Any.
  110. *
  111. * @throws BAD_OPERATION if the passed Any does not contain DynAnyFactory.
  112. */
  113. public static DynAnyFactory extract(Any any)
  114. {
  115. return narrow(any.extract_Object());
  116. }
  117. /**
  118. * Get the DynAnyFactory repository id.
  119. *
  120. * @return "IDL:omg.org/DynamicAny/DynAnyFactory:1.0", always.
  121. */
  122. public static String id()
  123. {
  124. return "IDL:omg.org/DynamicAny/DynAnyFactory:1.0";
  125. }
  126. /**
  127. * This should read DynAnyFactory from the CDR input stream, but (following
  128. * the JDK 1.5 API) it does not. The factory can only be obtained from the
  129. * ORB.
  130. *
  131. * @param input a org.omg.CORBA.portable stream to read from.
  132. *
  133. * @specenote Sun throws the same exception.
  134. *
  135. * @throws MARSHAL always.
  136. */
  137. public static DynAnyFactory read(InputStream input)
  138. {
  139. throw new MARSHAL(not_applicable(id()));
  140. }
  141. /**
  142. * This should read DynAnyFactory from the CDR input stream, but (following
  143. * the JDK 1.5 API) it does not.
  144. *
  145. * @param output a org.omg.CORBA.portable stream to write into.
  146. *
  147. * @specenote Sun throws the same exception.
  148. *
  149. * @throws MARSHAL always.
  150. */
  151. public static void write(OutputStream output, DynAnyFactory value)
  152. {
  153. throw new MARSHAL(not_applicable(id()));
  154. }
  155. /**
  156. * The package level method for throwing exception, explaining that the
  157. * operation is not applicable.
  158. *
  159. * @param Id the Id for the typecode for that the operations was attempted to
  160. * perform.
  161. */
  162. static String not_applicable(String Id)
  163. {
  164. MARSHAL m = new MARSHAL("The read/write are not applicable for " + Id);
  165. m.minor = Minor.Inappropriate;
  166. throw m;
  167. }
  168. }