1. /*
  2. * @(#)DynamicStubImpl.java 1.5 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.presentation.rmi ;
  8. import java.io.ObjectInputStream ;
  9. import java.io.ObjectOutputStream ;
  10. import java.io.IOException ;
  11. import java.io.Serializable ;
  12. import java.rmi.RemoteException ;
  13. import javax.rmi.CORBA.Tie ;
  14. import org.omg.CORBA_2_3.portable.ObjectImpl ;
  15. import org.omg.CORBA.portable.Delegate ;
  16. import org.omg.CORBA.portable.OutputStream ;
  17. import org.omg.CORBA.SystemException ;
  18. import org.omg.CORBA.ORB ;
  19. import com.sun.corba.se.spi.orbutil.proxy.InvocationHandlerFactory ;
  20. import com.sun.corba.se.spi.presentation.rmi.PresentationManager ;
  21. import com.sun.corba.se.spi.presentation.rmi.StubAdapter ;
  22. import com.sun.corba.se.spi.presentation.rmi.DynamicStub ;
  23. import com.sun.corba.se.impl.presentation.rmi.StubConnectImpl ;
  24. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  25. import com.sun.corba.se.impl.logging.UtilSystemException ;
  26. import com.sun.corba.se.impl.ior.StubIORImpl ;
  27. import com.sun.corba.se.impl.util.RepositoryId ;
  28. import com.sun.corba.se.impl.util.JDKBridge ;
  29. import com.sun.corba.se.impl.util.Utility ;
  30. // XXX Do we need _get_codebase?
  31. public class DynamicStubImpl extends ObjectImpl
  32. implements DynamicStub, Serializable
  33. {
  34. private static final long serialVersionUID = 4852612040012087675L;
  35. private String[] typeIds ;
  36. private StubIORImpl ior ;
  37. private DynamicStub self = null ; // The actual DynamicProxy for this stub.
  38. public void setSelf( DynamicStub self )
  39. {
  40. // XXX Should probably only allow this once.
  41. this.self = self ;
  42. }
  43. public DynamicStub getSelf()
  44. {
  45. return self ;
  46. }
  47. public DynamicStubImpl( String[] typeIds )
  48. {
  49. this.typeIds = typeIds ;
  50. ior = null ;
  51. }
  52. public void setDelegate( Delegate delegate )
  53. {
  54. _set_delegate( delegate ) ;
  55. }
  56. public Delegate getDelegate()
  57. {
  58. return _get_delegate() ;
  59. }
  60. public ORB getORB()
  61. {
  62. return (ORB)_orb() ;
  63. }
  64. public String[] _ids()
  65. {
  66. return typeIds ;
  67. }
  68. public String[] getTypeIds()
  69. {
  70. return _ids() ;
  71. }
  72. public void connect( ORB orb ) throws RemoteException
  73. {
  74. ior = StubConnectImpl.connect( ior, self, this, orb ) ;
  75. }
  76. public boolean isLocal()
  77. {
  78. return _is_local() ;
  79. }
  80. public OutputStream request( String operation,
  81. boolean responseExpected )
  82. {
  83. return _request( operation, responseExpected ) ;
  84. }
  85. private void readObject( ObjectInputStream stream ) throws
  86. IOException, ClassNotFoundException
  87. {
  88. ior = new StubIORImpl() ;
  89. ior.doRead( stream ) ;
  90. }
  91. private void writeObject( ObjectOutputStream stream ) throws
  92. IOException
  93. {
  94. if (ior == null)
  95. ior = new StubIORImpl( this ) ;
  96. ior.doWrite( stream ) ;
  97. }
  98. public Object readResolve()
  99. {
  100. String repositoryId = ior.getRepositoryId() ;
  101. String cname = RepositoryId.cache.getId( repositoryId ).getClassName() ;
  102. Class cls = null ;
  103. try {
  104. cls = JDKBridge.loadClass( cname, null, null ) ;
  105. } catch (ClassNotFoundException exc) {
  106. // XXX log this
  107. }
  108. PresentationManager pm =
  109. com.sun.corba.se.spi.orb.ORB.getPresentationManager() ;
  110. PresentationManager.ClassData classData = pm.getClassData( cls ) ;
  111. InvocationHandlerFactoryImpl ihfactory =
  112. (InvocationHandlerFactoryImpl)classData.getInvocationHandlerFactory() ;
  113. return ihfactory.getInvocationHandler( this ) ;
  114. }
  115. }