1. /*
  2. * @(#)POACurrent.java 1.17 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.oa.poa;
  8. import java.util.*;
  9. import org.omg.CORBA.CompletionStatus;
  10. import org.omg.PortableServer.CurrentPackage.NoContext;
  11. import org.omg.PortableServer.POA;
  12. import org.omg.PortableServer.Servant;
  13. import org.omg.PortableServer.ServantLocatorPackage.CookieHolder;
  14. import com.sun.corba.se.spi.oa.OAInvocationInfo ;
  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.logging.CORBALogDomains ;
  18. import com.sun.corba.se.impl.logging.POASystemException ;
  19. // XXX Needs to be turned into LocalObjectImpl.
  20. public class POACurrent extends org.omg.CORBA.portable.ObjectImpl
  21. implements org.omg.PortableServer.Current
  22. {
  23. private ORB orb;
  24. private POASystemException wrapper ;
  25. public POACurrent(ORB orb)
  26. {
  27. this.orb = orb;
  28. wrapper = POASystemException.get( orb,
  29. CORBALogDomains.OA_INVOCATION ) ;
  30. }
  31. public String[] _ids()
  32. {
  33. String[] ids = new String[1];
  34. ids[0] = "IDL:omg.org/PortableServer/Current:1.0";
  35. return ids;
  36. }
  37. //
  38. // Standard OMG operations.
  39. //
  40. public POA get_POA()
  41. throws
  42. NoContext
  43. {
  44. POA poa = (POA)(peekThrowNoContext().oa());
  45. throwNoContextIfNull(poa);
  46. return poa;
  47. }
  48. public byte[] get_object_id()
  49. throws
  50. NoContext
  51. {
  52. byte[] objectid = peekThrowNoContext().id();
  53. throwNoContextIfNull(objectid);
  54. return objectid;
  55. }
  56. //
  57. // Implementation operations used by POA package.
  58. //
  59. public ObjectAdapter getOA()
  60. {
  61. ObjectAdapter oa = peekThrowInternal().oa();
  62. throwInternalIfNull(oa);
  63. return oa;
  64. }
  65. public byte[] getObjectId()
  66. {
  67. byte[] objectid = peekThrowInternal().id();
  68. throwInternalIfNull(objectid);
  69. return objectid;
  70. }
  71. Servant getServant()
  72. {
  73. Servant servant = (Servant)(peekThrowInternal().getServantContainer());
  74. // If is OK for the servant to be null.
  75. // This could happen if POAImpl.getServant is called but
  76. // POAImpl.internalGetServant throws an exception.
  77. return servant;
  78. }
  79. CookieHolder getCookieHolder()
  80. {
  81. CookieHolder cookieHolder = peekThrowInternal().getCookieHolder();
  82. throwInternalIfNull(cookieHolder);
  83. return cookieHolder;
  84. }
  85. // This is public so we can test the stack balance.
  86. // It is not a security hole since this same info can be obtained from
  87. // PortableInterceptors.
  88. public String getOperation()
  89. {
  90. String operation = peekThrowInternal().getOperation();
  91. throwInternalIfNull(operation);
  92. return operation;
  93. }
  94. void setServant(Servant servant)
  95. {
  96. peekThrowInternal().setServant( servant );
  97. }
  98. //
  99. // Class utilities.
  100. //
  101. private OAInvocationInfo peekThrowNoContext()
  102. throws
  103. NoContext
  104. {
  105. OAInvocationInfo invocationInfo = null;
  106. try {
  107. invocationInfo = orb.peekInvocationInfo() ;
  108. } catch (EmptyStackException e) {
  109. throw new NoContext();
  110. }
  111. return invocationInfo;
  112. }
  113. private OAInvocationInfo peekThrowInternal()
  114. {
  115. OAInvocationInfo invocationInfo = null;
  116. try {
  117. invocationInfo = orb.peekInvocationInfo() ;
  118. } catch (EmptyStackException e) {
  119. // The completion status is maybe because this could happen
  120. // after the servant has been invoked.
  121. throw wrapper.poacurrentUnbalancedStack( e ) ;
  122. }
  123. return invocationInfo;
  124. }
  125. private void throwNoContextIfNull(Object o)
  126. throws
  127. NoContext
  128. {
  129. if ( o == null ) {
  130. throw new NoContext();
  131. }
  132. }
  133. private void throwInternalIfNull(Object o)
  134. {
  135. if ( o == null ) {
  136. throw wrapper.poacurrentNullField( CompletionStatus.COMPLETED_MAYBE ) ;
  137. }
  138. }
  139. }