Java Code Examples for com.sun.corba.se.impl.util.Utility#loadStub()

The following examples show how to use com.sun.corba.se.impl.util.Utility#loadStub() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PortableRemoteObject.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 2
Source File: PortableRemoteObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 3
Source File: PortableRemoteObject.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 4
Source File: PortableRemoteObject.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 5
Source File: PortableRemoteObject.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 6
Source File: PortableRemoteObject.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 7
Source File: PortableRemoteObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 8
Source File: PortableRemoteObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 9
Source File: PortableRemoteObject.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 10
Source File: PortableRemoteObject.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a stub for the given server object.
 * @param obj the server object for which a stub is required. Must either be a subclass
 * of PortableRemoteObject or have been previously the target of a call to
 * {@link #exportObject}.
 * @return the most derived stub for the object.
 * @exception NoSuchObjectException if a stub cannot be located for the given server object.
 */
public Remote toStub (Remote obj)
    throws NoSuchObjectException
{
    Remote result = null;
    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // If the class is already an IIOP stub then return it.
    if (StubAdapter.isStub( obj )) {
        return obj;
    }

    // If the class is already a JRMP stub then return it.
    if (obj instanceof java.rmi.server.RemoteStub) {
        return obj;
    }

    // Has it been exported to IIOP?
    Tie theTie = Util.getTie(obj);

    if (theTie != null) {
        result = Utility.loadStub(theTie,null,null,true);
    } else {
        if (Utility.loadTie(obj) == null) {
            result = java.rmi.server.RemoteObject.toStub(obj);
        }
    }

    if (result == null) {
        throw new NoSuchObjectException("object not exported");
    }

    return result;
}
 
Example 11
Source File: PortableRemoteObject.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks to ensure that an object of a remote or abstract interface type
 * can be cast to a desired type.
 * @param narrowFrom the object to check.
 * @param narrowTo the desired type.
 * @return an object which can be cast to the desired type.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public java.lang.Object narrow ( java.lang.Object narrowFrom,
    java.lang.Class narrowTo) throws ClassCastException
{
    java.lang.Object result = null;

    if (narrowFrom == null)
        return null;

    if (narrowTo == null)
        throw new NullPointerException("invalid argument");

    try {
        if (narrowTo.isAssignableFrom(narrowFrom.getClass()))
            return narrowFrom;

        // Is narrowTo an interface that might be
        // implemented by a servant running on iiop?
        if (narrowTo.isInterface() &&
            narrowTo != java.io.Serializable.class &&
            narrowTo != java.io.Externalizable.class) {

            org.omg.CORBA.Object narrowObj
                = (org.omg.CORBA.Object) narrowFrom;

            // Create an id from the narrowTo type...
            String id = RepositoryId.createForAnyType(narrowTo);

            if (narrowObj._is_a(id)) {
                return Utility.loadStub(narrowObj,narrowTo);
            } else {
                throw new ClassCastException( "Object is not of remote type " +
                    narrowTo.getName() ) ;
            }
        } else {
            throw new ClassCastException( "Class " + narrowTo.getName() +
                " is not a valid remote interface" ) ;
        }
    } catch(Exception error) {
        ClassCastException cce = new ClassCastException() ;
        cce.initCause( error ) ;
        throw cce ;
    }
}
 
Example 12
Source File: PortableRemoteObject.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks to ensure that an object of a remote or abstract interface type
 * can be cast to a desired type.
 * @param narrowFrom the object to check.
 * @param narrowTo the desired type.
 * @return an object which can be cast to the desired type.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public java.lang.Object narrow ( java.lang.Object narrowFrom,
    java.lang.Class narrowTo) throws ClassCastException
{
    java.lang.Object result = null;

    if (narrowFrom == null)
        return null;

    if (narrowTo == null)
        throw new NullPointerException("invalid argument");

    try {
        if (narrowTo.isAssignableFrom(narrowFrom.getClass()))
            return narrowFrom;

        // Is narrowTo an interface that might be
        // implemented by a servant running on iiop?
        if (narrowTo.isInterface() &&
            narrowTo != java.io.Serializable.class &&
            narrowTo != java.io.Externalizable.class) {

            org.omg.CORBA.Object narrowObj
                = (org.omg.CORBA.Object) narrowFrom;

            // Create an id from the narrowTo type...
            String id = RepositoryId.createForAnyType(narrowTo);

            if (narrowObj._is_a(id)) {
                return Utility.loadStub(narrowObj,narrowTo);
            } else {
                throw new ClassCastException( "Object is not of remote type " +
                    narrowTo.getName() ) ;
            }
        } else {
            throw new ClassCastException( "Class " + narrowTo.getName() +
                " is not a valid remote interface" ) ;
        }
    } catch(Exception error) {
        ClassCastException cce = new ClassCastException() ;
        cce.initCause( error ) ;
        throw cce ;
    }
}
 
Example 13
Source File: PortableRemoteObject.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks to ensure that an object of a remote or abstract interface type
 * can be cast to a desired type.
 * @param narrowFrom the object to check.
 * @param narrowTo the desired type.
 * @return an object which can be cast to the desired type.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public java.lang.Object narrow ( java.lang.Object narrowFrom,
    java.lang.Class narrowTo) throws ClassCastException
{
    java.lang.Object result = null;

    if (narrowFrom == null)
        return null;

    if (narrowTo == null)
        throw new NullPointerException("invalid argument");

    try {
        if (narrowTo.isAssignableFrom(narrowFrom.getClass()))
            return narrowFrom;

        // Is narrowTo an interface that might be
        // implemented by a servant running on iiop?
        if (narrowTo.isInterface() &&
            narrowTo != java.io.Serializable.class &&
            narrowTo != java.io.Externalizable.class) {

            org.omg.CORBA.Object narrowObj
                = (org.omg.CORBA.Object) narrowFrom;

            // Create an id from the narrowTo type...
            String id = RepositoryId.createForAnyType(narrowTo);

            if (narrowObj._is_a(id)) {
                return Utility.loadStub(narrowObj,narrowTo);
            } else {
                throw new ClassCastException( "Object is not of remote type " +
                    narrowTo.getName() ) ;
            }
        } else {
            throw new ClassCastException( "Class " + narrowTo.getName() +
                " is not a valid remote interface" ) ;
        }
    } catch(Exception error) {
        ClassCastException cce = new ClassCastException() ;
        cce.initCause( error ) ;
        throw cce ;
    }
}
 
Example 14
Source File: PortableRemoteObject.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks to ensure that an object of a remote or abstract interface type
 * can be cast to a desired type.
 * @param narrowFrom the object to check.
 * @param narrowTo the desired type.
 * @return an object which can be cast to the desired type.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public java.lang.Object narrow ( java.lang.Object narrowFrom,
    java.lang.Class narrowTo) throws ClassCastException
{
    java.lang.Object result = null;

    if (narrowFrom == null)
        return null;

    if (narrowTo == null)
        throw new NullPointerException("invalid argument");

    try {
        if (narrowTo.isAssignableFrom(narrowFrom.getClass()))
            return narrowFrom;

        // Is narrowTo an interface that might be
        // implemented by a servant running on iiop?
        if (narrowTo.isInterface() &&
            narrowTo != java.io.Serializable.class &&
            narrowTo != java.io.Externalizable.class) {

            org.omg.CORBA.Object narrowObj
                = (org.omg.CORBA.Object) narrowFrom;

            // Create an id from the narrowTo type...
            String id = RepositoryId.createForAnyType(narrowTo);

            if (narrowObj._is_a(id)) {
                return Utility.loadStub(narrowObj,narrowTo);
            } else {
                throw new ClassCastException( "Object is not of remote type " +
                    narrowTo.getName() ) ;
            }
        } else {
            throw new ClassCastException( "Class " + narrowTo.getName() +
                " is not a valid remote interface" ) ;
        }
    } catch(Exception error) {
        ClassCastException cce = new ClassCastException() ;
        cce.initCause( error ) ;
        throw cce ;
    }
}
 
Example 15
Source File: PortableRemoteObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks to ensure that an object of a remote or abstract interface type
 * can be cast to a desired type.
 * @param narrowFrom the object to check.
 * @param narrowTo the desired type.
 * @return an object which can be cast to the desired type.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public java.lang.Object narrow ( java.lang.Object narrowFrom,
    java.lang.Class narrowTo) throws ClassCastException
{
    java.lang.Object result = null;

    if (narrowFrom == null)
        return null;

    if (narrowTo == null)
        throw new NullPointerException("invalid argument");

    try {
        if (narrowTo.isAssignableFrom(narrowFrom.getClass()))
            return narrowFrom;

        // Is narrowTo an interface that might be
        // implemented by a servant running on iiop?
        if (narrowTo.isInterface() &&
            narrowTo != java.io.Serializable.class &&
            narrowTo != java.io.Externalizable.class) {

            org.omg.CORBA.Object narrowObj
                = (org.omg.CORBA.Object) narrowFrom;

            // Create an id from the narrowTo type...
            String id = RepositoryId.createForAnyType(narrowTo);

            if (narrowObj._is_a(id)) {
                return Utility.loadStub(narrowObj,narrowTo);
            } else {
                throw new ClassCastException( "Object is not of remote type " +
                    narrowTo.getName() ) ;
            }
        } else {
            throw new ClassCastException( "Class " + narrowTo.getName() +
                " is not a valid remote interface" ) ;
        }
    } catch(Exception error) {
        ClassCastException cce = new ClassCastException() ;
        cce.initCause( error ) ;
        throw cce ;
    }
}
 
Example 16
Source File: PortableRemoteObject.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks to ensure that an object of a remote or abstract interface type
 * can be cast to a desired type.
 * @param narrowFrom the object to check.
 * @param narrowTo the desired type.
 * @return an object which can be cast to the desired type.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public java.lang.Object narrow ( java.lang.Object narrowFrom,
    java.lang.Class narrowTo) throws ClassCastException
{
    java.lang.Object result = null;

    if (narrowFrom == null)
        return null;

    if (narrowTo == null)
        throw new NullPointerException("invalid argument");

    try {
        if (narrowTo.isAssignableFrom(narrowFrom.getClass()))
            return narrowFrom;

        // Is narrowTo an interface that might be
        // implemented by a servant running on iiop?
        if (narrowTo.isInterface() &&
            narrowTo != java.io.Serializable.class &&
            narrowTo != java.io.Externalizable.class) {

            org.omg.CORBA.Object narrowObj
                = (org.omg.CORBA.Object) narrowFrom;

            // Create an id from the narrowTo type...
            String id = RepositoryId.createForAnyType(narrowTo);

            if (narrowObj._is_a(id)) {
                return Utility.loadStub(narrowObj,narrowTo);
            } else {
                throw new ClassCastException( "Object is not of remote type " +
                    narrowTo.getName() ) ;
            }
        } else {
            throw new ClassCastException( "Class " + narrowTo.getName() +
                " is not a valid remote interface" ) ;
        }
    } catch(Exception error) {
        ClassCastException cce = new ClassCastException() ;
        cce.initCause( error ) ;
        throw cce ;
    }
}
 
Example 17
Source File: PortableRemoteObject.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Checks to ensure that an object of a remote or abstract interface type
 * can be cast to a desired type.
 * @param narrowFrom the object to check.
 * @param narrowTo the desired type.
 * @return an object which can be cast to the desired type.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public java.lang.Object narrow ( java.lang.Object narrowFrom,
    java.lang.Class narrowTo) throws ClassCastException
{
    java.lang.Object result = null;

    if (narrowFrom == null)
        return null;

    if (narrowTo == null)
        throw new NullPointerException("invalid argument");

    try {
        if (narrowTo.isAssignableFrom(narrowFrom.getClass()))
            return narrowFrom;

        // Is narrowTo an interface that might be
        // implemented by a servant running on iiop?
        if (narrowTo.isInterface() &&
            narrowTo != java.io.Serializable.class &&
            narrowTo != java.io.Externalizable.class) {

            org.omg.CORBA.Object narrowObj
                = (org.omg.CORBA.Object) narrowFrom;

            // Create an id from the narrowTo type...
            String id = RepositoryId.createForAnyType(narrowTo);

            if (narrowObj._is_a(id)) {
                return Utility.loadStub(narrowObj,narrowTo);
            } else {
                throw new ClassCastException( "Object is not of remote type " +
                    narrowTo.getName() ) ;
            }
        } else {
            throw new ClassCastException( "Class " + narrowTo.getName() +
                " is not a valid remote interface" ) ;
        }
    } catch(Exception error) {
        ClassCastException cce = new ClassCastException() ;
        cce.initCause( error ) ;
        throw cce ;
    }
}
 
Example 18
Source File: PortableRemoteObject.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks to ensure that an object of a remote or abstract interface type
 * can be cast to a desired type.
 * @param narrowFrom the object to check.
 * @param narrowTo the desired type.
 * @return an object which can be cast to the desired type.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public java.lang.Object narrow ( java.lang.Object narrowFrom,
    java.lang.Class narrowTo) throws ClassCastException
{
    java.lang.Object result = null;

    if (narrowFrom == null)
        return null;

    if (narrowTo == null)
        throw new NullPointerException("invalid argument");

    try {
        if (narrowTo.isAssignableFrom(narrowFrom.getClass()))
            return narrowFrom;

        // Is narrowTo an interface that might be
        // implemented by a servant running on iiop?
        if (narrowTo.isInterface() &&
            narrowTo != java.io.Serializable.class &&
            narrowTo != java.io.Externalizable.class) {

            org.omg.CORBA.Object narrowObj
                = (org.omg.CORBA.Object) narrowFrom;

            // Create an id from the narrowTo type...
            String id = RepositoryId.createForAnyType(narrowTo);

            if (narrowObj._is_a(id)) {
                return Utility.loadStub(narrowObj,narrowTo);
            } else {
                throw new ClassCastException( "Object is not of remote type " +
                    narrowTo.getName() ) ;
            }
        } else {
            throw new ClassCastException( "Class " + narrowTo.getName() +
                " is not a valid remote interface" ) ;
        }
    } catch(Exception error) {
        ClassCastException cce = new ClassCastException() ;
        cce.initCause( error ) ;
        throw cce ;
    }
}
 
Example 19
Source File: PortableRemoteObject.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks to ensure that an object of a remote or abstract interface type
 * can be cast to a desired type.
 * @param narrowFrom the object to check.
 * @param narrowTo the desired type.
 * @return an object which can be cast to the desired type.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public java.lang.Object narrow ( java.lang.Object narrowFrom,
    java.lang.Class narrowTo) throws ClassCastException
{
    java.lang.Object result = null;

    if (narrowFrom == null)
        return null;

    if (narrowTo == null)
        throw new NullPointerException("invalid argument");

    try {
        if (narrowTo.isAssignableFrom(narrowFrom.getClass()))
            return narrowFrom;

        // Is narrowTo an interface that might be
        // implemented by a servant running on iiop?
        if (narrowTo.isInterface() &&
            narrowTo != java.io.Serializable.class &&
            narrowTo != java.io.Externalizable.class) {

            org.omg.CORBA.Object narrowObj
                = (org.omg.CORBA.Object) narrowFrom;

            // Create an id from the narrowTo type...
            String id = RepositoryId.createForAnyType(narrowTo);

            if (narrowObj._is_a(id)) {
                return Utility.loadStub(narrowObj,narrowTo);
            } else {
                throw new ClassCastException( "Object is not of remote type " +
                    narrowTo.getName() ) ;
            }
        } else {
            throw new ClassCastException( "Class " + narrowTo.getName() +
                " is not a valid remote interface" ) ;
        }
    } catch(Exception error) {
        ClassCastException cce = new ClassCastException() ;
        cce.initCause( error ) ;
        throw cce ;
    }
}
 
Example 20
Source File: PortableRemoteObject.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Checks to ensure that an object of a remote or abstract interface type
 * can be cast to a desired type.
 * @param narrowFrom the object to check.
 * @param narrowTo the desired type.
 * @return an object which can be cast to the desired type.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public java.lang.Object narrow ( java.lang.Object narrowFrom,
    java.lang.Class narrowTo) throws ClassCastException
{
    java.lang.Object result = null;

    if (narrowFrom == null)
        return null;

    if (narrowTo == null)
        throw new NullPointerException("invalid argument");

    try {
        if (narrowTo.isAssignableFrom(narrowFrom.getClass()))
            return narrowFrom;

        // Is narrowTo an interface that might be
        // implemented by a servant running on iiop?
        if (narrowTo.isInterface() &&
            narrowTo != java.io.Serializable.class &&
            narrowTo != java.io.Externalizable.class) {

            org.omg.CORBA.Object narrowObj
                = (org.omg.CORBA.Object) narrowFrom;

            // Create an id from the narrowTo type...
            String id = RepositoryId.createForAnyType(narrowTo);

            if (narrowObj._is_a(id)) {
                return Utility.loadStub(narrowObj,narrowTo);
            } else {
                throw new ClassCastException( "Object is not of remote type " +
                    narrowTo.getName() ) ;
            }
        } else {
            throw new ClassCastException( "Class " + narrowTo.getName() +
                " is not a valid remote interface" ) ;
        }
    } catch(Exception error) {
        ClassCastException cce = new ClassCastException() ;
        cce.initCause( error ) ;
        throw cce ;
    }
}