1. /*
  2. * @(#)SpecialMethod.java 1.23 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.corba;
  8. import javax.rmi.CORBA.Tie;
  9. import org.omg.CORBA.*;
  10. import org.omg.CORBA.portable.*;
  11. import com.sun.corba.se.internal.core.ServerRequest;
  12. import com.sun.corba.se.internal.core.ServerResponse;
  13. import com.sun.corba.se.internal.orbutil.MinorCodes;
  14. public abstract class SpecialMethod {
  15. public abstract String getName();
  16. public abstract ServerResponse invoke(java.lang.Object servant,
  17. ServerRequest request);
  18. public static final SpecialMethod getSpecialMethod(String operation) {
  19. for(int i = 0; i < methods.length; i++)
  20. if (methods[i].getName().equals(operation))
  21. return methods[i];
  22. return null;
  23. }
  24. public static final boolean isSpecialMethod(String operation) {
  25. for(int i = 0; i < methods.length; i++)
  26. if (methods[i].getName().equals(operation))
  27. return true;
  28. return false;
  29. }
  30. static SpecialMethod[] methods = {
  31. new IsA(),
  32. new GetInterface(),
  33. new NonExistent(),
  34. new NotExistent()
  35. };
  36. }
  37. class NonExistent extends SpecialMethod {
  38. public String getName() { // _non_existent
  39. return "_non_existent";
  40. }
  41. public ServerResponse invoke(java.lang.Object servant,
  42. ServerRequest request)
  43. {
  44. boolean result = (servant == null) ? true : false;
  45. ServerResponse response = request.createResponse(null);
  46. response.write_boolean(result);
  47. return response;
  48. }
  49. }
  50. class NotExistent extends NonExistent {
  51. public String getName() { // _not_existent
  52. return "_not_existent";
  53. }
  54. }
  55. class IsA extends SpecialMethod { // _is_a
  56. public String getName() {
  57. return "_is_a";
  58. }
  59. public ServerResponse invoke(java.lang.Object servant,
  60. ServerRequest request)
  61. {
  62. if (servant == null) {
  63. SystemException ex
  64. = new OBJECT_NOT_EXIST(MinorCodes.BAD_SKELETON,
  65. CompletionStatus.COMPLETED_NO);
  66. return
  67. request.createSystemExceptionResponse(ex, null);
  68. }
  69. String[] ids = ((ObjectImpl) servant)._ids();
  70. String clientId = request.read_string();
  71. boolean answer = false;
  72. for(int i = 0; i < ids.length; i++)
  73. if (ids[i].equals(clientId)) {
  74. answer = true;
  75. break;
  76. }
  77. ServerResponse response = request.createResponse(null);
  78. response.write_boolean(answer);
  79. return response;
  80. }
  81. }
  82. class GetInterface extends SpecialMethod { // _get_interface
  83. public String getName() {
  84. return "_interface";
  85. }
  86. public ServerResponse invoke(java.lang.Object servant,
  87. ServerRequest request)
  88. {
  89. if (servant == null) {
  90. SystemException ex = new OBJECT_NOT_EXIST(MinorCodes.BAD_SKELETON,
  91. CompletionStatus.COMPLETED_NO);
  92. return request.createSystemExceptionResponse(ex, null);
  93. }
  94. SystemException ex = new NO_IMPLEMENT(MinorCodes.GETINTERFACE_NOT_IMPLEMENTED,
  95. CompletionStatus.COMPLETED_NO);
  96. return request.createSystemExceptionResponse(ex, null);
  97. }
  98. }