1. /*
  2. * @(#)DelegateImpl.java 1.8 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.POA;
  8. import org.omg.PortableServer.*;
  9. public class DelegateImpl implements org.omg.PortableServer.portable.Delegate{
  10. private POAORB _orb;
  11. public DelegateImpl(POAORB orb){
  12. _orb = orb;
  13. }
  14. /* org.omg.PortableServer.portable.Delegate methods. */
  15. //==============================================================================
  16. //==============================================================================
  17. public org.omg.CORBA.ORB orb(Servant self){
  18. return _orb;
  19. }
  20. public org.omg.CORBA.Object this_object(Servant self){
  21. //REVISIT Temporary implementation
  22. byte[] oid;
  23. POAImpl poa;
  24. try{
  25. oid = _orb.poaCurrent.get_object_id();
  26. poa = (POAImpl)_orb.poaCurrent.get_POA();
  27. return poa.createReference(self._all_interfaces(poa,oid)[0],oid);
  28. } catch (org.omg.PortableServer.CurrentPackage.NoContext notInInvocationE) {
  29. //Not within an invocation context
  30. POAImpl defaultPOA = null;
  31. try{
  32. defaultPOA = (POAImpl)self._default_POA();
  33. } catch (ClassCastException exception){
  34. throw new org.omg.CORBA.OBJ_ADAPTER(
  35. "Servant's _default_POA must be an instance of POAImpl.");
  36. }
  37. try{
  38. if ( defaultPOA.getPolicies().isImplicitlyActivated() )
  39. return defaultPOA.servant_to_reference(self);
  40. else if ( defaultPOA.getPolicies().isUniqueIds()
  41. && defaultPOA.getPolicies().retainServants())
  42. return defaultPOA.servant_to_reference(self);
  43. else throw new org.omg.CORBA.OBJ_ADAPTER(
  44. "Don't have the right POA policies for _this_object " +
  45. "called from outside of an invocation thread.");
  46. } catch ( org.omg.PortableServer.POAPackage.ServantNotActive e) {
  47. throw new org.omg.CORBA.OBJ_ADAPTER(
  48. "ServantNotActive: servant_to_reference failed.");
  49. } catch ( org.omg.PortableServer.POAPackage.WrongPolicy e) {
  50. throw new org.omg.CORBA.OBJ_ADAPTER(
  51. "WrongPolicy: servant_to_reference failed.");
  52. }
  53. } catch (ClassCastException e) {
  54. throw new org.omg.CORBA.OBJ_ADAPTER(
  55. "Servant's _default_POA must be an instance of POAImpl.");
  56. }
  57. }
  58. public POA poa(Servant self){
  59. try{
  60. return _orb.poaCurrent.get_POA();
  61. } catch (org.omg.PortableServer.CurrentPackage.NoContext exception){
  62. if (ShutdownUtilDelegate.instance != null) {
  63. POA returnValue = ShutdownUtilDelegate.instance.lookupPOA(self);
  64. if (returnValue != null) {
  65. return returnValue;
  66. }
  67. }
  68. throw new org.omg.CORBA.OBJ_ADAPTER(
  69. "NoContext: outside of an invocation context.");
  70. }
  71. }
  72. public byte[] object_id(Servant self){
  73. try{
  74. return _orb.poaCurrent.get_object_id();
  75. } catch (org.omg.PortableServer.CurrentPackage.NoContext exception){
  76. throw new org.omg.CORBA.OBJ_ADAPTER(
  77. "NoContext: outside of an invocation context.");
  78. }
  79. }
  80. public POA default_POA(Servant self){
  81. return _orb.getRootPOA();
  82. }
  83. public boolean is_a(Servant self, String repId){
  84. String[] repositoryIds = self._all_interfaces(poa(self),object_id(self));
  85. for ( int i=0; i<repositoryIds.length; i++ )
  86. if ( repId.equals(repositoryIds[i]) )
  87. return true;
  88. return false;
  89. }
  90. public boolean non_existent(Servant self){
  91. //REVISIT
  92. try{
  93. byte[] oid = _orb.poaCurrent.get_object_id();
  94. if( oid == null) return true;
  95. else return false;
  96. } catch (org.omg.PortableServer.CurrentPackage.NoContext exception){
  97. throw new org.omg.CORBA.OBJ_ADAPTER(
  98. "NoContext: outside of an invocation context.");
  99. }
  100. }
  101. //REVISIT
  102. //Simon And Ken Will Ask About Editorial Changes
  103. //In Idl To Java For The Following Signature.
  104. /*
  105. public org.omg.CORBA.Object get_interface(Servant Self){
  106. //Not currently implemented.
  107. throw new org.omg.CORBA.NO_IMPLEMENT("This method is not implemented.");
  108. }
  109. */
  110. // The get_interface() method has been replaced by get_interface_def()
  111. public org.omg.CORBA.Object get_interface_def(Servant Self){
  112. //Not currently implemented.
  113. throw new org.omg.CORBA.NO_IMPLEMENT("This method is not implemented.");
  114. }
  115. }