1. /*
  2. * @(#)POAPolicyMediatorImpl_R_UDS.java 1.23 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.Servant ;
  10. import org.omg.PortableServer.ServantManager ;
  11. import org.omg.PortableServer.ForwardRequest ;
  12. import org.omg.PortableServer.POAPackage.WrongPolicy ;
  13. import org.omg.PortableServer.POAPackage.ObjectNotActive ;
  14. import org.omg.PortableServer.POAPackage.ServantNotActive ;
  15. import org.omg.PortableServer.POAPackage.ObjectAlreadyActive ;
  16. import org.omg.PortableServer.POAPackage.ServantAlreadyActive ;
  17. import org.omg.PortableServer.POAPackage.NoServant ;
  18. import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ;
  19. import com.sun.corba.se.impl.orbutil.ORBUtility ;
  20. import com.sun.corba.se.impl.orbutil.ORBConstants ;
  21. /** Implementation of POARequesHandler that provides policy specific
  22. * operations on the POA.
  23. */
  24. public class POAPolicyMediatorImpl_R_UDS extends POAPolicyMediatorBase_R {
  25. private Servant defaultServant ;
  26. POAPolicyMediatorImpl_R_UDS( Policies policies, POAImpl poa )
  27. {
  28. // assert policies.retainServants()
  29. super( policies, poa ) ;
  30. defaultServant = null ;
  31. // policies.useDefaultServant()
  32. if (!policies.useDefaultServant())
  33. throw poa.invocationWrapper().policyMediatorBadPolicyInFactory() ;
  34. }
  35. protected java.lang.Object internalGetServant( byte[] id,
  36. String operation ) throws ForwardRequest
  37. {
  38. Servant servant = internalIdToServant( id ) ;
  39. if (servant == null)
  40. servant = defaultServant ;
  41. if (servant == null)
  42. throw poa.invocationWrapper().poaNoDefaultServant() ;
  43. return servant ;
  44. }
  45. public void etherealizeAll()
  46. {
  47. // NO-OP
  48. }
  49. public ServantManager getServantManager() throws WrongPolicy
  50. {
  51. throw new WrongPolicy();
  52. }
  53. public void setServantManager( ServantManager servantManager ) throws WrongPolicy
  54. {
  55. throw new WrongPolicy();
  56. }
  57. public Servant getDefaultServant() throws NoServant, WrongPolicy
  58. {
  59. if (defaultServant == null)
  60. throw new NoServant();
  61. else
  62. return defaultServant;
  63. }
  64. public void setDefaultServant( Servant servant ) throws WrongPolicy
  65. {
  66. defaultServant = servant;
  67. setDelegate(defaultServant, "DefaultServant".getBytes());
  68. }
  69. public Servant idToServant( byte[] id )
  70. throws WrongPolicy, ObjectNotActive
  71. {
  72. ActiveObjectMap.Key key = new ActiveObjectMap.Key( id ) ;
  73. Servant s = internalKeyToServant(key);
  74. if (s == null)
  75. if (defaultServant != null)
  76. s = defaultServant;
  77. if (s == null)
  78. throw new ObjectNotActive() ;
  79. return s;
  80. }
  81. }