KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > protocol > BootstrapServerRequestDispatcher


1 /*
2  * @(#)BootstrapServerRequestDispatcher.java 1.25 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
8 package com.sun.corba.se.impl.protocol ;
9
10 import java.util.Iterator JavaDoc ;
11
12 import org.omg.CORBA.SystemException JavaDoc ;
13
14 import com.sun.corba.se.pept.protocol.MessageMediator;
15
16 import com.sun.corba.se.spi.ior.IOR ;
17 import com.sun.corba.se.spi.ior.ObjectKey ;
18 import com.sun.corba.se.spi.orb.ORB ;
19 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
20 import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
21
22 import com.sun.corba.se.impl.encoding.MarshalInputStream ;
23 import com.sun.corba.se.impl.encoding.MarshalOutputStream ;
24
25 import com.sun.corba.se.spi.logging.CORBALogDomains ;
26
27 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
28
29 /**
30  * Class BootstrapServerRequestDispatcher handles the requests coming to the
31  * BootstrapServer. It implements Server so that it can be registered
32  * as a subcontract. It is passed a BootstrapServiceProperties object
33  * which contains
34  * the supported ids and their values for the bootstrap service. This
35  * Properties object is only read from, never written to, and is shared
36  * among all threads.
37  * <p>
38  * The BootstrapServerRequestDispatcher responds primarily to GIOP requests,
39  * but LocateRequests are also handled for graceful interoperability.
40  * The BootstrapServerRequestDispatcher handles one request at a time.
41  */

42 public class BootstrapServerRequestDispatcher
43     implements CorbaServerRequestDispatcher
44 {
45     private ORB orb;
46
47     ORBUtilSystemException wrapper ;
48
49     private static final boolean debug = false;
50
51     public BootstrapServerRequestDispatcher(ORB orb )
52     {
53     this.orb = orb;
54     this.wrapper = ORBUtilSystemException.get( orb,
55         CORBALogDomains.RPC_PROTOCOL ) ;
56     }
57     
58     /**
59      * Dispatch is called by the ORB and will serve get(key) and list()
60      * invocations on the initial object key.
61      */

62     public void dispatch(MessageMediator messageMediator)
63     {
64     CorbaMessageMediator request = (CorbaMessageMediator) messageMediator;
65     CorbaMessageMediator response = null;
66
67     try {
68         MarshalInputStream is = (MarshalInputStream)
69         request.getInputObject();
70         String JavaDoc method = request.getOperationName();
71         response = request.getProtocolHandler().createResponse(request, null);
72         MarshalOutputStream os = (MarshalOutputStream)
73         response.getOutputObject();
74
75             if (method.equals("get")) {
76                 // Get the name of the requested service
77
String JavaDoc serviceKey = is.read_string();
78
79                 // Look it up
80
org.omg.CORBA.Object JavaDoc serviceObject =
81             orb.getLocalResolver().resolve( serviceKey ) ;
82
83                 // Write reply value
84
os.write_Object(serviceObject);
85             } else if (method.equals("list")) {
86         java.util.Set JavaDoc keys = orb.getLocalResolver().list() ;
87         os.write_long( keys.size() ) ;
88         Iterator JavaDoc iter = keys.iterator() ;
89         while (iter.hasNext()) {
90             String JavaDoc obj = (String JavaDoc)iter.next() ;
91             os.write_string( obj ) ;
92         }
93         } else {
94         throw wrapper.illegalBootstrapOperation( method ) ;
95             }
96
97     } catch (org.omg.CORBA.SystemException JavaDoc ex) {
98             // Marshal the exception thrown
99
response = request.getProtocolHandler().createSystemExceptionResponse(
100         request, ex, null);
101     } catch (java.lang.RuntimeException JavaDoc ex) {
102             // Unknown exception
103
SystemException JavaDoc sysex = wrapper.bootstrapRuntimeException( ex ) ;
104         response = request.getProtocolHandler().createSystemExceptionResponse(
105                  request, sysex, null ) ;
106     } catch (java.lang.Exception JavaDoc ex) {
107             // Unknown exception
108
SystemException JavaDoc sysex = wrapper.bootstrapException( ex ) ;
109         response = request.getProtocolHandler().createSystemExceptionResponse(
110                  request, sysex, null ) ;
111     }
112
113     return;
114     }
115
116     /**
117      * Locates the object mentioned in the locate requests, and returns
118      * object here iff the object is the initial object key. A SystemException
119      * thrown if the object key is not the initial object key.
120      */

121     public IOR locate( ObjectKey objectKey) {
122     return null;
123     }
124
125     /**
126      * Not implemented
127      */

128     public int getId() {
129     throw wrapper.genericNoImpl() ;
130     }
131 }
132
Popular Tags