NamingContextExtHelper.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* NamingContextExtHelper.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.CosNaming;
  32. import gnu.CORBA.Minor;
  33. import gnu.CORBA.OrbRestricted;
  34. import org.omg.CORBA.Any;
  35. import org.omg.CORBA.BAD_OPERATION;
  36. import org.omg.CORBA.BAD_PARAM;
  37. import org.omg.CORBA.TypeCode;
  38. import org.omg.CORBA.portable.Delegate;
  39. import org.omg.CORBA.portable.InputStream;
  40. import org.omg.CORBA.portable.ObjectImpl;
  41. import org.omg.CORBA.portable.OutputStream;
  42. /**
  43. * The helper operations for the extended naming context.
  44. *
  45. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  46. */
  47. public abstract class NamingContextExtHelper
  48. {
  49. /**
  50. * The naming context repository id.
  51. */
  52. private static String _id = "IDL:omg.org/CosNaming/NamingContextExt:1.0";
  53. /**
  54. * Extract the naming context from the given {@link Any}.
  55. */
  56. public static NamingContextExt extract(Any a)
  57. {
  58. try
  59. {
  60. return ((NamingContextExtHolder) a.extract_Streamable()).value;
  61. }
  62. catch (ClassCastException ex)
  63. {
  64. BAD_OPERATION bad = new BAD_OPERATION("NamingContextExt expected");
  65. bad.initCause(ex);
  66. bad.minor = Minor.Any;
  67. throw bad;
  68. }
  69. }
  70. /**
  71. * Get the {@link NamingContextExt} repository id.
  72. */
  73. public static String id()
  74. {
  75. return _id;
  76. }
  77. /**
  78. * Insert the naming context into the given {@link Any}
  79. */
  80. public static void insert(Any a, NamingContextExt that)
  81. {
  82. a.insert_Streamable(new NamingContextExtHolder(that));
  83. }
  84. /**
  85. * Cast the passed object into the NamingContextExt. If the
  86. * object has a different java type, create an instance
  87. * of the NamingContextExt, using the same delegate, as for
  88. * the passed parameter. Hence this method may return
  89. * a different object, than has been passed.
  90. *
  91. * @param obj the object to cast.
  92. * @return casted instance.
  93. */
  94. public static NamingContextExt narrow(org.omg.CORBA.Object obj)
  95. {
  96. if (obj == null)
  97. return null;
  98. else if (obj instanceof NamingContextExt)
  99. return (NamingContextExt) obj;
  100. else if (!obj._is_a(id()))
  101. throw new BAD_PARAM();
  102. else
  103. {
  104. Delegate delegate = ((ObjectImpl) obj)._get_delegate();
  105. return new _NamingContextExtStub(delegate);
  106. }
  107. }
  108. /**
  109. * Narrow the given object to the NamingContextExt. No type-checking is
  110. * performed to verify that the object actually supports the requested type.
  111. * The {@link BAD_OPERATION} will be thrown if unsupported operations are
  112. * invoked on the new returned reference, but no failure is expected at the
  113. * time of the unchecked_narrow. See OMG issue 4158.
  114. *
  115. * @param obj the object to cast.
  116. *
  117. * @return the casted NamingContextExt
  118. *
  119. * @since 1.5
  120. */
  121. public static NamingContextExt unchecked_narrow(org.omg.CORBA.Object obj)
  122. {
  123. if (obj == null)
  124. return null;
  125. else if (obj instanceof NamingContextExt)
  126. return (NamingContextExt) obj;
  127. else
  128. {
  129. // Do not call the _is_a(..).
  130. Delegate delegate = ((ObjectImpl) obj)._get_delegate();
  131. return new _NamingContextExtStub(delegate);
  132. }
  133. }
  134. /**
  135. * Read the extended naming context from the given CDR input stream.
  136. */
  137. public static NamingContextExt read(InputStream istream)
  138. {
  139. return narrow(istream.read_Object(_NamingContextExtStub.class));
  140. }
  141. /**
  142. * Get the type code of the {@link NamingContextExt}.
  143. */
  144. public static TypeCode type()
  145. {
  146. return OrbRestricted.Singleton.create_interface_tc(NamingContextExtHelper.id(),
  147. "NamingContextExt");
  148. }
  149. /**
  150. * Write the given extended naming context into the given CDR output stream.
  151. */
  152. public static void write(OutputStream ostream, NamingContextExt value)
  153. {
  154. ostream.write_Object(value);
  155. }
  156. }