blob: ba47fc0d190fb523b088e076fb78ee8e2d808789 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1999-2004 Sun Microsystems, Inc. All Rights Reserved.
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
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
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 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.jndi.cosnaming;
27
28import javax.naming.*;
29import javax.naming.spi.StateFactory;
30import java.util.Hashtable;
31
32import org.omg.CORBA.ORB;
33
34import java.rmi.Remote;
35import java.rmi.server.ExportException;
36
37import com.sun.jndi.toolkit.corba.CorbaUtils; // for RMI-IIOP
38
39/**
40 * StateFactory that turns java.rmi.Remote objects to org.omg.CORBA.Object.
41 *
42 * @author Rosanna Lee
43 */
44
45public class RemoteToCorba implements StateFactory {
46 public RemoteToCorba() {
47 }
48
49 /**
50 * Returns the CORBA object for a Remote object.
51 * If input is not a Remote object, or if Remote object uses JRMP, return null.
52 * If the RMI-IIOP library is not available, throw ConfigurationException.
53 *
54 * @param orig The object to turn into a CORBA object. If not Remote,
55 * or if is a JRMP stub or impl, return null.
56 * @param name Ignored
57 * @param ctx The non-null CNCtx whose ORB to use.
58 * @param env Ignored
59 * @return The CORBA object for <tt>orig</tt> or null.
60 * @exception ConfigurationException If the CORBA object cannot be obtained
61 * due to configuration problems, for instance, if RMI-IIOP not available.
62 * @exception NamingException If some other problem prevented a CORBA
63 * object from being obtained from the Remote object.
64 */
65 public Object getStateToBind(Object orig, Name name, Context ctx,
66 Hashtable<?,?> env) throws NamingException {
67 if (orig instanceof org.omg.CORBA.Object) {
68 // Already a CORBA object, just use it
69 return null;
70 }
71
72 if (orig instanceof Remote) {
73 // Turn remote object into org.omg.CORBA.Object
74 try {
75 // Returns null if JRMP; let next factory try
76 // CNCtx will eventually throw IllegalArgumentException if
77 // no CORBA object gotten
78 return
79 CorbaUtils.remoteToCorba((Remote)orig, ((CNCtx)ctx)._orb);
80 } catch (ClassNotFoundException e) {
81 // RMI-IIOP library not available
82 throw new ConfigurationException(
83 "javax.rmi packages not available");
84 }
85 }
86 return null; // pass and let next state factory try
87 }
88}