1. /*
  2. * @(#)SpecialMethod.java 1.25 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.protocol ;
  8. import javax.rmi.CORBA.Tie;
  9. import org.omg.CORBA.SystemException ;
  10. import org.omg.CORBA.NO_IMPLEMENT ;
  11. import org.omg.CORBA.OBJECT_NOT_EXIST ;
  12. import org.omg.CORBA.CompletionStatus ;
  13. import org.omg.CORBA.portable.InputStream;
  14. import org.omg.CORBA.portable.OutputStream;
  15. import com.sun.corba.se.spi.oa.ObjectAdapter;
  16. import com.sun.corba.se.spi.orb.ORB;
  17. import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
  18. import com.sun.corba.se.spi.logging.CORBALogDomains;
  19. import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  20. import com.sun.corba.se.spi.oa.NullServant ;
  21. public abstract class SpecialMethod {
  22. public abstract boolean isNonExistentMethod() ;
  23. public abstract String getName();
  24. public abstract CorbaMessageMediator invoke(java.lang.Object servant,
  25. CorbaMessageMediator request,
  26. byte[] objectId,
  27. ObjectAdapter objectAdapter);
  28. public static final SpecialMethod getSpecialMethod(String operation) {
  29. for(int i = 0; i < methods.length; i++)
  30. if (methods[i].getName().equals(operation))
  31. return methods[i];
  32. return null;
  33. }
  34. static SpecialMethod[] methods = {
  35. new IsA(),
  36. new GetInterface(),
  37. new NonExistent(),
  38. new NotExistent()
  39. };
  40. }
  41. class NonExistent extends SpecialMethod {
  42. public boolean isNonExistentMethod()
  43. {
  44. return true ;
  45. }
  46. public String getName() { // _non_existent
  47. return "_non_existent";
  48. }
  49. public CorbaMessageMediator invoke(java.lang.Object servant,
  50. CorbaMessageMediator request,
  51. byte[] objectId,
  52. ObjectAdapter objectAdapter)
  53. {
  54. boolean result = (servant == null) || (servant instanceof NullServant) ;
  55. CorbaMessageMediator response =
  56. request.getProtocolHandler().createResponse(request, null);
  57. ((OutputStream)response.getOutputObject()).write_boolean(result);
  58. return response;
  59. }
  60. }
  61. class NotExistent extends NonExistent {
  62. public String getName() { // _not_existent
  63. return "_not_existent";
  64. }
  65. }
  66. class IsA extends SpecialMethod { // _is_a
  67. public boolean isNonExistentMethod()
  68. {
  69. return false ;
  70. }
  71. public String getName() {
  72. return "_is_a";
  73. }
  74. public CorbaMessageMediator invoke(java.lang.Object servant,
  75. CorbaMessageMediator request,
  76. byte[] objectId,
  77. ObjectAdapter objectAdapter)
  78. {
  79. if ((servant == null) || (servant instanceof NullServant)) {
  80. ORB orb = (ORB)request.getBroker() ;
  81. ORBUtilSystemException wrapper = ORBUtilSystemException.get( orb,
  82. CORBALogDomains.OA_INVOCATION ) ;
  83. return request.getProtocolHandler().createSystemExceptionResponse(
  84. request, wrapper.badSkeleton(), null);
  85. }
  86. String[] ids = objectAdapter.getInterfaces( servant, objectId );
  87. String clientId =
  88. ((InputStream)request.getInputObject()).read_string();
  89. boolean answer = false;
  90. for(int i = 0; i < ids.length; i++)
  91. if (ids[i].equals(clientId)) {
  92. answer = true;
  93. break;
  94. }
  95. CorbaMessageMediator response =
  96. request.getProtocolHandler().createResponse(request, null);
  97. ((OutputStream)response.getOutputObject()).write_boolean(answer);
  98. return response;
  99. }
  100. }
  101. class GetInterface extends SpecialMethod { // _get_interface
  102. public boolean isNonExistentMethod()
  103. {
  104. return false ;
  105. }
  106. public String getName() {
  107. return "_interface";
  108. }
  109. public CorbaMessageMediator invoke(java.lang.Object servant,
  110. CorbaMessageMediator request,
  111. byte[] objectId,
  112. ObjectAdapter objectAdapter)
  113. {
  114. ORB orb = (ORB)request.getBroker() ;
  115. ORBUtilSystemException wrapper = ORBUtilSystemException.get( orb,
  116. CORBALogDomains.OA_INVOCATION ) ;
  117. if ((servant == null) || (servant instanceof NullServant)) {
  118. return request.getProtocolHandler().createSystemExceptionResponse(
  119. request, wrapper.badSkeleton(), null);
  120. } else {
  121. return request.getProtocolHandler().createSystemExceptionResponse(
  122. request, wrapper.getinterfaceNotImplemented(), null);
  123. }
  124. }
  125. }
  126. // End of file.