Java Code Examples for javax.rmi.PortableRemoteObject#narrow()

The following examples show how to use javax.rmi.PortableRemoteObject#narrow() . 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: Client.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static CMXATest lookupCMXABean(InitialContext ictx, String jndiName) {
    try {
        Object home = ictx.lookup(jndiName);
        CMXATestHome rhome = (CMXATestHome) PortableRemoteObject.narrow(
                home, CMXATestHome.class);
        CMXATest bean = (CMXATest) PortableRemoteObject.narrow(
                rhome.create(), CMXATest.class);
        return bean;
    } catch (NamingException ne) {
        log("The client was unable to lookup the EJBHome.  Please make sure ");
        log("that you have deployed the ejb with the JNDI name " + jndiName
                + " on the WebLogic server at " + url);
    } catch (CreateException ce) {
        log("Creation failed: " + ce);
    } catch (RemoteException ex) {
        log("Creation failed: " + ex);
    }
    return null;
}
 
Example 2
Source File: Client.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static CMXATest lookupCMXABean(InitialContext ictx, String jndiName) {
    try {
        Object home = ictx.lookup(jndiName);
        CMXATestHome rhome = (CMXATestHome) PortableRemoteObject.narrow(
                home, CMXATestHome.class);
        CMXATest bean = (CMXATest) PortableRemoteObject.narrow(
                rhome.create(), CMXATest.class);
        return bean;
    } catch (NamingException ne) {
        log("The client was unable to lookup the EJBHome.  Please make sure ");
        log("that you have deployed the ejb with the JNDI name " + jndiName
                + " on the WebLogic server at " + url);
    } catch (CreateException ce) {
        log("Creation failed: " + ce);
    } catch (RemoteException ex) {
        log("Creation failed: " + ex);
    }
    return null;
}
 
Example 3
Source File: Utility.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read an abstract interface type from the input stream and narrow
 * it to the desired type.
 * @param in the stream to read from.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public static Object readAbstractAndNarrow(
    org.omg.CORBA_2_3.portable.InputStream in, Class narrowTo)
    throws ClassCastException
{
    Object result = in.read_abstract_interface();
    if (result != null)
        return PortableRemoteObject.narrow(result, narrowTo);
    else
        return null;
}
 
Example 4
Source File: AbstractRemoteSlsbInvokerInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This overridden lookup implementation performs a narrow operation
 * after the JNDI lookup, provided that a home interface is specified.
 * @see #setHomeInterface
 * @see javax.rmi.PortableRemoteObject#narrow
 */
@Override
protected Object lookup() throws NamingException {
	Object homeObject = super.lookup();
	if (this.homeInterface != null) {
		try {
			homeObject = PortableRemoteObject.narrow(homeObject, this.homeInterface);
		}
		catch (ClassCastException ex) {
			throw new RemoteLookupFailureException(
					"Could not narrow EJB home stub to home interface [" + this.homeInterface.getName() + "]", ex);
		}
	}
	return homeObject;
}
 
Example 5
Source File: Utility.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read an object reference from the input stream and narrow
 * it to the desired type.
 * @param in the stream to read from.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public static Object readObjectAndNarrow(InputStream in,
                                         Class narrowTo)
    throws ClassCastException
{
    Object result = in.read_Object();
    if (result != null)
        return PortableRemoteObject.narrow(result, narrowTo);
    else
        return null;
}
 
Example 6
Source File: Utility.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read an abstract interface type from the input stream and narrow
 * it to the desired type.
 * @param in the stream to read from.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public static Object readAbstractAndNarrow(
    org.omg.CORBA_2_3.portable.InputStream in, Class narrowTo)
    throws ClassCastException
{
    Object result = in.read_abstract_interface();
    if (result != null)
        return PortableRemoteObject.narrow(result, narrowTo);
    else
        return null;
}
 
Example 7
Source File: AbstractRemoteSlsbInvokerInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * This overridden lookup implementation performs a narrow operation
 * after the JNDI lookup, provided that a home interface is specified.
 * @see #setHomeInterface
 * @see javax.rmi.PortableRemoteObject#narrow
 */
@Override
protected Object lookup() throws NamingException {
	Object homeObject = super.lookup();
	if (this.homeInterface != null) {
		try {
			homeObject = PortableRemoteObject.narrow(homeObject, this.homeInterface);
		}
		catch (ClassCastException ex) {
			throw new RemoteLookupFailureException(
					"Could not narrow EJB home stub to home interface [" + this.homeInterface.getName() + "]", ex);
		}
	}
	return homeObject;
}
 
Example 8
Source File: Utility.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read an abstract interface type from the input stream and narrow
 * it to the desired type.
 * @param in the stream to read from.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public static Object readAbstractAndNarrow(
    org.omg.CORBA_2_3.portable.InputStream in, Class narrowTo)
    throws ClassCastException
{
    Object result = in.read_abstract_interface();
    if (result != null)
        return PortableRemoteObject.narrow(result, narrowTo);
    else
        return null;
}
 
