001: /*
002: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024:
025: package com.sun.jumpimpl.ixc;
026:
027: import java.rmi.registry.Registry;
028: import java.rmi.*;
029: import java.lang.reflect.Method;
030: import java.util.HashMap;
031: import java.util.Iterator;
032: import javax.microedition.xlet.XletContext;
033: import javax.microedition.xlet.ixc.StubException;
034:
035: /*
036: * A pre-generated Stub class for JUMPExecIxcRegistry.
037: * Clinet VMs use this class to talk with master IxcRegistry.
038: */
039:
040: public final class JUMPExecIxcRegistryStub extends StubObject implements
041: JUMPExecIxcRegistryRemote {
042:
043: static RemoteRef this Ref;
044: static HashMap methodIDsByName = new HashMap();
045:
046: static private boolean isInitialized = false;
047:
048: private static RemoteRef initialize() {
049: if (!isInitialized) {
050: isInitialized = true;
051: try {
052: RemoteObjectType type = new RemoteObjectType(
053: JUMPExecIxcRegistryRemote.class);
054:
055: this Ref = new RemoteRef(ExportedObject.newObjectID(),
056: ConnectionReceiver.getExecVMServicePort(),
057: Utils.getMtaskServerID(), type
058: .getRemoteInterfaceNames(), type
059: .getMethodIDsAslongs());
060:
061: Iterator iterator = type.methodsByID.keySet()
062: .iterator();
063: while (iterator.hasNext()) {
064: Long id = (Long) iterator.next();
065: Method m = (Method) type.methodsByID.get(id);
066: methodIDsByName.put(m.getName(), id);
067: }
068:
069: } catch (RemoteException e) {
070: System.err.println("Fatal error in starting IXC");
071: throw new RuntimeException(e.getCause());
072: }
073: }
074:
075: return this Ref;
076: }
077:
078: public JUMPExecIxcRegistryStub(XletContext context) {
079: // Arguments are of RemoteRef and XletContext, for it's ClassLoader.
080: super (initialize(), context);
081: }
082:
083: public long getMethodID(String s) {
084: Long l = (Long) methodIDsByName.get(s);
085: if (l != null)
086: return l.longValue();
087: else
088: return 0x0;
089: }
090:
091: public Remote lookup(String name) throws RemoteException,
092: NotBoundException, AccessException {
093:
094: try {
095: Object r = com_sun_xlet_execute(getMethodID("lookup"),
096: new Object[] { name });
097: return (Remote) r;
098: } catch (RemoteException re) {
099: throw re;
100: } catch (NotBoundException nbe) {
101: throw nbe;
102: } catch (Exception e) {
103: new StubException("", e);
104: }
105: return null;
106: }
107:
108: public Remote lookupWithXletID(String name, int xletID)
109: throws RemoteException, NotBoundException, AccessException {
110:
111: try {
112: Object r = com_sun_xlet_execute(
113: getMethodID("lookupWithXletID"), new Object[] {
114: name, new Integer(xletID) });
115: return (Remote) r;
116: } catch (RemoteException re) {
117: throw re;
118: } catch (NotBoundException nbe) {
119: throw nbe;
120: } catch (Exception e) {
121: new StubException("", e);
122: }
123: return null;
124: }
125:
126: public void bind(String name, Remote obj) throws RemoteException,
127: AlreadyBoundException, AccessException {
128:
129: try {
130: com_sun_xlet_execute(getMethodID("bind"), new Object[] {
131: name, obj });
132: } catch (RemoteException re) {
133: throw re;
134: } catch (AlreadyBoundException nbe) {
135: throw nbe;
136: } catch (Exception e) {
137: new StubException("", e);
138: }
139: }
140:
141: public void unbind(String name) throws RemoteException,
142: NotBoundException, AccessException {
143: try {
144: com_sun_xlet_execute(getMethodID("unbind"),
145: new Object[] { name });
146: } catch (RemoteException re) {
147: throw re;
148: } catch (NotBoundException nbe) {
149: throw nbe;
150: } catch (Exception e) {
151: new StubException("", e);
152: }
153: }
154:
155: public void rebind(String name, Remote obj) throws RemoteException,
156: AccessException {
157: try {
158: com_sun_xlet_execute(getMethodID("rebind"), new Object[] {
159: name, obj });
160: } catch (RemoteException re) {
161: throw re;
162: } catch (Exception e) {
163: new StubException("", e);
164: }
165: }
166:
167: public String[] list() throws RemoteException, AccessException {
168: try {
169: Object r = com_sun_xlet_execute(getMethodID("list"),
170: new Object[] {});
171: return (String[]) r;
172: } catch (RemoteException re) {
173: throw re;
174: } catch (Exception e) {
175: new StubException("", e);
176: }
177: return null;
178: }
179:
180: public void notifyObjectImport(int importingXletID, Remote obj) {
181: try {
182: com_sun_xlet_execute(getMethodID("notifyObjectImport"),
183: new Object[] { new Integer(importingXletID), obj });
184: } catch (Exception e) {
185: e.printStackTrace();
186: }
187: }
188: }
|