KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > resolver > BootstrapResolverImpl


1 package com.sun.corba.se.impl.resolver ;
2
3 import org.omg.CORBA.portable.InputStream JavaDoc ;
4 import org.omg.CORBA.portable.OutputStream JavaDoc ;
5 import org.omg.CORBA.portable.ApplicationException JavaDoc ;
6 import org.omg.CORBA.portable.RemarshalException JavaDoc ;
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 JavaDoc bootstrapDelegate ;
26     private ORBUtilSystemException wrapper ;
27
28     public BootstrapResolverImpl(ORB orb, String JavaDoc host, int port) {
29     wrapper = ORBUtilSystemException.get( orb,
30         CORBALogDomains.ORB_RESOLVER ) ;
31
32     // Create a new IOR with the magic of INIT
33
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     /**
50      * For the BootStrap operation we do not expect to have more than one
51      * parameter. We do not want to extend BootStrap protocol any further,
52      * as INS handles most of what BootStrap can handle in a portable way.
53      *
54      * @return InputStream which contains the response from the
55      * BootStrapOperation.
56      */

57     private InputStream JavaDoc invoke( String JavaDoc operationName, String JavaDoc parameter )
58     {
59     boolean remarshal = true;
60
61     // Invoke.
62

63     InputStream JavaDoc inStream = null;
64
65     // If there is a location forward then you will need
66
// to invoke again on the updated information.
67
// Just calling this same routine with the same host/port
68
// does not take the location forward info into account.
69

70     while (remarshal) {
71         org.omg.CORBA.Object JavaDoc objref = null ;
72         remarshal = false;
73
74         OutputStream JavaDoc os = (OutputStream JavaDoc) bootstrapDelegate.request( objref,
75         operationName, true);
76
77             if ( parameter != null ) {
78                 os.write_string( parameter );
79             }
80
81         try {
82         // The only reason a null objref is passed is to get the version of
83
// invoke used by streams. Otherwise the PortableInterceptor
84
// call stack will become unbalanced since the version of
85
// invoke which only takes the stream does not call
86
// PortableInterceptor ending points.
87
// Note that the first parameter is ignored inside invoke.
88

89         inStream = bootstrapDelegate.invoke( objref, os);
90         } catch (ApplicationException JavaDoc e) {
91         throw wrapper.bootstrapApplicationException( e ) ;
92         } catch (RemarshalException JavaDoc e) {
93         // XXX log this
94
remarshal = true;
95         }
96     }
97
98         return inStream;
99     }
100
101     public org.omg.CORBA.Object JavaDoc resolve( String JavaDoc identifier )
102     {
103     InputStream JavaDoc inStream = null ;
104     org.omg.CORBA.Object JavaDoc result = null ;
105
106     try {
107         inStream = invoke( "get", identifier ) ;
108
109         result = inStream.read_Object();
110
111         // NOTE: do note trap and ignore errors.
112
// Let them flow out.
113
} finally {
114         bootstrapDelegate.releaseReply( null, inStream ) ;
115     }
116
117     return result ;
118     }
119
120     public java.util.Set JavaDoc list()
121     {
122     InputStream JavaDoc inStream = null ;
123     java.util.Set JavaDoc result = new java.util.HashSet JavaDoc() ;
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         // NOTE: do note trap and ignore errors.
133
// Let them flow out.
134
} finally {
135         bootstrapDelegate.releaseReply( null, inStream ) ;
136     }
137
138     return result ;
139     }
140 }
141
Popular Tags