_PolicyImplBase.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* _PolicyImplBase.java --
  2. Copyright (C) 2005 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 gnu.CORBA;
  32. import org.omg.CORBA.BAD_OPERATION;
  33. import org.omg.CORBA.CompletionStatus;
  34. import org.omg.CORBA.Policy;
  35. import org.omg.CORBA.PolicyHelper;
  36. import org.omg.CORBA.portable.InputStream;
  37. import org.omg.CORBA.portable.InvokeHandler;
  38. import org.omg.CORBA.portable.ObjectImpl;
  39. import org.omg.CORBA.portable.OutputStream;
  40. import org.omg.CORBA.portable.ResponseHandler;
  41. /**
  42. * The server side implementation base for the {@link Policy}.
  43. *
  44. * @specnote The java 1.4 API does not define the server side policy
  45. * implementation base, but it defines the policy client side stub.
  46. * As these two classes always work together, and even no separate testing is
  47. * possible, the required implementation base is provided in gnu.CORBA
  48. * namespace. Sun will probably include they base in the future java APIs.
  49. *
  50. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  51. */
  52. public abstract class _PolicyImplBase
  53. extends ObjectImpl
  54. implements Policy, InvokeHandler
  55. {
  56. /**
  57. * Use serialVersionUID for interoperability.
  58. */
  59. private static final long serialVersionUID = 1;
  60. /**
  61. * The policy repository ids.
  62. */
  63. private final String[] ids;
  64. /**
  65. * The type of this policy.
  66. */
  67. private final int type;
  68. /**
  69. * The value of this policy. The value object is never the same
  70. * for different policies.
  71. */
  72. private final java.lang.Object value;
  73. /**
  74. * The policy integer code, written in request to write
  75. * the policy value.
  76. */
  77. private final int policyCode;
  78. /**
  79. * Create the new policy of the given type, having the given value.
  80. * For security reasons, the method is kept package private.
  81. *
  82. * @param p_type the type of this policy.
  83. * @param p_value the value of this policy.
  84. * @param p_code the integer code of this policy.
  85. * @param p_idl the policy IDL type string. The {@link #_ids()}
  86. * will return array, first line being this string and another
  87. * being PolicyHelper.id().
  88. */
  89. public _PolicyImplBase(int p_type, java.lang.Object p_value, int p_code,
  90. String p_idl
  91. )
  92. {
  93. type = p_type;
  94. value = p_value;
  95. policyCode = p_code;
  96. ids = new String[] { p_idl, PolicyHelper.id() };
  97. }
  98. /**
  99. * Get the integer code of the type of this policy.
  100. */
  101. public final int policy_type()
  102. {
  103. return type;
  104. }
  105. /**
  106. * Return the list of repository ids.
  107. */
  108. public final String[] _ids()
  109. {
  110. return ids;
  111. }
  112. /**
  113. * Call the required method.
  114. */
  115. public final OutputStream _invoke(String method, InputStream input,
  116. ResponseHandler rh
  117. )
  118. {
  119. OutputStream output = null;
  120. if (method.equals("destroy"))
  121. {
  122. // The "destroy" has been invoked.
  123. destroy();
  124. output = rh.createReply();
  125. }
  126. else if (method.equals("copy"))
  127. {
  128. // The "copy" has been invoked.
  129. org.omg.CORBA.Object returns = copy();
  130. output = rh.createReply();
  131. output.write_Object(this);
  132. }
  133. else if (method.equals("policy_type"))
  134. {
  135. // The "policy_type" has been invoked.
  136. int returns = policy_type();
  137. output = rh.createReply();
  138. output.write_long(returns);
  139. }
  140. else if (method.equals("value"))
  141. {
  142. // The "value" can be invoked on the children types
  143. // and must return an integer, representing the policy value
  144. // (CORBA enumeration).
  145. output = rh.createReply();
  146. output.write_long(policyCode);
  147. }
  148. else
  149. throw new BAD_OPERATION(method, Minor.Method,
  150. CompletionStatus.COMPLETED_MAYBE);
  151. return output;
  152. }
  153. /**
  154. * Get the value of this policy
  155. */
  156. public final java.lang.Object getValue()
  157. {
  158. return value;
  159. }
  160. /**
  161. * Get the integer code of this policy value.
  162. */
  163. public final int getCode()
  164. {
  165. return policyCode;
  166. }
  167. /**
  168. * Returns without action. It is a work of garbage collector
  169. * to remove the unused objects.
  170. */
  171. public final void destroy()
  172. {
  173. }
  174. /**
  175. * Returns the string representation of the given policy.
  176. */
  177. public final String toString()
  178. {
  179. return value.toString();
  180. }
  181. /**
  182. * Create a copy of this policy. The object is not mutable, so
  183. * <code>this</code> can be returned.
  184. *
  185. * @return <code>this</code>
  186. */
  187. public Policy copy()
  188. {
  189. return this;
  190. }
  191. /**
  192. * Use the value to get a hash code.
  193. */
  194. public int hashCode()
  195. {
  196. return getValue().hashCode();
  197. }
  198. /**
  199. * Check the values for equality.
  200. */
  201. public boolean equals(Object x)
  202. {
  203. return x == null ? false : getValue().equals(x);
  204. }
  205. }