1. package com.sun.corba.se.impl.resolver ;
  2. import org.omg.CORBA.portable.InputStream ;
  3. import org.omg.CORBA.portable.OutputStream ;
  4. import org.omg.CORBA.portable.ApplicationException ;
  5. import org.omg.CORBA.portable.RemarshalException ;
  6. import com.sun.corba.se.spi.ior.IOR ;
  7. import com.sun.corba.se.spi.ior.IORFactories ;
  8. import com.sun.corba.se.spi.ior.IORTemplate ;
  9. import com.sun.corba.se.spi.ior.ObjectKey ;
  10. import com.sun.corba.se.spi.ior.ObjectKeyFactory ;
  11. import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
  12. import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ;
  13. import com.sun.corba.se.spi.ior.iiop.IIOPFactories ;
  14. import com.sun.corba.se.spi.ior.iiop.GIOPVersion ;
  15. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  16. import com.sun.corba.se.spi.orb.ORB ;
  17. import com.sun.corba.se.spi.resolver.Resolver ;
  18. import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  19. import com.sun.corba.se.impl.orbutil.ORBUtility ;
  20. public class BootstrapResolverImpl implements Resolver {
  21. private org.omg.CORBA.portable.Delegate bootstrapDelegate ;
  22. private ORBUtilSystemException wrapper ;
  23. public BootstrapResolverImpl(ORB orb, String host, int port) {
  24. wrapper = ORBUtilSystemException.get( orb,
  25. CORBALogDomains.ORB_RESOLVER ) ;
  26. // Create a new IOR with the magic of INIT
  27. byte[] initialKey = "INIT".getBytes() ;
  28. ObjectKey okey = orb.getObjectKeyFactory().create(initialKey) ;
  29. IIOPAddress addr = IIOPFactories.makeIIOPAddress( orb, host, port ) ;
  30. IIOPProfileTemplate ptemp = IIOPFactories.makeIIOPProfileTemplate(
  31. orb, GIOPVersion.V1_0, addr);
  32. IORTemplate iortemp = IORFactories.makeIORTemplate( okey.getTemplate() ) ;
  33. iortemp.add( ptemp ) ;
  34. IOR initialIOR = iortemp.makeIOR( (com.sun.corba.se.spi.orb.ORB)orb,
  35. "", okey.getId() ) ;
  36. bootstrapDelegate = ORBUtility.makeClientDelegate( initialIOR ) ;
  37. }
  38. /**
  39. * For the BootStrap operation we do not expect to have more than one
  40. * parameter. We do not want to extend BootStrap protocol any further,
  41. * as INS handles most of what BootStrap can handle in a portable way.
  42. *
  43. * @return InputStream which contains the response from the
  44. * BootStrapOperation.
  45. */
  46. private InputStream invoke( String operationName, String parameter )
  47. {
  48. boolean remarshal = true;
  49. // Invoke.
  50. InputStream inStream = null;
  51. // If there is a location forward then you will need
  52. // to invoke again on the updated information.
  53. // Just calling this same routine with the same host/port
  54. // does not take the location forward info into account.
  55. while (remarshal) {
  56. org.omg.CORBA.Object objref = null ;
  57. remarshal = false;
  58. OutputStream os = (OutputStream) bootstrapDelegate.request( objref,
  59. operationName, true);
  60. if ( parameter != null ) {
  61. os.write_string( parameter );
  62. }
  63. try {
  64. // The only reason a null objref is passed is to get the version of
  65. // invoke used by streams. Otherwise the PortableInterceptor
  66. // call stack will become unbalanced since the version of
  67. // invoke which only takes the stream does not call
  68. // PortableInterceptor ending points.
  69. // Note that the first parameter is ignored inside invoke.
  70. inStream = bootstrapDelegate.invoke( objref, os);
  71. } catch (ApplicationException e) {
  72. throw wrapper.bootstrapApplicationException( e ) ;
  73. } catch (RemarshalException e) {
  74. // XXX log this
  75. remarshal = true;
  76. }
  77. }
  78. return inStream;
  79. }
  80. public org.omg.CORBA.Object resolve( String identifier )
  81. {
  82. InputStream inStream = null ;
  83. org.omg.CORBA.Object result = null ;
  84. try {
  85. inStream = invoke( "get", identifier ) ;
  86. result = inStream.read_Object();
  87. // NOTE: do note trap and ignore errors.
  88. // Let them flow out.
  89. } finally {
  90. bootstrapDelegate.releaseReply( null, inStream ) ;
  91. }
  92. return result ;
  93. }
  94. public java.util.Set list()
  95. {
  96. InputStream inStream = null ;
  97. java.util.Set result = new java.util.HashSet() ;
  98. try {
  99. inStream = invoke( "list", null ) ;
  100. int count = inStream.read_long();
  101. for (int i=0; i < count; i++)
  102. result.add( inStream.read_string() ) ;
  103. // NOTE: do note trap and ignore errors.
  104. // Let them flow out.
  105. } finally {
  106. bootstrapDelegate.releaseReply( null, inStream ) ;
  107. }
  108. return result ;
  109. }
  110. }