1. /*
  2. * @(#)SpecialMethod.java 1.20 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.POA;
  8. import org.omg.CORBA.*;
  9. import org.omg.CORBA.portable.*;
  10. import org.omg.PortableServer.Servant ;
  11. import com.sun.corba.se.internal.core.*;
  12. import com.sun.corba.se.internal.POA.MinorCodes;
  13. abstract class SpecialMethod {
  14. abstract String getName();
  15. abstract ServerResponse invoke(Servant servant,
  16. com.sun.corba.se.internal.core.ServerRequest req);
  17. static final SpecialMethod getSpecialMethod(String operation) {
  18. for(int i = 0; i < methods.length; i++)
  19. if (methods[i].getName().equals(operation))
  20. return methods[i];
  21. return null;
  22. }
  23. static final boolean isSpecialMethod(String operation) {
  24. for(int i = 0; i < methods.length; i++)
  25. if (methods[i].getName().equals(operation))
  26. return true;
  27. return false;
  28. }
  29. static SpecialMethod[] methods = {
  30. new IsA(),
  31. new GetInterface(),
  32. new NonExistent(),
  33. new NotExistent()
  34. };
  35. }
  36. class NonExistent extends SpecialMethod {
  37. String getName() { // _non_existent
  38. return "_non_existent";
  39. }
  40. ServerResponse invoke(Servant servant,
  41. com.sun.corba.se.internal.core.ServerRequest req) {
  42. boolean result = (servant == null) ? true : false;
  43. ServerResponse resp = req.createResponse(null);
  44. OutputStream os = (OutputStream)resp;
  45. os.write_boolean(result);
  46. return resp;
  47. }
  48. }
  49. class NotExistent extends NonExistent {
  50. public String getName() { // _not_existent
  51. return "_not_existent";
  52. }
  53. }
  54. class IsA extends SpecialMethod { // _is_a
  55. String getName() {
  56. return "_is_a";
  57. }
  58. ServerResponse invoke(Servant servant,
  59. com.sun.corba.se.internal.core.ServerRequest req) {
  60. if (servant == null)
  61. POAImpl.objectNotExist(MinorCodes.NULL_SERVANT,
  62. CompletionStatus.COMPLETED_NO);
  63. String[] ids =
  64. servant._all_interfaces(servant._poa(),servant._object_id());
  65. String clientId = ((InputStream)req).read_string();
  66. boolean answer = false;
  67. for(int i = 0; i < ids.length; i++)
  68. if (ids[i].equals(clientId)) {
  69. answer = true;
  70. }
  71. ServerResponse resp = req.createResponse(null);
  72. OutputStream os = (OutputStream)resp;
  73. os.write_boolean(answer);
  74. return resp;
  75. }
  76. }
  77. class GetInterface extends SpecialMethod { // _get_interface
  78. String getName() {
  79. return "_interface";
  80. }
  81. ServerResponse invoke(Servant servant,
  82. com.sun.corba.se.internal.core.ServerRequest req) {
  83. if (servant == null)
  84. POAImpl.objectNotExist(MinorCodes.NULL_SERVANT,
  85. CompletionStatus.COMPLETED_NO);
  86. throw new
  87. NO_IMPLEMENT(com.sun.corba.se.internal.orbutil.MinorCodes.GETINTERFACE_NOT_IMPLEMENTED,
  88. CompletionStatus.COMPLETED_NO);
  89. }
  90. }