Example 9
Source File: Utility.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read an abstract interface type from the input stream and narrow
 * it to the desired type.
 * @param in the stream to read from.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public static Object readAbstractAndNarrow(
    org.omg.CORBA_2_3.portable.InputStream in, Class narrowTo)
    throws ClassCastException
{
    Object result = in.read_abstract_interface();
    if (result != null)
        return PortableRemoteObject.narrow(result, narrowTo);
    else
        return null;
}
 
Example 10
Source File: Utility.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read an object reference from the input stream and narrow
 * it to the desired type.
 * @param in the stream to read from.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public static Object readObjectAndNarrow(InputStream in,
                                         Class narrowTo)
    throws ClassCastException
{
    Object result = in.read_Object();
    if (result != null)
        return PortableRemoteObject.narrow(result, narrowTo);
    else
        return null;
}
 
Example 11
Source File: Utility.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read an object reference from the input stream and narrow
 * it to the desired type.
 * @param in the stream to read from.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public static Object readObjectAndNarrow(InputStream in,
                                         Class narrowTo)
    throws ClassCastException
{
    Object result = in.read_Object();
    if (result != null)
        return PortableRemoteObject.narrow(result, narrowTo);
    else
        return null;
}
 
Example 12
Source File: Utility.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read an abstract interface type from the input stream and narrow
 * it to the desired type.
 * @param in the stream to read from.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public static Object readAbstractAndNarrow(
    org.omg.CORBA_2_3.portable.InputStream in, Class narrowTo)
    throws ClassCastException
{
    Object result = in.read_abstract_interface();
    if (result != null)
        return PortableRemoteObject.narrow(result, narrowTo);
    else
        return null;
}
 
Example 13
Source File: Utility.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read an object reference from the input stream and narrow
 * it to the desired type.
 * @param in the stream to read from.
 * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
 */
public static Object readObjectAndNarrow(InputStream in,
                                         Class narrowTo)
    throws ClassCastException
{
    Object result = in.read_Object();
    if (result != null)
        return PortableRemoteObject.narrow(result, narrowTo);
    else
        return null;
}
 
Example 14
Source File: IIOPProxyImpl.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T narrow(Object narrowFrom, Class<T> narrowTo) {
    return (T)PortableRemoteObject.narrow(narrowFrom, narrowTo);
}
 
Example 15
Source File: MoviesServlet.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    try {

        final PrintWriter pw = resp.getWriter();

        final Context initial = new InitialContext();

        final MoviesBusinessHome home = (MoviesBusinessHome)
                PortableRemoteObject.narrow(initial.lookup("java:comp/env/ejb/MoviesBusiness"), MoviesBusinessHome.class);

        final MoviesBusiness moviesBusiness = home.create();
        moviesBusiness.doLogic();

        final DataSource ds = (DataSource) initial.lookup("java:comp/env/db/DataSource");
        try (final Connection connection = ds.getConnection();
             final PreparedStatement ps = connection.prepareStatement(
                     "select TABLE_NAME, COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH " +
                             "from INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = 'PUBLIC' and TABLE_NAME in ('ACTOR', 'MOVIE', 'ACTOR_MOVIE')");

             final ResultSet rs = ps.executeQuery()) {

            final ResultSetMetaData metaData = rs.getMetaData();
            final int columnCount = metaData.getColumnCount();

            final String[] columnNames = new String[columnCount];

            for (int c = 0; c < columnCount; c++) {
                columnNames[c] = metaData.getColumnName(c + 1);
            }

            while (rs.next()) {
                final StringBuilder sb = new StringBuilder();

                for (int c = 0; c < columnCount; c++) {
                    if (c > 0) {
                        sb.append(", ");
                    }

                    sb.append(columnNames[c]).append(": ").append(rs.getString(c + 1));
                }

                pw.println(sb.toString());
            }
        }

        pw.flush();

    } catch (final Exception ex) {
        throw new ServletException(ex);
    }
}
 
Example 16
Source File: IIOPProxyImpl.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T narrow(Object narrowFrom, Class<T> narrowTo) {
    return (T)PortableRemoteObject.narrow(narrowFrom, narrowTo);
}
 
Example 17
Source File: IIOPProxyImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T narrow(Object narrowFrom, Class<T> narrowTo) {
    return (T)PortableRemoteObject.narrow(narrowFrom, narrowTo);
}
 
Example 18
Source File: BookShopBean.java    From Java-EE-8-Sampler with MIT License 4 votes vote down vote up
public List<Book> listBooks() throws RemoteException, NamingException {
    Object obj = new InitialContext().lookup("java:comp/env/ejb/BookHomeRemote");
    BookHomeRemote home = (BookHomeRemote) PortableRemoteObject.narrow(obj, BookHomeRemote.class);
    return home.listBooks();
}
 
Example 19
Source File: IIOPProxyImpl.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T narrow(Object narrowFrom, Class<T> narrowTo) {
    return (T)PortableRemoteObject.narrow(narrowFrom, narrowTo);
}
 
Example 20
Source File: IIOPProxyImpl.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T narrow(Object narrowFrom, Class<T> narrowTo) {
    return (T)PortableRemoteObject.narrow(narrowFrom, narrowTo);
}