1. /*
  2. * @(#)ObjectAdapterBase.java 1.40 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.spi.oa ;
  8. import org.omg.PortableInterceptor.ObjectReferenceTemplate ;
  9. import org.omg.PortableInterceptor.ObjectReferenceFactory ;
  10. import org.omg.CORBA.Policy ;
  11. import org.omg.PortableInterceptor.ACTIVE ;
  12. import com.sun.corba.se.spi.copyobject.ObjectCopierFactory ;
  13. import com.sun.corba.se.spi.ior.IORFactories ;
  14. import com.sun.corba.se.spi.ior.IORTemplate ;
  15. import com.sun.corba.se.spi.ior.ObjectAdapterId;
  16. import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
  17. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  18. import com.sun.corba.se.spi.oa.OADestroyed ;
  19. import com.sun.corba.se.spi.oa.ObjectAdapter ;
  20. import com.sun.corba.se.spi.orb.ORB ;
  21. import com.sun.corba.se.spi.protocol.PIHandler ;
  22. import com.sun.corba.se.impl.logging.POASystemException ;
  23. import com.sun.corba.se.impl.logging.OMGSystemException ;
  24. import com.sun.corba.se.impl.oa.poa.Policies;
  25. abstract public class ObjectAdapterBase extends org.omg.CORBA.LocalObject
  26. implements ObjectAdapter
  27. {
  28. private ORB orb;
  29. // Exception wrappers
  30. private final POASystemException _iorWrapper ;
  31. private final POASystemException _invocationWrapper ;
  32. private final POASystemException _lifecycleWrapper ;
  33. private final OMGSystemException _omgInvocationWrapper ;
  34. private final OMGSystemException _omgLifecycleWrapper ;
  35. // Data related to the construction of object references and
  36. // supporting the Object Reference Template.
  37. private IORTemplate iortemp;
  38. private byte[] adapterId ;
  39. private ObjectReferenceTemplate adapterTemplate ;
  40. private ObjectReferenceFactory currentFactory ;
  41. public ObjectAdapterBase( ORB orb )
  42. {
  43. this.orb = orb ;
  44. _iorWrapper = POASystemException.get( orb,
  45. CORBALogDomains.OA_IOR ) ;
  46. _lifecycleWrapper = POASystemException.get( orb,
  47. CORBALogDomains.OA_LIFECYCLE ) ;
  48. _omgLifecycleWrapper = OMGSystemException.get( orb,
  49. CORBALogDomains.OA_LIFECYCLE ) ;
  50. _invocationWrapper = POASystemException.get( orb,
  51. CORBALogDomains.OA_INVOCATION ) ;
  52. _omgInvocationWrapper = OMGSystemException.get( orb,
  53. CORBALogDomains.OA_INVOCATION ) ;
  54. }
  55. public final POASystemException iorWrapper()
  56. {
  57. return _iorWrapper ;
  58. }
  59. public final POASystemException lifecycleWrapper()
  60. {
  61. return _lifecycleWrapper ;
  62. }
  63. public final OMGSystemException omgLifecycleWrapper()
  64. {
  65. return _omgLifecycleWrapper ;
  66. }
  67. public final POASystemException invocationWrapper()
  68. {
  69. return _invocationWrapper ;
  70. }
  71. public final OMGSystemException omgInvocationWrapper()
  72. {
  73. return _omgInvocationWrapper ;
  74. }
  75. /*
  76. * This creates the complete template.
  77. * When it is done, reference creation can proceed.
  78. */
  79. final public void initializeTemplate( ObjectKeyTemplate oktemp,
  80. boolean notifyORB, Policies policies, String codebase,
  81. String objectAdapterManagerId, ObjectAdapterId objectAdapterId)
  82. {
  83. adapterId = oktemp.getAdapterId() ;
  84. iortemp = IORFactories.makeIORTemplate(oktemp) ;
  85. // This calls acceptors which create profiles and may
  86. // add tagged components to those profiles.
  87. orb.getCorbaTransportManager().addToIORTemplate(
  88. iortemp, policies,
  89. codebase, objectAdapterManagerId, objectAdapterId);
  90. adapterTemplate = IORFactories.makeObjectReferenceTemplate( orb,
  91. iortemp ) ;
  92. currentFactory = adapterTemplate ;
  93. if (notifyORB) {
  94. PIHandler pih = orb.getPIHandler() ;
  95. if (pih != null)
  96. // This runs the IORInterceptors.
  97. pih.objectAdapterCreated( this ) ;
  98. }
  99. iortemp.makeImmutable() ;
  100. }
  101. final public org.omg.CORBA.Object makeObject( String repId, byte[] oid )
  102. {
  103. return currentFactory.make_object( repId, oid ) ;
  104. }
  105. final public byte[] getAdapterId()
  106. {
  107. return adapterId ;
  108. }
  109. final public ORB getORB()
  110. {
  111. return orb ;
  112. }
  113. abstract public Policy getEffectivePolicy( int type ) ;
  114. final public IORTemplate getIORTemplate()
  115. {
  116. return iortemp ;
  117. }
  118. abstract public int getManagerId() ;
  119. abstract public short getState() ;
  120. final public ObjectReferenceTemplate getAdapterTemplate()
  121. {
  122. return adapterTemplate ;
  123. }
  124. final public ObjectReferenceFactory getCurrentFactory()
  125. {
  126. return currentFactory ;
  127. }
  128. final public void setCurrentFactory( ObjectReferenceFactory factory )
  129. {
  130. currentFactory = factory ;
  131. }
  132. abstract public org.omg.CORBA.Object getLocalServant( byte[] objectId ) ;
  133. abstract public void getInvocationServant( OAInvocationInfo info ) ;
  134. abstract public void returnServant() ;
  135. abstract public void enter() throws OADestroyed ;
  136. abstract public void exit() ;
  137. abstract protected ObjectCopierFactory getObjectCopierFactory() ;
  138. // Note that all current subclasses share the same implementation of this method,
  139. // but overriding it would make sense for OAs that use a different InvocationInfo.
  140. public OAInvocationInfo makeInvocationInfo( byte[] objectId )
  141. {
  142. OAInvocationInfo info = new OAInvocationInfo( this, objectId ) ;
  143. info.setCopierFactory( getObjectCopierFactory() ) ;
  144. return info ;
  145. }
  146. abstract public String[] getInterfaces( Object servant, byte[] objectId ) ;
  147. }