1801N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1801N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1801N/A *
1801N/A * This code is free software; you can redistribute it and/or modify it
1801N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1801N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1801N/A *
1801N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1801N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1801N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1801N/A * version 2 for more details (a copy is included in the LICENSE file that
1801N/A * accompanied this code).
1801N/A *
1801N/A * You should have received a copy of the GNU General Public License version
1801N/A * 2 along with this work; if not, write to the Free Software Foundation,
1801N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1801N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1801N/A */
1801N/A
1801N/Apackage com.sun.jmx.remote.internal;
1801N/A
1801N/Aimport java.util.Properties;
1801N/Aimport java.rmi.Remote;
1801N/Aimport java.rmi.RemoteException;
1801N/Aimport java.rmi.NoSuchObjectException;
1801N/A
1801N/Aimport java.util.Properties;
1801N/Aimport java.rmi.Remote;
1801N/Aimport java.rmi.RemoteException;
1801N/Aimport java.rmi.NoSuchObjectException;
1801N/A
1801N/Aimport java.security.AccessController;
1801N/Aimport java.security.PrivilegedAction;
1801N/A
1801N/A/**
1801N/A * A helper class for RMI-IIOP and CORBA APIs.
1801N/A */
1801N/A
1801N/Apublic final class IIOPHelper {
1801N/A private IIOPHelper() { }
1801N/A
1801N/A // loads IIOPProxy implementation class if available
1801N/A private static final String IMPL_CLASS =
1801N/A "com.sun.jmx.remote.protocol.iiop.IIOPProxyImpl";
1801N/A private static final IIOPProxy proxy =
1801N/A AccessController.doPrivileged(new PrivilegedAction<IIOPProxy>() {
1801N/A public IIOPProxy run() {
1801N/A try {
1801N/A Class<?> c = Class.forName(IMPL_CLASS, true, null);
1801N/A return (IIOPProxy)c.newInstance();
1801N/A } catch (ClassNotFoundException cnf) {
1801N/A return null;
1801N/A } catch (InstantiationException e) {
1801N/A throw new AssertionError(e);
1801N/A } catch (IllegalAccessException e) {
1801N/A throw new AssertionError(e);
1801N/A }
1801N/A }});
1801N/A
1801N/A /**
1801N/A * Returns true if RMI-IIOP and CORBA is available.
1801N/A */
1801N/A public static boolean isAvailable() {
1801N/A return proxy != null;
1801N/A }
1801N/A
1801N/A private static void ensureAvailable() {
1801N/A if (proxy == null)
1801N/A throw new AssertionError("Should not here");
1801N/A }
1801N/A
1801N/A /**
1801N/A * Returns true if the given object is a Stub.
1801N/A */
1801N/A public static boolean isStub(Object obj) {
1801N/A return (proxy == null) ? false : proxy.isStub(obj);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Returns the Delegate to which the given Stub delegates.
1801N/A */
1801N/A public static Object getDelegate(Object stub) {
1801N/A ensureAvailable();
1801N/A return proxy.getDelegate(stub);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Sets the Delegate for a given Stub.
1801N/A */
1801N/A public static void setDelegate(Object stub, Object delegate) {
1801N/A ensureAvailable();
1801N/A proxy.setDelegate(stub, delegate);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Returns the ORB associated with the given stub
1801N/A *
1801N/A * @throws UnsupportedOperationException
1801N/A * if the object does not support the operation that
1801N/A * was invoked
1801N/A */
1801N/A public static Object getOrb(Object stub) {
1801N/A ensureAvailable();
1801N/A return proxy.getOrb(stub);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Connects the Stub to the given ORB.
1801N/A */
1801N/A public static void connect(Object stub, Object orb)
1801N/A throws RemoteException
1801N/A {
1801N/A ensureAvailable();
1801N/A proxy.connect(stub, orb);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Returns true if the given object is an ORB.
1801N/A */
1801N/A public static boolean isOrb(Object obj) {
1801N/A ensureAvailable();
1801N/A return proxy.isOrb(obj);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Creates, and returns, a new ORB instance.
1801N/A */
1801N/A public static Object createOrb(String[] args, Properties props) {
1801N/A ensureAvailable();
1801N/A return proxy.createOrb(args, props);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Converts a string, produced by the object_to_string method, back
1801N/A * to a CORBA object reference.
1801N/A */
1801N/A public static Object stringToObject(Object orb, String str) {
1801N/A ensureAvailable();
1801N/A return proxy.stringToObject(orb, str);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Converts the given CORBA object reference to a string.
1801N/A */
1801N/A public static String objectToString(Object orb, Object obj) {
1801N/A ensureAvailable();
1801N/A return proxy.objectToString(orb, obj);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Checks to ensure that an object of a remote or abstract interface
1801N/A * type can be cast to a desired type.
1801N/A */
1801N/A public static <T> T narrow(Object narrowFrom, Class<T> narrowTo) {
1801N/A ensureAvailable();
1801N/A return proxy.narrow(narrowFrom, narrowTo);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Makes a server object ready to receive remote calls
1801N/A */
1801N/A public static void exportObject(Remote obj) throws RemoteException {
1801N/A ensureAvailable();
1801N/A proxy.exportObject(obj);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Deregisters a server object from the runtime.
1801N/A */
1801N/A public static void unexportObject(Remote obj) throws NoSuchObjectException {
1801N/A ensureAvailable();
1801N/A proxy.unexportObject(obj);
1801N/A }
1801N/A
1801N/A /**
1801N/A * Returns a stub for the given server object.
1801N/A */
1801N/A public static Remote toStub(Remote obj) throws NoSuchObjectException {
1801N/A ensureAvailable();
1801N/A return proxy.toStub(obj);
1801N/A }
1801N/A}