1 package com.sun.corba.se.impl.resolver ; 2 3 import org.omg.CORBA.portable.InputStream ; 4 import org.omg.CORBA.portable.OutputStream ; 5 import org.omg.CORBA.portable.ApplicationException ; 6 import org.omg.CORBA.portable.RemarshalException ; 7 8 import com.sun.corba.se.spi.ior.IOR ; 9 import com.sun.corba.se.spi.ior.IORFactories ; 10 import com.sun.corba.se.spi.ior.IORTemplate ; 11 import com.sun.corba.se.spi.ior.ObjectKey ; 12 import com.sun.corba.se.spi.ior.ObjectKeyFactory ; 13 import com.sun.corba.se.spi.ior.iiop.IIOPAddress ; 14 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ; 15 import com.sun.corba.se.spi.ior.iiop.IIOPFactories ; 16 import com.sun.corba.se.spi.ior.iiop.GIOPVersion ; 17 import com.sun.corba.se.spi.logging.CORBALogDomains ; 18 import com.sun.corba.se.spi.orb.ORB ; 19 import com.sun.corba.se.spi.resolver.Resolver ; 20 21 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 22 import com.sun.corba.se.impl.orbutil.ORBUtility ; 23 24 public class BootstrapResolverImpl implements Resolver { 25 private org.omg.CORBA.portable.Delegate bootstrapDelegate ; 26 private ORBUtilSystemException wrapper ; 27 28 public BootstrapResolverImpl(ORB orb, String host, int port) { 29 wrapper = ORBUtilSystemException.get( orb, 30 CORBALogDomains.ORB_RESOLVER ) ; 31 32 byte[] initialKey = "INIT".getBytes() ; 34 ObjectKey okey = orb.getObjectKeyFactory().create(initialKey) ; 35 36 IIOPAddress addr = IIOPFactories.makeIIOPAddress( orb, host, port ) ; 37 IIOPProfileTemplate ptemp = IIOPFactories.makeIIOPProfileTemplate( 38 orb, GIOPVersion.V1_0, addr); 39 40 IORTemplate iortemp = IORFactories.makeIORTemplate( okey.getTemplate() ) ; 41 iortemp.add( ptemp ) ; 42 43 IOR initialIOR = iortemp.makeIOR( (com.sun.corba.se.spi.orb.ORB)orb, 44 "", okey.getId() ) ; 45 46 bootstrapDelegate = ORBUtility.makeClientDelegate( initialIOR ) ; 47 } 48 49 57 private InputStream invoke( String operationName, String parameter ) 58 { 59 boolean remarshal = true; 60 61 63 InputStream inStream = null; 64 65 70 while (remarshal) { 71 org.omg.CORBA.Object objref = null ; 72 remarshal = false; 73 74 OutputStream os = (OutputStream ) bootstrapDelegate.request( objref, 75 operationName, true); 76 77 if ( parameter != null ) { 78 os.write_string( parameter ); 79 } 80 81 try { 82 89 inStream = bootstrapDelegate.invoke( objref, os); 90 } catch (ApplicationException e) { 91 throw wrapper.bootstrapApplicationException( e ) ; 92 } catch (RemarshalException e) { 93 remarshal = true; 95 } 96 } 97 98 return inStream; 99 } 100 101 public org.omg.CORBA.Object resolve( String identifier ) 102 { 103 InputStream inStream = null ; 104 org.omg.CORBA.Object result = null ; 105 106 try { 107 inStream = invoke( "get", identifier ) ; 108 109 result = inStream.read_Object(); 110 111 } finally { 114 bootstrapDelegate.releaseReply( null, inStream ) ; 115 } 116 117 return result ; 118 } 119 120 public java.util.Set list() 121 { 122 InputStream inStream = null ; 123 java.util.Set result = new java.util.HashSet () ; 124 125 try { 126 inStream = invoke( "list", null ) ; 127 128 int count = inStream.read_long(); 129 for (int i=0; i < count; i++) 130 result.add( inStream.read_string() ) ; 131 132 } finally { 135 bootstrapDelegate.releaseReply( null, inStream ) ; 136 } 137 138 return result ; 139 } 140 } 141 | Popular Tags |