author | lana |
Fri, 18 Sep 2015 14:20:00 -0700 | |
changeset 32689 | ede6e8912b79 |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
4167 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
13589
diff
changeset
|
2 |
* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
4167 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
4167 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
4167 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
4167 | 24 |
*/ |
25 |
||
26 |
package com.sun.jmx.remote.internal; |
|
27 |
||
28 |
import java.util.Properties; |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
29 |
import java.io.IOException; |
4167 | 30 |
import java.rmi.Remote; |
31 |
import java.rmi.NoSuchObjectException; |
|
32 |
||
33 |
import java.security.AccessController; |
|
34 |
import java.security.PrivilegedAction; |
|
35 |
||
36 |
/** |
|
37 |
* A helper class for RMI-IIOP and CORBA APIs. |
|
38 |
*/ |
|
39 |
||
40 |
public final class IIOPHelper { |
|
41 |
private IIOPHelper() { } |
|
42 |
||
43 |
// loads IIOPProxy implementation class if available |
|
44 |
private static final String IMPL_CLASS = |
|
45 |
"com.sun.jmx.remote.protocol.iiop.IIOPProxyImpl"; |
|
46 |
private static final IIOPProxy proxy = |
|
47 |
AccessController.doPrivileged(new PrivilegedAction<IIOPProxy>() { |
|
48 |
public IIOPProxy run() { |
|
49 |
try { |
|
13589
da4cb574f4a6
7193339: Prepare system classes be defined by a non-null module loader
mchung
parents:
5506
diff
changeset
|
50 |
Class<?> c = Class.forName(IMPL_CLASS, true, |
da4cb574f4a6
7193339: Prepare system classes be defined by a non-null module loader
mchung
parents:
5506
diff
changeset
|
51 |
IIOPHelper.class.getClassLoader()); |
4167 | 52 |
return (IIOPProxy)c.newInstance(); |
53 |
} catch (ClassNotFoundException cnf) { |
|
54 |
return null; |
|
55 |
} catch (InstantiationException e) { |
|
56 |
throw new AssertionError(e); |
|
57 |
} catch (IllegalAccessException e) { |
|
58 |
throw new AssertionError(e); |
|
59 |
} |
|
60 |
}}); |
|
61 |
||
62 |
/** |
|
63 |
* Returns true if RMI-IIOP and CORBA is available. |
|
64 |
*/ |
|
65 |
public static boolean isAvailable() { |
|
66 |
return proxy != null; |
|
67 |
} |
|
68 |
||
69 |
private static void ensureAvailable() { |
|
70 |
if (proxy == null) |
|
71 |
throw new AssertionError("Should not here"); |
|
72 |
} |
|
73 |
||
74 |
/** |
|
75 |
* Returns true if the given object is a Stub. |
|
76 |
*/ |
|
77 |
public static boolean isStub(Object obj) { |
|
78 |
return (proxy == null) ? false : proxy.isStub(obj); |
|
79 |
} |
|
80 |
||
81 |
/** |
|
82 |
* Returns the Delegate to which the given Stub delegates. |
|
83 |
*/ |
|
84 |
public static Object getDelegate(Object stub) { |
|
85 |
ensureAvailable(); |
|
86 |
return proxy.getDelegate(stub); |
|
87 |
} |
|
88 |
||
89 |
/** |
|
90 |
* Sets the Delegate for a given Stub. |
|
91 |
*/ |
|
92 |
public static void setDelegate(Object stub, Object delegate) { |
|
93 |
ensureAvailable(); |
|
94 |
proxy.setDelegate(stub, delegate); |
|
95 |
} |
|
96 |
||
97 |
/** |
|
98 |
* Returns the ORB associated with the given stub |
|
99 |
* |
|
100 |
* @throws UnsupportedOperationException |
|
101 |
* if the object does not support the operation that |
|
102 |
* was invoked |
|
103 |
*/ |
|
104 |
public static Object getOrb(Object stub) { |
|
105 |
ensureAvailable(); |
|
106 |
return proxy.getOrb(stub); |
|
107 |
} |
|
108 |
||
109 |
/** |
|
110 |
* Connects the Stub to the given ORB. |
|
111 |
*/ |
|
112 |
public static void connect(Object stub, Object orb) |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
113 |
throws IOException |
4167 | 114 |
{ |
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
115 |
if (proxy == null) |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
116 |
throw new IOException("Connection to ORB failed, RMI/IIOP not available"); |
4167 | 117 |
proxy.connect(stub, orb); |
118 |
} |
|
119 |
||
120 |
/** |
|
121 |
* Returns true if the given object is an ORB. |
|
122 |
*/ |
|
123 |
public static boolean isOrb(Object obj) { |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
124 |
return (proxy == null) ? false : proxy.isOrb(obj); |
4167 | 125 |
} |
126 |
||
127 |
/** |
|
128 |
* Creates, and returns, a new ORB instance. |
|
129 |
*/ |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
130 |
public static Object createOrb(String[] args, Properties props) |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
131 |
throws IOException |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
132 |
{ |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
133 |
if (proxy == null) |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
134 |
throw new IOException("ORB initialization failed, RMI/IIOP not available"); |
4167 | 135 |
return proxy.createOrb(args, props); |
136 |
} |
|
137 |
||
138 |
/** |
|
139 |
* Converts a string, produced by the object_to_string method, back |
|
140 |
* to a CORBA object reference. |
|
141 |
*/ |
|
142 |
public static Object stringToObject(Object orb, String str) { |
|
143 |
ensureAvailable(); |
|
144 |
return proxy.stringToObject(orb, str); |
|
145 |
} |
|
146 |
||
147 |
/** |
|
148 |
* Converts the given CORBA object reference to a string. |
|
149 |
*/ |
|
150 |
public static String objectToString(Object orb, Object obj) { |
|
151 |
ensureAvailable(); |
|
152 |
return proxy.objectToString(orb, obj); |
|
153 |
} |
|
154 |
||
155 |
/** |
|
156 |
* Checks to ensure that an object of a remote or abstract interface |
|
157 |
* type can be cast to a desired type. |
|
158 |
*/ |
|
159 |
public static <T> T narrow(Object narrowFrom, Class<T> narrowTo) { |
|
160 |
ensureAvailable(); |
|
161 |
return proxy.narrow(narrowFrom, narrowTo); |
|
162 |
} |
|
163 |
||
164 |
/** |
|
165 |
* Makes a server object ready to receive remote calls |
|
166 |
*/ |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
167 |
public static void exportObject(Remote obj) throws IOException { |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
168 |
if (proxy == null) |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
169 |
throw new IOException("RMI object cannot be exported, RMI/IIOP not available"); |
4167 | 170 |
proxy.exportObject(obj); |
171 |
} |
|
172 |
||
173 |
/** |
|
174 |
* Deregisters a server object from the runtime. |
|
175 |
*/ |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
176 |
public static void unexportObject(Remote obj) throws IOException { |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
177 |
if (proxy == null) |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
178 |
throw new NoSuchObjectException("Object not exported"); |
4167 | 179 |
proxy.unexportObject(obj); |
180 |
} |
|
181 |
||
182 |
/** |
|
183 |
* Returns a stub for the given server object. |
|
184 |
*/ |
|
14917
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
185 |
public static Remote toStub(Remote obj) throws IOException { |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
186 |
if (proxy == null) |
bf08557604f8
8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents:
14342
diff
changeset
|
187 |
throw new NoSuchObjectException("Object not exported"); |
4167 | 188 |
return proxy.toStub(obj); |
189 |
} |
|
190 |
} |