1. /*
  2. * @(#)DelegateImpl.java 1.12 04/06/21
  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.EmptyStackException;
  9. import org.omg.PortableServer.*;
  10. import com.sun.corba.se.spi.orb.ORB ;
  11. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  12. import com.sun.corba.se.impl.logging.POASystemException ;
  13. public class DelegateImpl implements org.omg.PortableServer.portable.Delegate
  14. {
  15. private ORB orb ;
  16. private POASystemException wrapper ;
  17. private POAFactory factory;
  18. public DelegateImpl(ORB orb, POAFactory factory){
  19. this.orb = orb ;
  20. this.wrapper = POASystemException.get( orb,
  21. CORBALogDomains.OA ) ;
  22. this.factory = factory;
  23. }
  24. public org.omg.CORBA.ORB orb(Servant self)
  25. {
  26. return orb;
  27. }
  28. public org.omg.CORBA.Object this_object(Servant self)
  29. {
  30. byte[] oid;
  31. POA poa;
  32. try {
  33. oid = orb.peekInvocationInfo().id();
  34. poa = (POA)orb.peekInvocationInfo().oa();
  35. String repId = self._all_interfaces(poa,oid)[0] ;
  36. return poa.create_reference_with_id(oid, repId);
  37. } catch (EmptyStackException notInInvocationE) {
  38. //Not within an invocation context
  39. POAImpl defaultPOA = null;
  40. try {
  41. defaultPOA = (POAImpl)self._default_POA();
  42. } catch (ClassCastException exception){
  43. throw wrapper.defaultPoaNotPoaimpl( exception ) ;
  44. }
  45. try {
  46. if (defaultPOA.getPolicies().isImplicitlyActivated() ||
  47. (defaultPOA.getPolicies().isUniqueIds() &&
  48. defaultPOA.getPolicies().retainServants())) {
  49. return defaultPOA.servant_to_reference(self);
  50. } else {
  51. throw wrapper.wrongPoliciesForThisObject() ;
  52. }
  53. } catch ( org.omg.PortableServer.POAPackage.ServantNotActive e) {
  54. throw wrapper.thisObjectServantNotActive( e ) ;
  55. } catch ( org.omg.PortableServer.POAPackage.WrongPolicy e) {
  56. throw wrapper.thisObjectWrongPolicy( e ) ;
  57. }
  58. } catch (ClassCastException e) {
  59. throw wrapper.defaultPoaNotPoaimpl( e ) ;
  60. }
  61. }
  62. public POA poa(Servant self)
  63. {
  64. try {
  65. return (POA)orb.peekInvocationInfo().oa();
  66. } catch (EmptyStackException exception){
  67. POA returnValue = factory.lookupPOA(self);
  68. if (returnValue != null) {
  69. return returnValue;
  70. }
  71. throw wrapper.noContext( exception ) ;
  72. }
  73. }
  74. public byte[] object_id(Servant self)
  75. {
  76. try{
  77. return orb.peekInvocationInfo().id();
  78. } catch (EmptyStackException exception){
  79. throw wrapper.noContext(exception) ;
  80. }
  81. }
  82. public POA default_POA(Servant self)
  83. {
  84. return factory.getRootPOA();
  85. }
  86. public boolean is_a(Servant self, String repId)
  87. {
  88. String[] repositoryIds = self._all_interfaces(poa(self),object_id(self));
  89. for ( int i=0; i<repositoryIds.length; i++ )
  90. if ( repId.equals(repositoryIds[i]) )
  91. return true;
  92. return false;
  93. }
  94. public boolean non_existent(Servant self)
  95. {
  96. //REVISIT
  97. try{
  98. byte[] oid = orb.peekInvocationInfo().id();
  99. if( oid == null) return true;
  100. else return false;
  101. } catch (EmptyStackException exception){
  102. throw wrapper.noContext(exception) ;
  103. }
  104. }
  105. // The get_interface() method has been replaced by get_interface_def()
  106. public org.omg.CORBA.Object get_interface_def(Servant Self)
  107. {
  108. throw wrapper.methodNotImplemented() ;
  109. }
  110. }