KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > remote > rmi > RMIIIOPServerImpl


1 /*
2  * @(#)RMIIIOPServerImpl.java 1.26 07/08/14
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.management.remote.rmi;
9
10 import java.io.IOException JavaDoc;
11 import java.rmi.Remote JavaDoc;
12 import java.security.AccessControlContext JavaDoc;
13 import java.security.AccessController JavaDoc;
14 import java.security.PrivilegedActionException JavaDoc;
15 import java.security.PrivilegedExceptionAction JavaDoc;
16 import java.util.Map JavaDoc;
17 import java.util.Collections JavaDoc;
18 import javax.rmi.PortableRemoteObject JavaDoc;
19 import javax.security.auth.Subject JavaDoc;
20
21 /**
22  * <p>An {@link RMIServerImpl} that is exported through IIOP and that
23  * creates client connections as RMI objects exported through IIOP.
24  * User code does not usually reference this class directly.</p>
25  *
26  * @see RMIServerImpl
27  *
28  * @since 1.5
29  * @since.unbundled 1.0
30  */

31 public class RMIIIOPServerImpl extends RMIServerImpl JavaDoc {
32     /**
33      * <p>Creates a new {@link RMIServerImpl}.</p>
34      *
35      * @param env the environment containing attributes for the new
36      * <code>RMIServerImpl</code>. Can be null, which is equivalent
37      * to an empty Map.
38      *
39      * @exception IOException if the RMI object cannot be created.
40      */

41     public RMIIIOPServerImpl(Map JavaDoc<String JavaDoc,?> env)
42         throws IOException JavaDoc {
43     super(env);
44
45     this.env = (env == null) ? Collections.EMPTY_MAP : env;
46
47         callerACC = AccessController.getContext();
48     }
49
50     protected void export() throws IOException JavaDoc {
51     PortableRemoteObject.exportObject(this);
52     }
53
54     protected String JavaDoc getProtocol() {
55     return "iiop";
56     }
57
58     /**
59      * <p>Returns an IIOP stub.</p>
60      * The stub might not yet be connected to the ORB. The stub will
61      * be serializable only if it is connected to the ORB.
62      * @return an IIOP stub.
63      * @exception IOException if the stub cannot be created - e.g the
64      * RMIIIOPServerImpl has not been exported yet.
65      **/

66     public Remote JavaDoc toStub() throws IOException JavaDoc {
67     // javax.rmi.CORBA.Stub stub =
68
// (javax.rmi.CORBA.Stub) PortableRemoteObject.toStub(this);
69
final Remote JavaDoc stub = PortableRemoteObject.toStub(this);
70     // java.lang.System.out.println("NON CONNECTED STUB " + stub);
71
// org.omg.CORBA.ORB orb =
72
// org.omg.CORBA.ORB.init((String[])null, (Properties)null);
73
// stub.connect(orb);
74
// java.lang.System.out.println("CONNECTED STUB " + stub);
75
return (Remote JavaDoc) stub;
76     }
77
78     /**
79      * <p>Creates a new client connection as an RMI object exported
80      * through IIOP.
81      *
82      * @param connectionId the ID of the new connection. Every
83      * connection opened by this connector server will have a
84      * different ID. The behavior is unspecified if this parameter is
85      * null.
86      *
87      * @param subject the authenticated subject. Can be null.
88      *
89      * @return the newly-created <code>RMIConnection</code>.
90      *
91      * @exception IOException if the new client object cannot be
92      * created or exported.
93      */

94     protected RMIConnection JavaDoc makeClient(String JavaDoc connectionId, Subject JavaDoc subject)
95         throws IOException JavaDoc {
96
97     if (connectionId == null)
98         throw new NullPointerException JavaDoc("Null connectionId");
99
100     RMIConnection JavaDoc client =
101         new RMIConnectionImpl JavaDoc(this, connectionId, getDefaultClassLoader(),
102                   subject, env);
103     PortableRemoteObject.exportObject(client);
104     return client;
105     }
106
107     protected void closeClient(RMIConnection JavaDoc client) throws IOException JavaDoc {
108     PortableRemoteObject.unexportObject(client);
109     }
110     
111     /**
112      * <p>Called by {@link #close()} to close the connector server by
113      * unexporting this object. After returning from this method, the
114      * connector server must not accept any new connections.</p>
115      *
116      * @exception IOException if the attempt to close the connector
117      * server failed.
118      */

119     protected void closeServer() throws IOException JavaDoc {
120     PortableRemoteObject.unexportObject(this);
121     }
122
123     @Override JavaDoc
124     RMIConnection JavaDoc doNewClient(final Object JavaDoc credentials) throws IOException JavaDoc {
125         if (callerACC == null) {
126             throw new SecurityException JavaDoc("AccessControlContext cannot be null");
127         }
128         try {
129             return AccessController.doPrivileged(
130                 new PrivilegedExceptionAction JavaDoc<RMIConnection JavaDoc>() {
131                     public RMIConnection JavaDoc run() throws IOException JavaDoc {
132                         return superDoNewClient(credentials);
133                     }
134             }, callerACC);
135         } catch (PrivilegedActionException JavaDoc pae) {
136             throw (IOException JavaDoc) pae.getCause();
137         }
138     }
139
140     RMIConnection JavaDoc superDoNewClient(Object JavaDoc credentials) throws IOException JavaDoc {
141         return super.doNewClient(credentials);
142     }
143
144     private final Map JavaDoc env;
145     private final AccessControlContext JavaDoc callerACC;
146 }
147
Popular Tags