1. /*
  2. * @(#)POAPolicyMediatorImpl_NR_USM.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.oa.poa ;
  8. import java.util.Enumeration ;
  9. import org.omg.PortableServer.POA ;
  10. import org.omg.PortableServer.Servant ;
  11. import org.omg.PortableServer.ServantManager ;
  12. import org.omg.PortableServer.ServantLocator ;
  13. import org.omg.PortableServer.ForwardRequest ;
  14. import org.omg.PortableServer.POAPackage.NoServant ;
  15. import org.omg.PortableServer.POAPackage.WrongPolicy ;
  16. import org.omg.PortableServer.POAPackage.ObjectNotActive ;
  17. import org.omg.PortableServer.POAPackage.ServantNotActive ;
  18. import org.omg.PortableServer.POAPackage.ObjectAlreadyActive ;
  19. import org.omg.PortableServer.POAPackage.ServantAlreadyActive ;
  20. import org.omg.PortableServer.ServantLocatorPackage.CookieHolder ;
  21. import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ;
  22. import com.sun.corba.se.impl.orbutil.ORBUtility ;
  23. import com.sun.corba.se.impl.orbutil.ORBConstants ;
  24. import com.sun.corba.se.spi.oa.OAInvocationInfo ;
  25. import com.sun.corba.se.impl.oa.NullServantImpl ;
  26. /** Implementation of POARequesHandler that provides policy specific
  27. * operations on the POA.
  28. */
  29. public class POAPolicyMediatorImpl_NR_USM extends POAPolicyMediatorBase {
  30. private ServantLocator locator ;
  31. POAPolicyMediatorImpl_NR_USM( Policies policies, POAImpl poa )
  32. {
  33. super( policies, poa ) ;
  34. // assert !policies.retainServants() && policies.useServantManager()
  35. if (policies.retainServants())
  36. throw poa.invocationWrapper().policyMediatorBadPolicyInFactory() ;
  37. if (!policies.useServantManager())
  38. throw poa.invocationWrapper().policyMediatorBadPolicyInFactory() ;
  39. locator = null ;
  40. }
  41. protected java.lang.Object internalGetServant( byte[] id,
  42. String operation ) throws ForwardRequest
  43. {
  44. if (locator == null)
  45. throw poa.invocationWrapper().poaNoServantManager() ;
  46. CookieHolder cookieHolder = orb.peekInvocationInfo().getCookieHolder() ;
  47. // Try - finally is J2EE requirement.
  48. java.lang.Object servant;
  49. try{
  50. poa.unlock() ;
  51. servant = locator.preinvoke(id, poa, operation, cookieHolder);
  52. if (servant == null)
  53. servant = new NullServantImpl( poa.omgInvocationWrapper().nullServantReturned() ) ;
  54. else
  55. setDelegate( (Servant)servant, id);
  56. } finally {
  57. poa.lock() ;
  58. }
  59. return servant;
  60. }
  61. public void returnServant()
  62. {
  63. OAInvocationInfo info = orb.peekInvocationInfo();
  64. if (locator == null)
  65. return;
  66. try {
  67. poa.unlock() ;
  68. locator.postinvoke(info.id(), (POA)(info.oa()),
  69. info.getOperation(), info.getCookieHolder().value,
  70. (Servant)(info.getServantContainer()) );
  71. } finally {
  72. poa.lock() ;
  73. }
  74. }
  75. public void etherealizeAll()
  76. {
  77. // NO-OP
  78. }
  79. public void clearAOM()
  80. {
  81. // NO-OP
  82. }
  83. public ServantManager getServantManager() throws WrongPolicy
  84. {
  85. return locator ;
  86. }
  87. public void setServantManager( ServantManager servantManager ) throws WrongPolicy
  88. {
  89. if (locator != null)
  90. throw poa.invocationWrapper().servantManagerAlreadySet() ;
  91. if (servantManager instanceof ServantLocator)
  92. locator = (ServantLocator)servantManager;
  93. else
  94. throw poa.invocationWrapper().servantManagerBadType() ;
  95. }
  96. public Servant getDefaultServant() throws NoServant, WrongPolicy
  97. {
  98. throw new WrongPolicy();
  99. }
  100. public void setDefaultServant( Servant servant ) throws WrongPolicy
  101. {
  102. throw new WrongPolicy();
  103. }
  104. public final void activateObject(byte[] id, Servant servant)
  105. throws WrongPolicy, ServantAlreadyActive, ObjectAlreadyActive
  106. {
  107. throw new WrongPolicy();
  108. }
  109. public Servant deactivateObject( byte[] id ) throws ObjectNotActive, WrongPolicy
  110. {
  111. throw new WrongPolicy();
  112. }
  113. public byte[] servantToId( Servant servant ) throws ServantNotActive, WrongPolicy
  114. {
  115. throw new WrongPolicy();
  116. }
  117. public Servant idToServant( byte[] id )
  118. throws WrongPolicy, ObjectNotActive
  119. {
  120. throw new WrongPolicy();
  121. }
  122. }