001: /*
002: * @(#)IxcRegistry.java 1.19 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package javax.microedition.xlet.ixc;
029:
030: import java.lang.reflect.Method;
031: import java.rmi.*;
032: import java.rmi.registry.Registry;
033: import java.util.Hashtable;
034: import javax.microedition.xlet.XletContext;
035:
036: /**
037: * <code>IXCRegistry</code> is the bootstrap mechanism for obtaining
038: * references to remote objects residing in other Xlets executing on
039: * the same machine, but in separate classloaders.
040: *
041: * <p>
042: * Instances of <code>IXCRegistry</code> are never accessible via
043: * <code>java.rmi.Naming</code> or
044: * <code>java.rmi.registry.LocateRegistry</code> if RMI functionality
045: * is implemented.
046: *
047: * @see java.rmi.Registry
048: */
049:
050: public abstract class IxcRegistry implements Registry {
051: /**
052: * Creates the IxcRegistry instance.
053: */
054: protected IxcRegistry() {
055: }
056:
057: static boolean isPlatformChecked = false;
058: static Method getRegistryImplMethod = null;
059:
060: static String svmIxcRegistryName = "com.sun.xlet.ixc.IxcRegistryImpl";
061: static String mvmIxcRegistryName = "com.sun.jumpimpl.ixc.JUMPIxcRegistryImpl";
062:
063: /**
064: * Returns the Inter-Xlet Communication registry.
065: */
066: public static IxcRegistry getRegistry(XletContext context) {
067:
068: if (context == null)
069: throw new NullPointerException("XletContext is null");
070:
071: if (getRegistryImplMethod == null) {
072: Class ixcRegistryImplClass = null;
073: try {
074: ixcRegistryImplClass = Class
075: .forName(svmIxcRegistryName);
076: } catch (Exception e) { // Not found, let's try MVM.
077: }
078:
079: if (ixcRegistryImplClass == null) {
080: try {
081: ixcRegistryImplClass = Class
082: .forName(mvmIxcRegistryName);
083: } catch (Exception e) { // Problem. ixcRegistryImplClass remains null.
084: }
085: }
086:
087: if (ixcRegistryImplClass == null) {
088: System.out.println("Fatal error in starting IXC: ");
089: System.out.println("Neither " + svmIxcRegistryName
090: + " or " + mvmIxcRegistryName + " is found.");
091:
092: return null;
093: }
094:
095: try {
096: getRegistryImplMethod = ixcRegistryImplClass
097: .getMethod(
098: "getIxcRegistryImpl",
099: new Class[] { javax.microedition.xlet.XletContext.class });
100: } catch (NoSuchMethodException nsme) {
101: nsme.printStackTrace();
102: } catch (SecurityException se) {
103: se.printStackTrace();
104: }
105: }
106:
107: try {
108: if (getRegistryImplMethod != null) {
109: return (IxcRegistry) getRegistryImplMethod.invoke(null,
110: new Object[] { context });
111: }
112: } catch (Exception e) {
113: e.printStackTrace();
114: }
115:
116: return null;
117: }
118:
119: /**
120: * Returns a reference, a stub, for the remote object associated
121: * with the specified <code>name</code>.
122: *
123: * @param name a URL-formatted name for the remote object
124: * @return a reference for a remote object
125: * @exception NotBoundException if name is not currently bound
126: * @exception StubException If a stub could not be generated
127: */
128:
129: public abstract Remote lookup(String name) throws StubException,
130: NotBoundException;
131:
132: /**
133: * Binds the specified <code>name</code> to a remote object.
134: *
135: * @param name a URL-formatted name for the remote object
136: * @param obj a reference for the remote object (usually a stub)
137: * @exception AlreadyBoundException if name is already bound
138: * @exception MalformedURLException if the name is not an appropriately
139: * formatted URL
140: * @exception RemoteException if registry could not be contacted
141: */
142: public abstract void bind(String name, Remote obj)
143: throws StubException, AlreadyBoundException;
144:
145: /**
146: * Destroys the binding for the specified name that is associated
147: * with a remote object.
148: *
149: * @param name a URL-formatted name associated with a remote object
150: * @exception NotBoundException if name is not currently bound
151: */
152: public abstract void unbind(String name) throws NotBoundException,
153: AccessException;
154:
155: /**
156: * Rebinds the specified name to a new remote object. Any existing
157: * binding for the name is replaced.
158: *
159: * @param name a URL-formatted name associated with the remote object
160: * @param obj new remote object to associate with the name
161: * @exception MalformedURLException if the name is not an appropriately
162: * formatted URL
163: * @exception RemoteException if registry could not be contacted
164: * @exception AccessException if this operation is not permitted (if
165: * originating from a non-local host, for example)
166: */
167: public abstract void rebind(String name, Remote obj)
168: throws StubException, AccessException;
169:
170: /**
171: * Returns an array of the names bound in the registry. The names are
172: * URL-formatted strings. The array contains a snapshot of the names
173: * present in the registry at the time of the call.
174: *
175: * @return an array of names (in the appropriate URL format) bound
176: * in the registry
177: * @exception RemoteException if registry could not be contacted
178: * @exception AccessException if this operation is not permitted (if
179: * originating from a non-local host, for example)
180: */
181: public abstract String[] list();
182:
183: /**
184: * Removes the bindings for all remote objects currently exported by
185: * the calling Xlet.
186: */
187: public abstract void unbindAll();
188:
189: }
|