01: /*
02: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License version
07: * 2 only, as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful, but
10: * WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * General Public License version 2 for more details (a copy is
13: * included at /legal/license.txt).
14: *
15: * You should have received a copy of the GNU General Public License
16: * version 2 along with this work; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18: * 02110-1301 USA
19: *
20: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
21: * Clara, CA 95054 or visit www.sun.com if you need additional
22: * information or have any questions.
23: */
24:
25: package com.sun.jumpimpl.client.module.serviceregistry;
26:
27: import java.rmi.Remote;
28: import java.rmi.RemoteException;
29: import java.rmi.NotBoundException;
30: import javax.microedition.xlet.Xlet;
31: import javax.microedition.xlet.XletContext;
32: import javax.microedition.xlet.ixc.IxcRegistry;
33: import javax.microedition.xlet.ixc.StubException;
34:
35: import com.sun.jumpimpl.ixc.XletContextFactory;
36: import com.sun.jumpimpl.ixc.ConnectionReceiver;
37:
38: import com.sun.jumpimpl.process.JUMPModulesConfig;
39: import com.sun.jump.isolate.jvmprocess.JUMPIsolateProcess;
40:
41: public class ServiceRegistryClient {
42:
43: IxcRegistry registry;
44:
45: /**
46: *
47: * @param classloader class loader to use
48: */
49: public ServiceRegistryClient(ClassLoader classloader, int portNumber) {
50:
51: /*
52: * First set the port number that the executive VM's registry is
53: * accepting connection at.
54: *
55: * FIXME: this port number setup should go away once IXC is on messaging.
56: */
57:
58: ConnectionReceiver.setExecVMServicePort(portNumber);
59:
60: /*
61: * Grab the IxcRegistry instance for the client VM.
62: * Use the system classloader to get the registry. This classloader
63: * would later be used for loading the stub classes for the remote objects.
64: */
65: XletContext context = XletContextFactory
66: .getXletContext(classloader);
67:
68: registry = IxcRegistry.getRegistry(context);
69: }
70:
71: public Remote getRemoteService(String name) {
72: try {
73: return registry.lookup(name);
74: } catch (StubException e) {
75: e.printStackTrace();
76: } catch (NotBoundException e) {
77: System.err.println(name + " not found in the registry");
78: } catch (SecurityException e) { // shouldn't happen
79: e.printStackTrace();
80: }
81:
82: return null;
83: }
84: }
|