aboutsummaryrefslogtreecommitdiff
path: root/libjava/gnu/java
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2001-08-28 00:03:35 +0000
committerTom Tromey <tromey@gcc.gnu.org>2001-08-28 00:03:35 +0000
commit83e7315b5fae7fc17b3ddcae2b6b1835620b3bc5 (patch)
tree0524f17b5bc6a9ba62b7ab93c70f5b39e858a828 /libjava/gnu/java
parentc5bb59c118038f25b2479b2513c36626a8df6cb3 (diff)
downloadgcc-83e7315b5fae7fc17b3ddcae2b6b1835620b3bc5.zip
gcc-83e7315b5fae7fc17b3ddcae2b6b1835620b3bc5.tar.gz
gcc-83e7315b5fae7fc17b3ddcae2b6b1835620b3bc5.tar.bz2
Activatable.java, [...]: RMI implementation from Kaffe.
* java/rmi/activation/Activatable.java, java/rmi/activation/ActivateFailedException.java, java/rmi/activation/ActivationDesc.java, java/rmi/activation/ActivationException.java, java/rmi/activation/ActivationGroup.java, java/rmi/activation/ActivationGroupDesc.java, java/rmi/activation/ActivationGroupID.java, java/rmi/activation/ActivationID.java, java/rmi/activation/ActivationInstantiator.java, java/rmi/activation/ActivationMonitor.java, java/rmi/activation/ActivationSystem.java, java/rmi/activation/Activator.java, java/rmi/activation/UnknownGroupException.java, java/rmi/activation/UnknownObjectException.java, java/rmi/AccessException.java, java/rmi/AlreadyBoundException.java, java/rmi/ConnectException.java, java/rmi/ConnectIOException.java, java/rmi/MarshalException.java, java/rmi/MarshalledObject.java, java/rmi/Naming.java, java/rmi/NoSuchObjectException.java, java/rmi/NotBoundException.java, java/rmi/RMISecurityException.java, java/rmi/RMISecurityManager.java, java/rmi/Remote.java, java/rmi/RemoteException.java, java/rmi/ServerError.java, java/rmi/ServerException.java, java/rmi/ServerRuntimeException.java, java/rmi/StubNotFoundException.java, java/rmi/UnexpectedException.java, java/rmi/UnknownHostException.java, java/rmi/UnmarshalException.java, java/rmi/dgc/DGC.java, java/rmi/dgc/Lease.java, java/rmi/dgc/VMID.java, java/rmi/registry/LocateRegistry.java, java/rmi/registry/Registry.java, java/rmi/registry/RegistryHandler.java, java/rmi/server/ExportException.java, java/rmi/server/LoaderHandler.java, java/rmi/server/LogStream.java, java/rmi/server/ObjID.java, java/rmi/server/Operation.java, java/rmi/server/RMIClassLoader.java, java/rmi/server/RMIClientSocketFactory.java, java/rmi/server/RMIFailureHandler.java, java/rmi/server/RMIServerSocketFactory.java, java/rmi/server/RMISocketFactory.java, java/rmi/server/RemoteCall.java, java/rmi/server/RemoteObject.java, java/rmi/server/RemoteRef.java, java/rmi/server/RemoteServer.java, java/rmi/server/RemoteStub.java, java/rmi/server/ServerCloneException.java, java/rmi/server/ServerNotActiveException.java, java/rmi/server/ServerRef.java, java/rmi/server/Skeleton.java, java/rmi/server/SkeletonMismatchException.java, java/rmi/server/SkeletonNotFoundException.java, java/rmi/server/SocketSecurityException.java, java/rmi/server/UID.java, java/rmi/server/UnicastRemoteObject.java, java/rmi/server/Unreferenced.java, gnu/java/rmi/dgc/DGCImpl.java, gnu/java/rmi/dgc/DGCImpl_Skel.java, gnu/java/rmi/dgc/DGCImpl_Stub.java, gnu/java/rmi/registry/RegistryImpl.java, gnu/java/rmi/registry/RegistryImpl_Skel.java, gnu/java/rmi/registry/RegistryImpl_Stub.java, gnu/java/rmi/rmic/RMIC.java, gnu/java/rmi/rmic/TabbedWriter.java, gnu/java/rmi/server/ProtocolConstants.java, gnu/java/rmi/server/RMIDefaultSocketFactory.java, gnu/java/rmi/server/RMIHashes.java, gnu/java/rmi/server/RMIObjectInputStream.java, gnu/java/rmi/server/RMIObjectOutputStream.java, gnu/java/rmi/server/UnicastConnection.java, gnu/java/rmi/server/UnicastConnectionManager.java, gnu/java/rmi/server/UnicastRef.java, gnu/java/rmi/server/UnicastRemoteCall.java, gnu/java/rmi/server/UnicastRemoteStub.java, gnu/java/rmi/server/UnicastServer.java, gnu/java/rmi/server/UnicastServerRef.java: RMI implementation from Kaffe. Relabelled classes to fit into Classpath tree. * Makefile.in: Rebuilt. * Makefile.am (rmi_java_source_files): New macro. (ordinary_java_source_files): Reference it. (bin_PROGRAMS): Added rmic and rmiregistry. (rmic_SOURCES): New macro. (EXTRA_rmic_SOURCES): Likewise. (rmic_LDFLAGS): Likewise. (rmic_LINK): Likewise. (rmic_LDADD): Likewise. (rmic_DEPENDENCIES): Likewise. (rmiregistry_SOURCES): New macro. (EXTRA_rmiregistry_SOURCES): Likewise. (rmiregistry_LDFLAGS): Likewise. (rmiregistry_LINK): Likewise. (rmiregistry_LDADD): Likewise. (rmiregistry_DEPENDENCIES): Likewise. From-SVN: r45218
Diffstat (limited to 'libjava/gnu/java')
-rw-r--r--libjava/gnu/java/rmi/dgc/DGCImpl.java55
-rw-r--r--libjava/gnu/java/rmi/dgc/DGCImpl_Skel.java106
-rw-r--r--libjava/gnu/java/rmi/dgc/DGCImpl_Stub.java120
-rw-r--r--libjava/gnu/java/rmi/registry/RegistryImpl.java115
-rw-r--r--libjava/gnu/java/rmi/registry/RegistryImpl_Skel.java189
-rw-r--r--libjava/gnu/java/rmi/registry/RegistryImpl_Stub.java255
-rw-r--r--libjava/gnu/java/rmi/rmic/RMIC.java982
-rw-r--r--libjava/gnu/java/rmi/rmic/TabbedWriter.java90
-rw-r--r--libjava/gnu/java/rmi/server/ProtocolConstants.java53
-rw-r--r--libjava/gnu/java/rmi/server/RMIDefaultSocketFactory.java49
-rw-r--r--libjava/gnu/java/rmi/server/RMIHashes.java45
-rw-r--r--libjava/gnu/java/rmi/server/RMIObjectInputStream.java65
-rw-r--r--libjava/gnu/java/rmi/server/RMIObjectOutputStream.java47
-rw-r--r--libjava/gnu/java/rmi/server/UnicastConnection.java162
-rw-r--r--libjava/gnu/java/rmi/server/UnicastConnectionManager.java262
-rw-r--r--libjava/gnu/java/rmi/server/UnicastRef.java219
-rw-r--r--libjava/gnu/java/rmi/server/UnicastRemoteCall.java301
-rw-r--r--libjava/gnu/java/rmi/server/UnicastRemoteStub.java40
-rw-r--r--libjava/gnu/java/rmi/server/UnicastServer.java119
-rw-r--r--libjava/gnu/java/rmi/server/UnicastServerRef.java198
20 files changed, 3472 insertions, 0 deletions
diff --git a/libjava/gnu/java/rmi/dgc/DGCImpl.java b/libjava/gnu/java/rmi/dgc/DGCImpl.java
new file mode 100644
index 0000000..2c07c14
--- /dev/null
+++ b/libjava/gnu/java/rmi/dgc/DGCImpl.java
@@ -0,0 +1,55 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.dgc;
+
+import java.rmi.dgc.DGC;
+import java.rmi.dgc.Lease;
+import java.rmi.dgc.VMID;
+import java.rmi.server.ObjID;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+import java.rmi.server.RMISocketFactory;
+import gnu.java.rmi.server.UnicastServerRef;
+
+public class DGCImpl
+ extends UnicastRemoteObject implements DGC {
+
+public DGCImpl() throws RemoteException {
+ super(new UnicastServerRef(new ObjID(ObjID.DGC_ID), 0, RMISocketFactory.getSocketFactory()));
+}
+
+public Lease dirty(ObjID[] ids, long sequenceNum, Lease lease) throws RemoteException {
+ System.out.println("DGCImpl.dirty - not implemented");
+ return (lease);
+}
+
+public void clean(ObjID[] ids, long sequenceNum, VMID vmid, boolean strong) throws RemoteException {
+ System.out.println("DGCImpl.clean - not implemented");
+}
+
+}
diff --git a/libjava/gnu/java/rmi/dgc/DGCImpl_Skel.java b/libjava/gnu/java/rmi/dgc/DGCImpl_Skel.java
new file mode 100644
index 0000000..fd0f2ee
--- /dev/null
+++ b/libjava/gnu/java/rmi/dgc/DGCImpl_Skel.java
@@ -0,0 +1,106 @@
+// Skel class generated by rmic - DO NOT EDIT!
+
+package gnu.java.rmi.dgc;
+
+public final class DGCImpl_Skel
+ implements java.rmi.server.Skeleton
+{
+ private static final long interfaceHash = -669196253586618813L;
+
+ private static final java.rmi.server.Operation[] operations = {
+ new java.rmi.server.Operation("void clean(java.rmi.server.ObjID[], long, java.rmi.dgc.VMID, boolean"),
+ new java.rmi.server.Operation("java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[], long, java.rmi.dgc.Lease")
+ };
+
+ public java.rmi.server.Operation[] getOperations() {
+ return ((java.rmi.server.Operation[]) operations.clone());
+ }
+
+ public void dispatch(java.rmi.Remote obj, java.rmi.server.RemoteCall call, int opnum, long hash) throws java.lang.Exception {
+ if (opnum < 0) {
+ if (hash == -5803803475088455571L) {
+ opnum = 0;
+ }
+ else if (hash == -8139341527526761862L) {
+ opnum = 1;
+ }
+ else {
+ throw new java.rmi.server.SkeletonMismatchException("interface hash mismatch");
+ }
+ }
+ else if (hash != interfaceHash) {
+ throw new java.rmi.server.SkeletonMismatchException("interface hash mismatch");
+ }
+
+ gnu.java.rmi.dgc.DGCImpl server = (gnu.java.rmi.dgc.DGCImpl)obj;
+ switch (opnum) {
+ case 0:
+ {
+ java.rmi.server.ObjID[] $param_0;
+ long $param_1;
+ java.rmi.dgc.VMID $param_2;
+ boolean $param_3;
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ $param_0 = (java.rmi.server.ObjID[])in.readObject();
+ $param_1 = (long)in.readLong();
+ $param_2 = (java.rmi.dgc.VMID)in.readObject();
+ $param_3 = (boolean)in.readBoolean();
+
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ catch (java.lang.ClassCastException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ finally {
+ call.releaseInputStream();
+ }
+ server.clean($param_0, $param_1, $param_2, $param_3);
+ try {
+ java.io.ObjectOutput out = call.getResultStream(true);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling return", e);
+ }
+ break;
+ }
+
+ case 1:
+ {
+ java.rmi.server.ObjID[] $param_0;
+ long $param_1;
+ java.rmi.dgc.Lease $param_2;
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ $param_0 = (java.rmi.server.ObjID[])in.readObject();
+ $param_1 = (long)in.readLong();
+ $param_2 = (java.rmi.dgc.Lease)in.readObject();
+
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ catch (java.lang.ClassCastException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ finally {
+ call.releaseInputStream();
+ }
+ java.rmi.dgc.Lease $result = server.dirty($param_0, $param_1, $param_2);
+ try {
+ java.io.ObjectOutput out = call.getResultStream(true);
+ out.writeObject($result);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling return", e);
+ }
+ break;
+ }
+
+ default:
+ throw new java.rmi.UnmarshalException("invalid method number");
+ }
+ }
+}
diff --git a/libjava/gnu/java/rmi/dgc/DGCImpl_Stub.java b/libjava/gnu/java/rmi/dgc/DGCImpl_Stub.java
new file mode 100644
index 0000000..e611fb2
--- /dev/null
+++ b/libjava/gnu/java/rmi/dgc/DGCImpl_Stub.java
@@ -0,0 +1,120 @@
+// Stub class generated by rmic - DO NOT EDIT!
+
+package gnu.java.rmi.dgc;
+
+public final class DGCImpl_Stub
+ extends java.rmi.server.RemoteStub
+ implements java.rmi.dgc.DGC
+{
+ private static final long serialVersionUID = 2L;
+
+ private static final long interfaceHash = -669196253586618813L;
+
+ private static boolean useNewInvoke;
+
+ private static final java.rmi.server.Operation[] operations = {
+ new java.rmi.server.Operation("void clean(java.rmi.server.ObjID[], long, java.rmi.dgc.VMID, boolean)"),
+ new java.rmi.server.Operation("java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[], long, java.rmi.dgc.Lease)")
+ };
+
+ private static java.lang.reflect.Method $method_clean_0;
+ private static java.lang.reflect.Method $method_dirty_1;
+
+ static {
+ try {
+ java.rmi.server.RemoteRef.class.getMethod("invoke", new java.lang.Class[] { java.rmi.Remote.class, java.lang.reflect.Method.class, java.lang.Object[].class, long.class });
+ useNewInvoke = true;
+ $method_clean_0 = gnu.java.rmi.dgc.DGCImpl.class.getMethod("clean", new java.lang.Class[] {java.rmi.server.ObjID[].class, long.class, java.rmi.dgc.VMID.class, boolean.class});
+ $method_dirty_1 = gnu.java.rmi.dgc.DGCImpl.class.getMethod("dirty", new java.lang.Class[] {java.rmi.server.ObjID[].class, long.class, java.rmi.dgc.Lease.class});
+
+ }
+ catch (java.lang.NoSuchMethodException e) {
+ useNewInvoke = false;
+ }
+ }
+
+ public DGCImpl_Stub() {
+ super();
+ }
+ public DGCImpl_Stub(java.rmi.server.RemoteRef ref) {
+ super(ref);
+ }
+
+ public void clean(java.rmi.server.ObjID[] $param_0, long $param_1, java.rmi.dgc.VMID $param_2, boolean $param_3) throws java.rmi.RemoteException {
+ try {
+ if (useNewInvoke) {
+ ref.invoke(this, $method_clean_0, new java.lang.Object[] {$param_0, new java.lang.Long($param_1), $param_2, new java.lang.Boolean($param_3)}, -5803803475088455571L);
+ }
+ else {
+ java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 0, interfaceHash);
+ try {
+ java.io.ObjectOutput out = call.getOutputStream();
+ out.writeObject($param_0);
+ out.writeLong($param_1);
+ out.writeObject($param_2);
+ out.writeBoolean($param_3);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling arguments", e);
+ }
+ ref.invoke(call);
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling return", e);
+ }
+ finally {
+ ref.done(call);
+ }
+ }
+ }
+ catch (java.rmi.RemoteException e) {
+ throw e;
+ }
+ catch (java.lang.Exception e) {
+ throw new java.rmi.UnexpectedException("undeclared checked exception", e);
+ }
+ }
+
+ public java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[] $param_0, long $param_1, java.rmi.dgc.Lease $param_2) throws java.rmi.RemoteException {
+ try {
+ if (useNewInvoke) {
+ java.lang.Object $result = ref.invoke(this, $method_dirty_1, new java.lang.Object[] {$param_0, new java.lang.Long($param_1), $param_2}, -8139341527526761862L);
+ return ((java.rmi.dgc.Lease)$result);
+ }
+ else {
+ java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 1, interfaceHash);
+ try {
+ java.io.ObjectOutput out = call.getOutputStream();
+ out.writeObject($param_0);
+ out.writeLong($param_1);
+ out.writeObject($param_2);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling arguments", e);
+ }
+ ref.invoke(call);
+ java.rmi.dgc.Lease $result;
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ $result = (java.rmi.dgc.Lease)in.readObject();
+ return ($result);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling return", e);
+ }
+ finally {
+ ref.done(call);
+ }
+ }
+ }
+ catch (java.rmi.RemoteException e) {
+ throw e;
+ }
+ catch (java.lang.Exception e) {
+ throw new java.rmi.UnexpectedException("undeclared checked exception", e);
+ }
+ }
+
+}
diff --git a/libjava/gnu/java/rmi/registry/RegistryImpl.java b/libjava/gnu/java/rmi/registry/RegistryImpl.java
new file mode 100644
index 0000000..1dab766
--- /dev/null
+++ b/libjava/gnu/java/rmi/registry/RegistryImpl.java
@@ -0,0 +1,115 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.registry;
+
+import java.rmi.registry.Registry;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.RemoteException;
+import java.rmi.NotBoundException;
+import java.rmi.AccessException;
+import java.rmi.AlreadyBoundException;
+import java.rmi.Remote;
+import java.rmi.server.UnicastRemoteObject;
+import java.rmi.server.ObjID;
+import java.util.Hashtable;
+import java.util.Enumeration;
+import java.rmi.server.RMISocketFactory;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.server.RMIServerSocketFactory;
+import gnu.java.rmi.server.UnicastServerRef;
+
+public class RegistryImpl
+ extends UnicastRemoteObject implements Registry {
+
+private Hashtable bindings = new Hashtable();
+
+public RegistryImpl(int port) throws RemoteException {
+ this(port, RMISocketFactory.getSocketFactory(), RMISocketFactory.getSocketFactory());
+}
+
+public RegistryImpl(int port, RMIClientSocketFactory cf, RMIServerSocketFactory sf) throws RemoteException {
+ super(new UnicastServerRef(new ObjID(ObjID.REGISTRY_ID), port, sf));
+ ((UnicastServerRef)getRef()).exportObject(this);
+}
+
+public Remote lookup(String name) throws RemoteException, NotBoundException, AccessException {
+ Object obj = bindings.get(name);
+ if (obj == null) {
+ throw new NotBoundException(name);
+ }
+ return ((Remote)obj);
+}
+
+public void bind(String name, Remote obj) throws RemoteException, AlreadyBoundException, AccessException {
+ if (bindings.containsKey(name)) {
+ throw new AlreadyBoundException(name);
+ }
+ bindings.put(name, obj);
+}
+
+public void unbind(String name) throws RemoteException, NotBoundException, AccessException {
+ Object obj = bindings.remove(name);
+ if (obj == null) {
+ throw new NotBoundException(name);
+ }
+}
+
+public void rebind(String name, Remote obj) throws RemoteException, AccessException {
+ bindings.put(name, obj);
+}
+
+public String[] list() throws RemoteException, AccessException {
+ int size = bindings.size();
+ String[] strings = new String[size];
+ Enumeration e = bindings.keys();
+ for (int i = 0; i < size; i++) {
+ strings[i] = (String)e.nextElement();
+ }
+ return (strings);
+}
+
+public static void main(String[] args) {
+ int port = Registry.REGISTRY_PORT;
+ if (args.length > 0) {
+ try {
+ port = Integer.parseInt(args[0]);
+ }
+ catch (NumberFormatException _) {
+ System.err.println("Bad port number - using default");
+ }
+ }
+
+ try {
+ Registry impl = LocateRegistry.createRegistry(port);
+ }
+ catch (RemoteException _) {
+ System.err.println("Registry failed");
+ }
+}
+
+}
diff --git a/libjava/gnu/java/rmi/registry/RegistryImpl_Skel.java b/libjava/gnu/java/rmi/registry/RegistryImpl_Skel.java
new file mode 100644
index 0000000..7ba41c3
--- /dev/null
+++ b/libjava/gnu/java/rmi/registry/RegistryImpl_Skel.java
@@ -0,0 +1,189 @@
+// Skel class generated by rmic - DO NOT EDIT!
+
+package gnu.java.rmi.registry;
+
+public final class RegistryImpl_Skel
+ implements java.rmi.server.Skeleton
+{
+ private static final long interfaceHash = 4905912898345647071L;
+
+ private static final java.rmi.server.Operation[] operations = {
+ new java.rmi.server.Operation("void bind(java.lang.String, java.rmi.Remote"),
+ new java.rmi.server.Operation("java.lang.String[] list("),
+ new java.rmi.server.Operation("java.rmi.Remote lookup(java.lang.String"),
+ new java.rmi.server.Operation("void rebind(java.lang.String, java.rmi.Remote"),
+ new java.rmi.server.Operation("void unbind(java.lang.String")
+ };
+
+ public java.rmi.server.Operation[] getOperations() {
+ return ((java.rmi.server.Operation[]) operations.clone());
+ }
+
+ public void dispatch(java.rmi.Remote obj, java.rmi.server.RemoteCall call, int opnum, long hash) throws java.lang.Exception {
+ if (opnum < 0) {
+ if (hash == 7583982177005850366L) {
+ opnum = 0;
+ }
+ else if (hash == 2571371476350237748L) {
+ opnum = 1;
+ }
+ else if (hash == -7538657168040752697L) {
+ opnum = 2;
+ }
+ else if (hash == -8381844669958460146L) {
+ opnum = 3;
+ }
+ else if (hash == 7305022919901907578L) {
+ opnum = 4;
+ }
+ else {
+ throw new java.rmi.server.SkeletonMismatchException("interface hash mismatch");
+ }
+ }
+ else if (hash != interfaceHash) {
+ throw new java.rmi.server.SkeletonMismatchException("interface hash mismatch");
+ }
+
+ gnu.java.rmi.registry.RegistryImpl server = (gnu.java.rmi.registry.RegistryImpl)obj;
+ switch (opnum) {
+ case 0:
+ {
+ java.lang.String $param_0;
+ java.rmi.Remote $param_1;
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ $param_0 = (java.lang.String)in.readObject();
+ $param_1 = (java.rmi.Remote)in.readObject();
+
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ catch (java.lang.ClassCastException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ finally {
+ call.releaseInputStream();
+ }
+ server.bind($param_0, $param_1);
+ try {
+ java.io.ObjectOutput out = call.getResultStream(true);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling return", e);
+ }
+ break;
+ }
+
+ case 1:
+ {
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ finally {
+ call.releaseInputStream();
+ }
+ java.lang.String[] $result = server.list();
+ try {
+ java.io.ObjectOutput out = call.getResultStream(true);
+ out.writeObject($result);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling return", e);
+ }
+ break;
+ }
+
+ case 2:
+ {
+ java.lang.String $param_0;
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ $param_0 = (java.lang.String)in.readObject();
+
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ catch (java.lang.ClassCastException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ finally {
+ call.releaseInputStream();
+ }
+ java.rmi.Remote $result = server.lookup($param_0);
+ try {
+ java.io.ObjectOutput out = call.getResultStream(true);
+ out.writeObject($result);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling return", e);
+ }
+ break;
+ }
+
+ case 3:
+ {
+ java.lang.String $param_0;
+ java.rmi.Remote $param_1;
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ $param_0 = (java.lang.String)in.readObject();
+ $param_1 = (java.rmi.Remote)in.readObject();
+
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ catch (java.lang.ClassCastException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ finally {
+ call.releaseInputStream();
+ }
+ server.rebind($param_0, $param_1);
+ try {
+ java.io.ObjectOutput out = call.getResultStream(true);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling return", e);
+ }
+ break;
+ }
+
+ case 4:
+ {
+ java.lang.String $param_0;
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ $param_0 = (java.lang.String)in.readObject();
+
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ catch (java.lang.ClassCastException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling arguments", e);
+ }
+ finally {
+ call.releaseInputStream();
+ }
+ server.unbind($param_0);
+ try {
+ java.io.ObjectOutput out = call.getResultStream(true);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling return", e);
+ }
+ break;
+ }
+
+ default:
+ throw new java.rmi.UnmarshalException("invalid method number");
+ }
+ }
+}
diff --git a/libjava/gnu/java/rmi/registry/RegistryImpl_Stub.java b/libjava/gnu/java/rmi/registry/RegistryImpl_Stub.java
new file mode 100644
index 0000000..bfa755c
--- /dev/null
+++ b/libjava/gnu/java/rmi/registry/RegistryImpl_Stub.java
@@ -0,0 +1,255 @@
+// Stub class generated by rmic - DO NOT EDIT!
+
+package gnu.java.rmi.registry;
+
+public final class RegistryImpl_Stub
+ extends java.rmi.server.RemoteStub
+ implements java.rmi.registry.Registry
+{
+ private static final long serialVersionUID = 2L;
+
+ private static final long interfaceHash = 4905912898345647071L;
+
+ private static boolean useNewInvoke;
+
+ private static final java.rmi.server.Operation[] operations = {
+ new java.rmi.server.Operation("void bind(java.lang.String, java.rmi.Remote)"),
+ new java.rmi.server.Operation("java.lang.String[] list()"),
+ new java.rmi.server.Operation("java.rmi.Remote lookup(java.lang.String)"),
+ new java.rmi.server.Operation("void rebind(java.lang.String, java.rmi.Remote)"),
+ new java.rmi.server.Operation("void unbind(java.lang.String)")
+ };
+
+ private static java.lang.reflect.Method $method_bind_0;
+ private static java.lang.reflect.Method $method_list_1;
+ private static java.lang.reflect.Method $method_lookup_2;
+ private static java.lang.reflect.Method $method_rebind_3;
+ private static java.lang.reflect.Method $method_unbind_4;
+
+ static {
+ try {
+ java.rmi.server.RemoteRef.class.getMethod("invoke", new java.lang.Class[] { java.rmi.Remote.class, java.lang.reflect.Method.class, java.lang.Object[].class, long.class });
+ useNewInvoke = true;
+ $method_bind_0 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("bind", new java.lang.Class[] {java.lang.String.class, java.rmi.Remote.class});
+ $method_list_1 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("list", new java.lang.Class[] {});
+ $method_lookup_2 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("lookup", new java.lang.Class[] {java.lang.String.class});
+ $method_rebind_3 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("rebind", new java.lang.Class[] {java.lang.String.class, java.rmi.Remote.class});
+ $method_unbind_4 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("unbind", new java.lang.Class[] {java.lang.String.class});
+
+ }
+ catch (java.lang.NoSuchMethodException e) {
+ useNewInvoke = false;
+ }
+ }
+
+ public RegistryImpl_Stub() {
+ super();
+ }
+ public RegistryImpl_Stub(java.rmi.server.RemoteRef ref) {
+ super(ref);
+ }
+
+ public void bind(java.lang.String $param_0, java.rmi.Remote $param_1) throws java.rmi.AccessException, java.rmi.AlreadyBoundException, java.rmi.RemoteException {
+ try {
+ if (useNewInvoke) {
+ ref.invoke(this, $method_bind_0, new java.lang.Object[] {$param_0, $param_1}, 7583982177005850366L);
+ }
+ else {
+ java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 0, interfaceHash);
+ try {
+ java.io.ObjectOutput out = call.getOutputStream();
+ out.writeObject($param_0);
+ out.writeObject($param_1);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling arguments", e);
+ }
+ ref.invoke(call);
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling return", e);
+ }
+ finally {
+ ref.done(call);
+ }
+ }
+ }
+ catch (java.rmi.AccessException e) {
+ throw e;
+ }
+ catch (java.rmi.AlreadyBoundException e) {
+ throw e;
+ }
+ catch (java.rmi.RemoteException e) {
+ throw e;
+ }
+ catch (java.lang.Exception e) {
+ throw new java.rmi.UnexpectedException("undeclared checked exception", e);
+ }
+ }
+
+ public java.lang.String[] list() throws java.rmi.AccessException, java.rmi.RemoteException {
+ try {
+ if (useNewInvoke) {
+ java.lang.Object $result = ref.invoke(this, $method_list_1, null, 2571371476350237748L);
+ return ((java.lang.String[])$result);
+ }
+ else {
+ java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 1, interfaceHash);
+ try {
+ java.io.ObjectOutput out = call.getOutputStream();
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling arguments", e);
+ }
+ ref.invoke(call);
+ java.lang.String[] $result;
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ $result = (java.lang.String[])in.readObject();
+ return ($result);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling return", e);
+ }
+ finally {
+ ref.done(call);
+ }
+ }
+ }
+ catch (java.rmi.AccessException e) {
+ throw e;
+ }
+ catch (java.rmi.RemoteException e) {
+ throw e;
+ }
+ catch (java.lang.Exception e) {
+ throw new java.rmi.UnexpectedException("undeclared checked exception", e);
+ }
+ }
+
+ public java.rmi.Remote lookup(java.lang.String $param_0) throws java.rmi.AccessException, java.rmi.NotBoundException, java.rmi.RemoteException {
+ try {
+ if (useNewInvoke) {
+ java.lang.Object $result = ref.invoke(this, $method_lookup_2, new java.lang.Object[] {$param_0}, -7538657168040752697L);
+ return ((java.rmi.Remote)$result);
+ }
+ else {
+ java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 2, interfaceHash);
+ try {
+ java.io.ObjectOutput out = call.getOutputStream();
+ out.writeObject($param_0);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling arguments", e);
+ }
+ ref.invoke(call);
+ java.rmi.Remote $result;
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ $result = (java.rmi.Remote)in.readObject();
+ return ($result);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling return", e);
+ }
+ finally {
+ ref.done(call);
+ }
+ }
+ }
+ catch (java.rmi.AccessException e) {
+ throw e;
+ }
+ catch (java.rmi.NotBoundException e) {
+ throw e;
+ }
+ catch (java.rmi.RemoteException e) {
+ throw e;
+ }
+ catch (java.lang.Exception e) {
+ throw new java.rmi.UnexpectedException("undeclared checked exception", e);
+ }
+ }
+
+ public void rebind(java.lang.String $param_0, java.rmi.Remote $param_1) throws java.rmi.AccessException, java.rmi.RemoteException {
+ try {
+ if (useNewInvoke) {
+ ref.invoke(this, $method_rebind_3, new java.lang.Object[] {$param_0, $param_1}, -8381844669958460146L);
+ }
+ else {
+ java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 3, interfaceHash);
+ try {
+ java.io.ObjectOutput out = call.getOutputStream();
+ out.writeObject($param_0);
+ out.writeObject($param_1);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling arguments", e);
+ }
+ ref.invoke(call);
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling return", e);
+ }
+ finally {
+ ref.done(call);
+ }
+ }
+ }
+ catch (java.rmi.AccessException e) {
+ throw e;
+ }
+ catch (java.rmi.RemoteException e) {
+ throw e;
+ }
+ catch (java.lang.Exception e) {
+ throw new java.rmi.UnexpectedException("undeclared checked exception", e);
+ }
+ }
+
+ public void unbind(java.lang.String $param_0) throws java.rmi.AccessException, java.rmi.NotBoundException, java.rmi.RemoteException {
+ try {
+ if (useNewInvoke) {
+ ref.invoke(this, $method_unbind_4, new java.lang.Object[] {$param_0}, 7305022919901907578L);
+ }
+ else {
+ java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 4, interfaceHash);
+ try {
+ java.io.ObjectOutput out = call.getOutputStream();
+ out.writeObject($param_0);
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.MarshalException("error marshalling arguments", e);
+ }
+ ref.invoke(call);
+ try {
+ java.io.ObjectInput in = call.getInputStream();
+ }
+ catch (java.io.IOException e) {
+ throw new java.rmi.UnmarshalException("error unmarshalling return", e);
+ }
+ finally {
+ ref.done(call);
+ }
+ }
+ }
+ catch (java.rmi.AccessException e) {
+ throw e;
+ }
+ catch (java.rmi.NotBoundException e) {
+ throw e;
+ }
+ catch (java.rmi.RemoteException e) {
+ throw e;
+ }
+ catch (java.lang.Exception e) {
+ throw new java.rmi.UnexpectedException("undeclared checked exception", e);
+ }
+ }
+
+}
diff --git a/libjava/gnu/java/rmi/rmic/RMIC.java b/libjava/gnu/java/rmi/rmic/RMIC.java
new file mode 100644
index 0000000..84681e2
--- /dev/null
+++ b/libjava/gnu/java/rmi/rmic/RMIC.java
@@ -0,0 +1,982 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.rmic;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Arrays;
+import java.lang.Comparable;
+import gnu.java.rmi.server.RMIHashes;
+// import kaffe.tools.compiler.Compiler;
+
+public class RMIC {
+
+private String[] args;
+private int next;
+private Exception exception;
+
+private boolean keep = false;
+private boolean need11Stubs = true;
+private boolean need12Stubs = true;
+private boolean compile = true;
+private boolean verbose;
+private String destination;
+
+private PrintWriter out;
+private TabbedWriter ctrl;
+
+private Class clazz;
+private String classname;
+private String fullclassname;
+private MethodRef[] remotemethods;
+private String stubname;
+private String skelname;
+
+public RMIC(String[] a) {
+ args = a;
+}
+
+public static void main(String args[]) {
+ RMIC r = new RMIC(args);
+ if (r.run() == false) {
+ Exception exception = r.getException();
+ if (exception != null) {
+ exception.printStackTrace();
+ }
+ else {
+ usage();
+ }
+ }
+}
+
+public boolean run() {
+ parseOptions();
+ if (next >= args.length) {
+ return (false);
+ }
+ for (int i = next; i < args.length; i++) {
+ try {
+ if (verbose) {
+ System.out.println("[Processing class " + args[i] + ".class]");
+ }
+ processClass(args[i]);
+ }
+ catch (Exception e) {
+ exception = e;
+ return (false);
+ }
+ }
+ return (true);
+}
+
+private boolean processClass(String classname) throws Exception {
+ analyzeClass(classname);
+ generateStub();
+ if (need11Stubs) {
+ generateSkel();
+ }
+ if (compile) {
+ compile(stubname + ".java");
+ if (need11Stubs) {
+ compile(skelname + ".java");
+ }
+ }
+ if (!keep) {
+ (new File(stubname + ".java")).delete();
+ if (need11Stubs) {
+ (new File(skelname + ".java")).delete();
+ }
+ }
+ return (true);
+}
+
+private void analyzeClass(String cname) throws Exception {
+ int p = cname.lastIndexOf('.');
+ if (p != -1) {
+ classname = cname.substring(p+1);
+ }
+ else {
+ classname = cname;
+ }
+ fullclassname = cname;
+
+ HashSet rmeths = new HashSet();
+ findClass();
+ for (Class cls = clazz; cls != null; cls = cls.getSuperclass()) {
+ // Keep going down the inheritence tree until we hit the system
+ if (cls.getName().startsWith("java.")) {
+ break;
+ }
+
+ Method[] meths = cls.getDeclaredMethods();
+ for (int i = 0; i < meths.length; i++) {
+ // Only include public methods
+ int mods = meths[i].getModifiers();
+ if (Modifier.isPublic(mods) && !Modifier.isStatic(mods)) {
+ // Should check exceptions here. - XXX
+
+ // Add this one in.
+ rmeths.add(meths[i]);
+ }
+ }
+ }
+
+ // Convert into a MethodRef array and sort them
+ remotemethods = new MethodRef[rmeths.size()];
+ int c = 0;
+ for (Iterator i = rmeths.iterator(); i.hasNext(); ) {
+ remotemethods[c++] = new MethodRef((Method)i.next());
+ }
+ Arrays.sort(remotemethods);
+}
+
+public Exception getException() {
+ return (exception);
+}
+
+private void findClass() throws ClassNotFoundException {
+ clazz = Class.forName(fullclassname);
+}
+
+private void generateStub() throws IOException {
+ stubname = classname + "_Stub";
+ ctrl = new TabbedWriter(new FileWriter(stubname + ".java"));
+ out = new PrintWriter(ctrl);
+
+ if (verbose) {
+ System.out.println("[Generating class " + stubname + ".java]");
+ }
+
+ out.println("// Stub class generated by rmic - DO NOT EDIT!");
+ out.println();
+ if (fullclassname != classname) {
+ String pname = fullclassname.substring(0, fullclassname.lastIndexOf('.'));
+ out.println("package " + pname + ";");
+ out.println();
+ }
+
+ out.print("public final class " + stubname);
+ ctrl.indent();
+ out.println("extends java.rmi.server.RemoteStub");
+
+ // Output interfaces we implement
+ out.print("implements ");
+ Class[] ifaces = clazz.getInterfaces();
+ for (int i = 0; i < ifaces.length; i++) {
+ out.print(ifaces[i].getName());
+ if (i+1 < ifaces.length) {
+ out.print(", ");
+ }
+ }
+
+ ctrl.unindent();
+ out.print("{");
+ ctrl.indent();
+
+ // UID
+ if (need12Stubs) {
+ out.println("private static final long serialVersionUID = 2L;");
+ out.println();
+ }
+
+ // InterfaceHash - don't know how to calculate this - XXX
+ if (need11Stubs) {
+ out.println("private static final long interfaceHash = " + RMIHashes.getInterfaceHash(clazz) + "L;");
+ out.println();
+ if (need12Stubs) {
+ out.println("private static boolean useNewInvoke;");
+ out.println();
+ }
+
+ // Operation table
+ out.print("private static final java.rmi.server.Operation[] operations = {");
+
+ ctrl.indent();
+ for (int i = 0; i < remotemethods.length; i++) {
+ Method m = remotemethods[i].meth;
+ out.print("new java.rmi.server.Operation(\"");
+ out.print(getPrettyName(m.getReturnType()) + " ");
+ out.print(m.getName() + "(");
+ // Output signature
+ Class[] sig = m.getParameterTypes();
+ for (int j = 0; j < sig.length; j++) {
+ out.print(getPrettyName(sig[j]));
+ if (j+1 < sig.length) {
+ out.print(", ");
+ }
+ }
+ out.print(")\")");
+ if (i + 1 < remotemethods.length) {
+ out.println(",");
+ }
+ }
+ ctrl.unindent();
+ out.println("};");
+ out.println();
+ }
+
+ // Set of method references.
+ if (need12Stubs) {
+ for (int i = 0; i < remotemethods.length; i++) {
+ Method m = remotemethods[i].meth;
+ out.println("private static java.lang.reflect.Method $method_" + m.getName() + "_" + i + ";");
+ }
+
+ // Initialize the methods references.
+ out.println();
+ out.print("static {");
+ ctrl.indent();
+
+ out.print("try {");
+ ctrl.indent();
+
+ if (need11Stubs) {
+ out.println("java.rmi.server.RemoteRef.class.getMethod(\"invoke\", new java.lang.Class[] { java.rmi.Remote.class, java.lang.reflect.Method.class, java.lang.Object[].class, long.class });");
+ out.println("useNewInvoke = true;");
+ }
+
+ for (int i = 0; i < remotemethods.length; i++) {
+ Method m = remotemethods[i].meth;
+ out.print("$method_" + m.getName() + "_" + i + " = ");
+ out.print(fullclassname + ".class.getMethod(\"" + m.getName() + "\"");
+ out.print(", new java.lang.Class[] {");
+ // Output signature
+ Class[] sig = m.getParameterTypes();
+ for (int j = 0; j < sig.length; j++) {
+ out.print(getPrettyName(sig[j]) + ".class");
+ if (j+1 < sig.length) {
+ out.print(", ");
+ }
+ }
+ out.println("});");
+ }
+ ctrl.unindent();
+ out.println("}");
+ out.print("catch (java.lang.NoSuchMethodException e) {");
+ ctrl.indent();
+ if (need11Stubs) {
+ out.print("useNewInvoke = false;");
+ }
+ else {
+ out.print("throw new java.lang.NoSuchMethodError(\"stub class initialization failed\");");
+ }
+
+ ctrl.unindent();
+ out.print("}");
+
+ ctrl.unindent();
+ out.println("}");
+ out.println();
+ }
+
+ // Constructors
+ if (need11Stubs) {
+ out.print("public " + stubname + "() {");
+ ctrl.indent();
+ out.print("super();");
+ ctrl.unindent();
+ out.println("}");
+ }
+
+ if (need12Stubs) {
+ out.print("public " + stubname + "(java.rmi.server.RemoteRef ref) {");
+ ctrl.indent();
+ out.print("super(ref);");
+ ctrl.unindent();
+ out.println("}");
+ }
+
+ // Method implementations
+ for (int i = 0; i < remotemethods.length; i++) {
+ Method m = remotemethods[i].meth;
+ Class[] sig = m.getParameterTypes();
+ Class returntype = m.getReturnType();
+ Class[] except = sortExceptions(m.getExceptionTypes());
+
+ out.println();
+ out.print("public " + getPrettyName(returntype) + " " + m.getName() + "(");
+ for (int j = 0; j < sig.length; j++) {
+ out.print(getPrettyName(sig[j]));
+ out.print(" $param_" + j);
+ if (j+1 < sig.length) {
+ out.print(", ");
+ }
+ }
+ out.print(") ");
+ out.print("throws ");
+ for (int j = 0; j < except.length; j++) {
+ out.print(getPrettyName(except[j]));
+ if (j+1 < except.length) {
+ out.print(", ");
+ }
+ }
+ out.print(" {");
+ ctrl.indent();
+
+ out.print("try {");
+ ctrl.indent();
+
+ if (need12Stubs) {
+ if (need11Stubs) {
+ out.print("if (useNewInvoke) {");
+ ctrl.indent();
+ }
+ if (returntype != Void.TYPE) {
+ out.print("java.lang.Object $result = ");
+ }
+ out.print("ref.invoke(this, $method_" + m.getName() + "_" + i + ", ");
+ if (sig.length == 0) {
+ out.print("null, ");
+ }
+ else {
+ out.print("new java.lang.Object[] {");
+ for (int j = 0; j < sig.length; j++) {
+ if (sig[j] == Boolean.TYPE) {
+ out.print("new java.lang.Boolean($param_" + j + ")");
+ }
+ else if (sig[j] == Byte.TYPE) {
+ out.print("new java.lang.Byte($param_" + j + ")");
+ }
+ else if (sig[j] == Character.TYPE) {
+ out.print("new java.lang.Character($param_" + j + ")");
+ }
+ else if (sig[j] == Short.TYPE) {
+ out.print("new java.lang.Short($param_" + j + ")");
+ }
+ else if (sig[j] == Integer.TYPE) {
+ out.print("new java.lang.Integer($param_" + j + ")");
+ }
+ else if (sig[j] == Long.TYPE) {
+ out.print("new java.lang.Long($param_" + j + ")");
+ }
+ else if (sig[j] == Float.TYPE) {
+ out.print("new java.lang.Float($param_" + j + ")");
+ }
+ else if (sig[j] == Double.TYPE) {
+ out.print("new java.lang.Double($param_" + j + ")");
+ }
+ else {
+ out.print("$param_" + j);
+ }
+ if (j+1 < sig.length) {
+ out.print(", ");
+ }
+ }
+ out.print("}, ");
+ }
+ out.print(Long.toString(remotemethods[i].hash) + "L");
+ out.print(");");
+
+ if (returntype != Void.TYPE) {
+ out.println();
+ out.print("return (");
+ if (returntype == Boolean.TYPE) {
+ out.print("((java.lang.Boolean)$result).booleanValue()");
+ }
+ else if (returntype == Byte.TYPE) {
+ out.print("((java.lang.Byte)$result).byteValue()");
+ }
+ else if (returntype == Character.TYPE) {
+ out.print("((java.lang.Character)$result).charValue()");
+ }
+ else if (returntype == Short.TYPE) {
+ out.print("((java.lang.Short)$result).shortValue()");
+ }
+ else if (returntype == Integer.TYPE) {
+ out.print("((java.lang.Integer)$result).intValue()");
+ }
+ else if (returntype == Long.TYPE) {
+ out.print("((java.lang.Long)$result).longValue()");
+ }
+ else if (returntype == Float.TYPE) {
+ out.print("((java.lang.Float)$result).floatValue()");
+ }
+ else if (returntype == Double.TYPE) {
+ out.print("((java.lang.Double)$result).doubleValue()");
+ }
+ else {
+ out.print("(" + getPrettyName(returntype) + ")$result");
+ }
+ out.print(");");
+ }
+
+ if (need11Stubs) {
+ ctrl.unindent();
+ out.println("}");
+ out.print("else {");
+ ctrl.indent();
+ }
+ }
+
+ if (need11Stubs) {
+ out.println("java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, " + i + ", interfaceHash);");
+ out.print("try {");
+ ctrl.indent();
+ out.print("java.io.ObjectOutput out = call.getOutputStream();");
+ for (int j = 0; j < sig.length; j++) {
+ out.println();
+ if (sig[j] == Boolean.TYPE) {
+ out.print("out.writeBoolean(");
+ }
+ else if (sig[j] == Byte.TYPE) {
+ out.print("out.writeByte(");
+ }
+ else if (sig[j] == Character.TYPE) {
+ out.print("out.writeChar(");
+ }
+ else if (sig[j] == Short.TYPE) {
+ out.print("out.writeShort(");
+ }
+ else if (sig[j] == Integer.TYPE) {
+ out.print("out.writeInt(");
+ }
+ else if (sig[j] == Long.TYPE) {
+ out.print("out.writeLong(");
+ }
+ else if (sig[j] == Float.TYPE) {
+ out.print("out.writeFloat(");
+ }
+ else if (sig[j] == Double.TYPE) {
+ out.print("out.writeDouble(");
+ }
+ else {
+ out.print("out.writeObject(");
+ }
+ out.print("$param_" + j + ");");
+ }
+ ctrl.unindent();
+ out.println("}");
+ out.print("catch (java.io.IOException e) {");
+ ctrl.indent();
+ out.print("throw new java.rmi.MarshalException(\"error marshalling arguments\", e);");
+ ctrl.unindent();
+ out.println("}");
+ out.println("ref.invoke(call);");
+ if (returntype != Void.TYPE) {
+ out.println(getPrettyName(returntype) + " $result;");
+ }
+ out.print("try {");
+ ctrl.indent();
+ out.print("java.io.ObjectInput in = call.getInputStream();");
+ boolean needcastcheck = false;
+ if (returntype != Void.TYPE) {
+ out.println();
+ out.print("$result = ");
+ if (returntype == Boolean.TYPE) {
+ out.print("in.readBoolean();");
+ }
+ else if (returntype == Byte.TYPE) {
+ out.print("in.readByte();");
+ }
+ else if (returntype == Character.TYPE) {
+ out.print("in.readChar();");
+ }
+ else if (returntype == Short.TYPE) {
+ out.print("in.readShort();");
+ }
+ else if (returntype == Integer.TYPE) {
+ out.print("in.readInt();");
+ }
+ else if (returntype == Long.TYPE) {
+ out.print("in.readLong();");
+ }
+ else if (returntype == Float.TYPE) {
+ out.print("in.readFloat();");
+ }
+ else if (returntype == Double.TYPE) {
+ out.print("in.readDouble();");
+ }
+ else {
+ if (returntype != Object.class) {
+ out.print("(" + getPrettyName(returntype) + ")");
+ }
+ else {
+ needcastcheck = true;
+ }
+ out.print("in.readObject();");
+ }
+ out.println();
+ out.print("return ($result);");
+ }
+ ctrl.unindent();
+ out.println("}");
+ out.print("catch (java.io.IOException e) {");
+ ctrl.indent();
+ out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling return\", e);");
+ ctrl.unindent();
+ out.println("}");
+ if (needcastcheck) {
+ out.print("catch (java.lang.ClassNotFoundException e) {");
+ ctrl.indent();
+ out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling return\", e);");
+ ctrl.unindent();
+ out.println("}");
+ }
+ out.print("finally {");
+ ctrl.indent();
+ out.print("ref.done(call);");
+ ctrl.unindent();
+ out.print("}");
+
+ if (need12Stubs && need11Stubs) {
+ ctrl.unindent();
+ out.print("}");
+ }
+ }
+
+ ctrl.unindent();
+ out.print("}");
+
+ boolean needgeneral = true;
+ for (int j = 0; j < except.length; j++) {
+ out.println();
+ out.print("catch (" + getPrettyName(except[j]) + " e) {");
+ ctrl.indent();
+ out.print("throw e;");
+ ctrl.unindent();
+ out.print("}");
+ if (except[j] == Exception.class) {
+ needgeneral = false;
+ }
+ }
+ if (needgeneral) {
+ out.println();
+ out.print("catch (java.lang.Exception e) {");
+ ctrl.indent();
+ out.print("throw new java.rmi.UnexpectedException(\"undeclared checked exception\", e);");
+ ctrl.unindent();
+ out.print("}");
+ }
+
+ ctrl.unindent();
+ out.print("}");
+ out.println();
+ }
+
+ ctrl.unindent();
+ out.println("}");
+
+ out.close();
+}
+
+private void generateSkel() throws IOException {
+ skelname = classname + "_Skel";
+ ctrl = new TabbedWriter(new FileWriter(skelname + ".java"));
+ out = new PrintWriter(ctrl);
+
+ if (verbose) {
+ System.out.println("[Generating class " + skelname + ".java]");
+ }
+
+ out.println("// Skel class generated by rmic - DO NOT EDIT!");
+ out.println();
+ if (fullclassname != classname) {
+ String pname = fullclassname.substring(0, fullclassname.lastIndexOf('.'));
+ out.println("package " + pname + ";");
+ out.println();
+ }
+
+ out.print("public final class " + skelname);
+ ctrl.indent();
+
+ // Output interfaces we implement
+ out.print("implements java.rmi.server.Skeleton");
+
+ ctrl.unindent();
+ out.print("{");
+ ctrl.indent();
+
+ // Interface hash - don't know how to calculate this - XXX
+ out.println("private static final long interfaceHash = " + RMIHashes.getInterfaceHash(clazz) + "L;");
+ out.println();
+
+ // Operation table
+ out.print("private static final java.rmi.server.Operation[] operations = {");
+
+ ctrl.indent();
+ for (int i = 0; i < remotemethods.length; i++) {
+ Method m = remotemethods[i].meth;
+ out.print("new java.rmi.server.Operation(\"");
+ out.print(getPrettyName(m.getReturnType()) + " ");
+ out.print(m.getName() + "(");
+ // Output signature
+ Class[] sig = m.getParameterTypes();
+ for (int j = 0; j < sig.length; j++) {
+ out.print(getPrettyName(sig[j]));
+ if (j+1 < sig.length) {
+ out.print(", ");
+ }
+ }
+ out.print("\")");
+ if (i + 1 < remotemethods.length) {
+ out.println(",");
+ }
+ }
+ ctrl.unindent();
+ out.println("};");
+
+ out.println();
+
+ // getOpertions method
+ out.print("public java.rmi.server.Operation[] getOperations() {");
+ ctrl.indent();
+ out.print("return ((java.rmi.server.Operation[]) operations.clone());");
+ ctrl.unindent();
+ out.println("}");
+
+ out.println();
+
+ // Dispatch method
+ out.print("public void dispatch(java.rmi.Remote obj, java.rmi.server.RemoteCall call, int opnum, long hash) throws java.lang.Exception {");
+ ctrl.indent();
+
+ out.print("if (opnum < 0) {");
+ ctrl.indent();
+
+ for (int i = 0; i < remotemethods.length; i++) {
+ out.print("if (hash == " + Long.toString(remotemethods[i].hash) + "L) {");
+ ctrl.indent();
+ out.print("opnum = " + i + ";");
+ ctrl.unindent();
+ out.println("}");
+ out.print("else ");
+ }
+ out.print("{");
+ ctrl.indent();
+ out.print("throw new java.rmi.server.SkeletonMismatchException(\"interface hash mismatch\");");
+ ctrl.unindent();
+ out.print("}");
+
+ ctrl.unindent();
+ out.println("}");
+ out.print("else if (hash != interfaceHash) {");
+ ctrl.indent();
+ out.print("throw new java.rmi.server.SkeletonMismatchException(\"interface hash mismatch\");");
+ ctrl.unindent();
+ out.println("}");
+
+ out.println();
+
+ out.println(fullclassname + " server = (" + fullclassname + ")obj;");
+ out.println("switch (opnum) {");
+
+ // Method dispatch
+ for (int i = 0; i < remotemethods.length; i++) {
+ Method m = remotemethods[i].meth;
+ out.println("case " + i + ":");
+ out.print("{");
+ ctrl.indent();
+
+ Class[] sig = m.getParameterTypes();
+ for (int j = 0; j < sig.length; j++) {
+ out.print(getPrettyName(sig[j]));
+ out.println(" $param_" + j + ";");
+ }
+
+ out.print("try {");
+ boolean needcastcheck = false;
+ ctrl.indent();
+ out.println("java.io.ObjectInput in = call.getInputStream();");
+ for (int j = 0; j < sig.length; j++) {
+ out.print("$param_" + j + " = ");
+ if (sig[j] == Boolean.TYPE) {
+ out.print("in.readBoolean();");
+ }
+ else if (sig[j] == Byte.TYPE) {
+ out.print("in.readByte();");
+ }
+ else if (sig[j] == Character.TYPE) {
+ out.print("in.readChar();");
+ }
+ else if (sig[j] == Short.TYPE) {
+ out.print("in.readShort();");
+ }
+ else if (sig[j] == Integer.TYPE) {
+ out.print("in.readInt();");
+ }
+ else if (sig[j] == Long.TYPE) {
+ out.print("in.readLong();");
+ }
+ else if (sig[j] == Float.TYPE) {
+ out.print("in.readFloat();");
+ }
+ else if (sig[j] == Double.TYPE) {
+ out.print("in.readDouble();");
+ }
+ else {
+ if (sig[j] != Object.class) {
+ out.print("(" + getPrettyName(sig[j]) + ")");
+ needcastcheck = true;
+ }
+ out.print("in.readObject();");
+ }
+ out.println();
+ }
+ ctrl.unindent();
+ out.println("}");
+ out.print("catch (java.io.IOException e) {");
+ ctrl.indent();
+ out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling arguments\", e);");
+ ctrl.unindent();
+ out.println("}");
+ if (needcastcheck) {
+ out.print("catch (java.lang.ClassCastException e) {");
+ ctrl.indent();
+ out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling arguments\", e);");
+ ctrl.unindent();
+ out.println("}");
+ }
+ out.print("finally {");
+ ctrl.indent();
+ out.print("call.releaseInputStream();");
+ ctrl.unindent();
+ out.println("}");
+
+ Class returntype = m.getReturnType();
+ if (returntype != Void.TYPE) {
+ out.print(getPrettyName(returntype) + " $result = ");
+ }
+ out.print("server." + m.getName() + "(");
+ for (int j = 0; j < sig.length; j++) {
+ out.print("$param_" + j);
+ if (j + 1 < sig.length) {
+ out.print(", ");
+ }
+ }
+ out.println(");");
+
+ out.print("try {");
+ ctrl.indent();
+ out.print("java.io.ObjectOutput out = call.getResultStream(true);");
+ if (returntype != Void.TYPE) {
+ out.println();
+ if (returntype == Boolean.TYPE) {
+ out.print("out.writeBoolean($result);");
+ }
+ else if (returntype == Byte.TYPE) {
+ out.print("out.writeByte($result);");
+ }
+ else if (returntype == Character.TYPE) {
+ out.print("out.writeChar($result);");
+ }
+ else if (returntype == Short.TYPE) {
+ out.print("out.writeShort($result);");
+ }
+ else if (returntype == Integer.TYPE) {
+ out.print("out.writeInt($result);");
+ }
+ else if (returntype == Long.TYPE) {
+ out.print("out.writeLong($result);");
+ }
+ else if (returntype == Float.TYPE) {
+ out.print("out.writeFloat($result);");
+ }
+ else if (returntype == Double.TYPE) {
+ out.print("out.writeDouble($result);");
+ }
+ else {
+ out.print("out.writeObject($result);");
+ }
+ }
+ ctrl.unindent();
+ out.println("}");
+ out.print("catch (java.io.IOException e) {");
+ ctrl.indent();
+ out.print("throw new java.rmi.MarshalException(\"error marshalling return\", e);");
+ ctrl.unindent();
+ out.println("}");
+ out.print("break;");
+
+ ctrl.unindent();
+ out.println("}");
+ out.println();
+ }
+
+ out.print("default:");
+ ctrl.indent();
+ out.print("throw new java.rmi.UnmarshalException(\"invalid method number\");");
+ ctrl.unindent();
+ out.print("}");
+
+ ctrl.unindent();
+ out.print("}");
+
+ ctrl.unindent();
+ out.println("}");
+
+ out.close();
+}
+
+private void compile(String name) throws Exception {
+ throw new Error ("Not implemented");
+// Compiler comp = Compiler.getInstance();
+// if (verbose) {
+// System.out.println("[Compiling class " + name + "]");
+// }
+// comp.setDestination(destination);
+// boolean result = comp.compile(name);
+// if (result == false) {
+// throw comp.getException();
+// }
+}
+
+private static String getPrettyName(Class cls) {
+ StringBuffer str = new StringBuffer();
+ for (int count = 0;; count++) {
+ if (!cls.isArray()) {
+ str.append(cls.getName());
+ for (; count > 0; count--) {
+ str.append("[]");
+ }
+ return (str.toString());
+ }
+ cls = cls.getComponentType();
+ }
+}
+
+/**
+ * Sort exceptions so the most general go last.
+ */
+private Class[] sortExceptions(Class[] except) {
+ for (int i = 0; i < except.length; i++) {
+ for (int j = i+1; j < except.length; j++) {
+ if (except[i].isAssignableFrom(except[j])) {
+ Class tmp = except[i];
+ except[i] = except[j];
+ except[j] = tmp;
+ }
+ }
+ }
+ return (except);
+}
+
+/**
+ * Process the options until we find the first argument.
+ */
+private void parseOptions() {
+ for (;;) {
+ if (next >= args.length || args[next].charAt(0) != '-') {
+ break;
+ }
+ String arg = args[next];
+ next++;
+
+ if (arg.equals("-keep")) {
+ keep = true;
+ }
+ else if (arg.equals("-keepgenerated")) {
+ keep = true;
+ }
+ else if (arg.equals("-v1.1")) {
+ need11Stubs = true;
+ need12Stubs = false;
+ }
+ else if (arg.equals("-vcompat")) {
+ need11Stubs = true;
+ need12Stubs = true;
+ }
+ else if (arg.equals("-v1.2")) {
+ need11Stubs = false;
+ need12Stubs = true;
+ }
+ else if (arg.equals("-g")) {
+ }
+ else if (arg.equals("-depend")) {
+ }
+ else if (arg.equals("-nowarn")) {
+ }
+ else if (arg.equals("-verbose")) {
+ verbose = true;
+ }
+ else if (arg.equals("-nocompile")) {
+ compile = false;
+ }
+ else if (arg.equals("-classpath")) {
+ next++;
+ }
+ else if (arg.equals("-d")) {
+ destination = args[next];
+ next++;
+ }
+ else if (arg.charAt(1) == 'J') {
+ }
+ else {
+ System.err.println("Unknown option: " + arg);
+ }
+ }
+}
+
+private static void usage() {
+ System.out.println(
+"usage: rmic [-options] classes\n" +
+"Options are:\n" +
+" -keep Don't delete any intermediate files\n" +
+" -keepgenerated Same as -keep\n" +
+" -v1.1 Java 1.1 style stubs only\n" +
+" -vcompat Java 1.1 & Java 1.2 stubs\n" +
+" -v1.2 Java 1.2 style stubs only\n" +
+" -g * Generated debugging information\n" +
+" -depend * Recompile out-of-date files\n" +
+" -nowarn * Suppress warning messages\n" +
+" -nocompile Don't compile the generated files\n" +
+" -verbose Output what's going on\n" +
+" -classpath <path> * Use given path as classpath\n" +
+" -d <directory> Specify where to place generated classes\n" +
+" -J<flag> * Pass flag to Java\n" +
+" * Option currently ignored"
+ );
+}
+
+static class MethodRef
+ implements Comparable {
+
+Method meth;
+String sig;
+long hash;
+
+MethodRef(Method m) {
+ meth = m;
+ // We match on the name - but what about overloading? - XXX
+ sig = m.getName();
+ hash = RMIHashes.getMethodHash(m);
+}
+
+public int compareTo(Object obj) {
+ MethodRef that = (MethodRef)obj;
+ return (this.sig.compareTo(that.sig));
+}
+
+}
+
+}
diff --git a/libjava/gnu/java/rmi/rmic/TabbedWriter.java b/libjava/gnu/java/rmi/rmic/TabbedWriter.java
new file mode 100644
index 0000000..c2e668c
--- /dev/null
+++ b/libjava/gnu/java/rmi/rmic/TabbedWriter.java
@@ -0,0 +1,90 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.rmic;
+
+import java.io.FilterWriter;
+import java.io.Writer;
+import java.io.IOException;
+
+public class TabbedWriter
+ extends FilterWriter {
+
+private static final String defaultTabstring = " ";
+private char[] tabstring;
+private int tabs;
+
+public TabbedWriter(Writer o) {
+ this(o, defaultTabstring);
+}
+
+public TabbedWriter(Writer o, String str) {
+ super(o);
+ tabs = 0;
+ tabstring = str.toCharArray();
+}
+
+public void write(int c) throws IOException {
+ out.write(c);
+ if (c == '\n') {
+ for (int i = 0; i < tabs; i++) {
+ out.write(tabstring, 0, tabstring.length);
+ }
+ }
+}
+
+public void write(char cbuf[], int off, int len) throws IOException {
+ for (int i = 0; i < len; i++) {
+ write((int)cbuf[i+off]);
+ }
+}
+
+public void write(String str, int off, int len) throws IOException {
+ write(str.toCharArray(), off, len);
+}
+
+public void unindent() throws IOException {
+ unindent(1);
+}
+
+public void unindent(int nr) throws IOException {
+ indent(-nr);
+}
+
+public void indent() throws IOException {
+ indent(1);
+}
+
+public void indent(int nr) throws IOException {
+ tabs += nr;
+ if (tabs < 0) {
+ tabs = 0;
+ }
+ write((int)'\n');
+}
+
+}
diff --git a/libjava/gnu/java/rmi/server/ProtocolConstants.java b/libjava/gnu/java/rmi/server/ProtocolConstants.java
new file mode 100644
index 0000000..431a699
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/ProtocolConstants.java
@@ -0,0 +1,53 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+public interface ProtocolConstants {
+
+final public static int PROTOCOL_HEADER = 0x4a524d49; // JRMI
+final public static int PROTOCOL_VERSION = 2;
+
+final public static int STREAM_PROTOCOL = 0x4b;
+final public static int SINGLE_OP_PROTOCOL = 0x4c;
+final public static int MULTIPLEX_PROTOCOL = 0x4d;
+
+final public static int PROTOCOL_ACK = 0x4e;
+final public static int PROTOCOL_NACK = 0x4f;
+
+final public static int MESSAGE_CALL = 0x50;
+final public static int MESSAGE_CALL_ACK = 0x51;
+final public static int MESSAGE_PING = 0x52;
+final public static int MESSAGE_PING_ACK = 0x53;
+final public static int MESSAGE_DGCACK = 0x54;
+
+final public static int RETURN_ACK = 0x01;
+final public static int RETURN_NACK = 0x02;
+
+final public static int DEFAULT_PROTOCOL = STREAM_PROTOCOL;
+
+};
diff --git a/libjava/gnu/java/rmi/server/RMIDefaultSocketFactory.java b/libjava/gnu/java/rmi/server/RMIDefaultSocketFactory.java
new file mode 100644
index 0000000..610c3a7
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/RMIDefaultSocketFactory.java
@@ -0,0 +1,49 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+import java.rmi.server.RMISocketFactory;
+import java.io.IOException;
+import java.net.Socket;
+import java.net.ServerSocket;
+
+public class RMIDefaultSocketFactory
+ extends RMISocketFactory {
+
+public RMIDefaultSocketFactory() {
+}
+
+public Socket createSocket(String host, int port) throws IOException {
+ return (new Socket(host, port));
+}
+
+public ServerSocket createServerSocket(int port) throws IOException {
+ return (new ServerSocket(port));
+}
+
+}
diff --git a/libjava/gnu/java/rmi/server/RMIHashes.java b/libjava/gnu/java/rmi/server/RMIHashes.java
new file mode 100644
index 0000000..dc00276
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/RMIHashes.java
@@ -0,0 +1,45 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+import java.lang.reflect.Method;
+import java.lang.Class;
+import gnu.java.security.provider.SHA;
+
+public class RMIHashes
+{
+ public static long getMethodHash(Method meth)
+ {
+ return meth.hashCode ();
+ }
+
+ public static long getInterfaceHash(Class clazz)
+ {
+ return clazz.hashCode ();
+ }
+}
diff --git a/libjava/gnu/java/rmi/server/RMIObjectInputStream.java b/libjava/gnu/java/rmi/server/RMIObjectInputStream.java
new file mode 100644
index 0000000..b6efbf0
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/RMIObjectInputStream.java
@@ -0,0 +1,65 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+import java.io.ObjectStreamClass;
+import java.io.ObjectInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.rmi.server.RMIClassLoader;
+
+public class RMIObjectInputStream
+ extends ObjectInputStream {
+
+UnicastConnectionManager manager;
+
+public RMIObjectInputStream(InputStream strm, UnicastConnectionManager man) throws IOException {
+ super(strm);
+ manager = man;
+ enableResolveObject(true);
+}
+
+protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+//System.out.println("Resolving class: " + desc.getName());
+ String annotation = (String)readObject();
+ if (annotation == null) {
+ return (super.resolveClass(desc));
+ }
+ else {
+ try {
+ return (RMIClassLoader.loadClass(new URL(annotation), desc.getName()));
+ }
+ catch (MalformedURLException _) {
+ throw new ClassNotFoundException(desc.getName());
+ }
+ }
+}
+
+}
diff --git a/libjava/gnu/java/rmi/server/RMIObjectOutputStream.java b/libjava/gnu/java/rmi/server/RMIObjectOutputStream.java
new file mode 100644
index 0000000..960252b
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/RMIObjectOutputStream.java
@@ -0,0 +1,47 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.rmi.server.RMIClassLoader;
+
+public class RMIObjectOutputStream
+ extends ObjectOutputStream {
+
+public RMIObjectOutputStream(OutputStream strm) throws IOException {
+ super(strm);
+}
+
+protected void annotateClass(Class cls) throws IOException {
+//System.out.println("Annotating class: " + cls);
+ writeObject(RMIClassLoader.getClassAnnotation(cls));
+}
+
+}
diff --git a/libjava/gnu/java/rmi/server/UnicastConnection.java b/libjava/gnu/java/rmi/server/UnicastConnection.java
new file mode 100644
index 0000000..04d18be
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/UnicastConnection.java
@@ -0,0 +1,162 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+import java.lang.Runnable;
+import java.net.Socket;
+import java.net.ServerSocket;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectInput;
+import java.io.IOException;
+import java.rmi.RemoteException;
+
+public class UnicastConnection
+ implements Runnable, ProtocolConstants {
+
+UnicastConnectionManager manager;
+Socket sock;
+DataInputStream din;
+DataOutputStream dout;
+ObjectInputStream oin;
+ObjectOutputStream oout;
+
+UnicastConnection(UnicastConnectionManager man, Socket sock) {
+ this.manager = man;
+ this.sock = sock;
+}
+
+void acceptConnection() throws IOException {
+//System.out.println("Accepting connection on " + lport);
+ din = new DataInputStream(sock.getInputStream());
+ dout = new DataOutputStream(sock.getOutputStream());
+
+ int sig = din.readInt();
+ if (sig != PROTOCOL_HEADER) {
+ throw new IOException("bad protocol header");
+ }
+ short ver = din.readShort();
+ if (ver != PROTOCOL_VERSION) {
+ throw new IOException("bad protocol version");
+ }
+ int protocol = din.readUnsignedByte();
+ if (protocol != SINGLE_OP_PROTOCOL) {
+ // Send an ACK
+ dout.writeByte(PROTOCOL_ACK);
+
+ // Send my hostname and port
+ dout.writeUTF(manager.serverName);
+ dout.writeInt(manager.serverPort);
+
+ // Read their hostname and port
+ String rhost = din.readUTF();
+ int rport = din.readInt();
+ }
+ // Okay, ready to roll ...
+}
+
+void makeConnection(int protocol) throws IOException {
+ dout = new DataOutputStream(sock.getOutputStream());
+ din = new DataInputStream(sock.getInputStream());
+
+ // Send header
+ dout.writeInt(PROTOCOL_HEADER);
+ dout.writeShort(PROTOCOL_VERSION);
+ dout.writeByte(protocol);
+ dout.flush();
+
+ if (protocol != SINGLE_OP_PROTOCOL) {
+ // Get back ack.
+ int ack = din.readUnsignedByte();
+ if (ack != PROTOCOL_ACK) {
+ throw new RemoteException("Unsupported protocol");
+ }
+
+ // Read in host and port
+ String dicard_rhost = din.readUTF();
+ int discard_rport = din.readInt();
+
+ // Send them my endpoint
+ dout.writeUTF(manager.serverName);
+ dout.writeInt(manager.serverPort);
+ }
+ // Okay, ready to roll ...
+}
+
+DataInputStream getDataInputStream() throws IOException {
+ return (din);
+}
+
+DataOutputStream getDataOutputStream() throws IOException {
+ return (dout);
+}
+
+ObjectInputStream getObjectInputStream() throws IOException {
+ if (oin == null) {
+ oin = new RMIObjectInputStream(din, manager);
+ }
+ return (oin);
+}
+
+ObjectOutputStream getObjectOutputStream() throws IOException {
+ if (oout == null) {
+ oout = new RMIObjectOutputStream(dout);
+ }
+ return (oout);
+}
+
+void disconnect() {
+ oin = null;
+ oout = null;
+ try {
+ sock.close();
+ }
+ catch (IOException _) {
+ }
+ din = null;
+ dout = null;
+ sock = null;
+}
+
+/**
+ * We run connects on the server. Dispatch it then discard it.
+ */
+public void run() {
+ try {
+ UnicastServer.dispatch(this);
+ manager.discardConnection(this);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+}
+
+}
diff --git a/libjava/gnu/java/rmi/server/UnicastConnectionManager.java b/libjava/gnu/java/rmi/server/UnicastConnectionManager.java
new file mode 100644
index 0000000..84152bd
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/UnicastConnectionManager.java
@@ -0,0 +1,262 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+import java.rmi.server.RMISocketFactory;
+import java.rmi.server.RMIServerSocketFactory;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.RemoteException;
+import gnu.java.rmi.server.UnicastConnection;
+import java.util.Hashtable;
+import java.net.Socket;
+import java.net.ServerSocket;
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.io.ObjectInput;
+import java.lang.Thread;
+import java.lang.Runnable;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class UnicastConnectionManager
+ implements Runnable, ProtocolConstants {
+
+private static String localhost;
+private static Hashtable servers = new Hashtable();
+
+private Thread serverThread;
+private ServerSocket ssock;
+String serverName;
+int serverPort;
+private RMIServerSocketFactory serverFactory;
+private RMIClientSocketFactory clientFactory;
+
+static {
+ try {
+ localhost = InetAddress.getLocalHost().getHostName();
+ }
+ catch (UnknownHostException _) {
+ localhost = "localhost";
+ }
+}
+
+private UnicastConnectionManager(String host, int port, RMIClientSocketFactory csf) {
+ ssock = null;
+ serverName = host;
+ serverPort = port;
+ serverFactory = null;
+ clientFactory = csf;
+}
+
+private UnicastConnectionManager(int port, RMIServerSocketFactory ssf) {
+ try {
+ ssock = ssf.createServerSocket(port);
+ serverPort = ssock.getLocalPort();
+ }
+ catch (IOException _) {
+ try {
+ ssock = ssf.createServerSocket(0);
+ serverPort = ssock.getLocalPort();
+ }
+ catch (IOException __) {
+ ssock = null;
+ serverPort = 0;
+ }
+ }
+ serverName = localhost;
+ serverFactory = ssf;
+ clientFactory = null;
+}
+
+/**
+ * Return a client connection manager which will connect to the given
+ * host/port.
+ */
+public static synchronized UnicastConnectionManager getInstance(String host, int port, RMIClientSocketFactory csf) {
+//System.out.println("getInstance: " + host + "," + port + "," + csf);
+ if (csf == null) {
+ csf = RMISocketFactory.getSocketFactory();
+ }
+ TripleKey key = new TripleKey(host, port, csf);
+ UnicastConnectionManager man = (UnicastConnectionManager)servers.get(key);
+ if (man == null) {
+ man = new UnicastConnectionManager(host, port, csf);
+ servers.put(key, man);
+ }
+ return (man);
+}
+
+/**
+ * Return a server connection manager which will accept connection on the
+ * given port.
+ */
+public static synchronized UnicastConnectionManager getInstance(int port, RMIServerSocketFactory ssf) {
+//System.out.println("getInstance: " + port + "," + ssf);
+ if (ssf == null) {
+ ssf = RMISocketFactory.getSocketFactory();
+ }
+ TripleKey key = new TripleKey(localhost, port, ssf);
+ UnicastConnectionManager man = (UnicastConnectionManager)servers.get(key);
+ if (man == null) {
+ man = new UnicastConnectionManager(port, ssf);
+ // The provided port might not be the set port.
+ key.port = man.serverPort;
+ servers.put(key, man);
+ }
+ return (man);
+}
+
+/**
+ * Get a connection from this manager.
+ */
+public UnicastConnection getConnection() throws IOException {
+ if (ssock == null) {
+ return (getClientConnection());
+ }
+ else {
+ return (getServerConnection());
+ }
+}
+
+/**
+ * Accept a connection to this server.
+ */
+private UnicastConnection getServerConnection() throws IOException {
+ Socket sock = ssock.accept();
+ UnicastConnection conn = new UnicastConnection(this, sock);
+ conn.acceptConnection();
+//System.out.println("Server connection " + conn);
+ return (conn);
+}
+
+/**
+ * Make a conection from this client to the server.
+ */
+private UnicastConnection getClientConnection() throws IOException {
+ Socket sock = clientFactory.createSocket(serverName, serverPort);
+ UnicastConnection conn = new UnicastConnection(this, sock);
+ conn.makeConnection(DEFAULT_PROTOCOL);
+//System.out.println("Client connection " + conn);
+ return (conn);
+}
+
+/**
+ * Discard a connection when we're done with it - maybe it can be
+ * recycled.
+ */
+public void discardConnection(UnicastConnection conn) {
+//System.out.println("Discarding connection " + conn);
+ conn.disconnect();
+}
+
+/**
+ * Start a server on this manager if it's a server socket and we've not
+ * already got one running.
+ */
+public void startServer() {
+ synchronized(this) {
+ if (ssock == null || serverThread != null) {
+ return;
+ }
+ serverThread = new Thread(this);
+ }
+ serverThread.start();
+}
+
+/**
+ * Server thread for connection manager.
+ */
+public void run() {
+ for (;;) {
+ try {
+//System.out.println("Waiting for connection on " + serverPort);
+ UnicastConnection conn = getServerConnection();
+ (new Thread(conn)).start();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
+
+/**
+ * Serialization routine.
+ */
+void write(ObjectOutput out) throws IOException {
+ out.writeUTF(serverName);
+ out.writeInt(serverPort);
+}
+
+/**
+ * Serialization routine.
+ */
+static UnicastConnectionManager read(ObjectInput in) throws IOException {
+ String host = in.readUTF();
+ int port = in.readInt();
+ RMIClientSocketFactory csf = ((RMIObjectInputStream)in).manager.clientFactory;
+ return (getInstance(host, port, csf));
+}
+
+}
+
+/**
+ * This is use as the hashkey for the client/server connections.
+ */
+class TripleKey {
+
+String host;
+int port;
+Object other;
+
+TripleKey(String host, int port, Object other) {
+ this.host = host;
+ this.port = port;
+ this.other = other;
+}
+
+/**
+ * Hash code just include the host and other - we ignore the port since
+ * this has unusual matching behaviour.
+ */
+public int hashCode() {
+ return (host.hashCode() ^ other.hashCode());
+}
+
+public boolean equals(Object obj) {
+ if (obj instanceof TripleKey) {
+ TripleKey other = (TripleKey)obj;
+ if (this.host.equals(other.host) &&
+ this.other == other.other &&
+ (this.port == other.port || this.port == 0 || other.port == 0)) {
+ return (true);
+ }
+ }
+ return (false);
+}
+
+}
diff --git a/libjava/gnu/java/rmi/server/UnicastRef.java b/libjava/gnu/java/rmi/server/UnicastRef.java
new file mode 100644
index 0000000..837e6e4
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/UnicastRef.java
@@ -0,0 +1,219 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.server.RemoteRef;
+import java.rmi.server.RMISocketFactory;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.server.RMIServerSocketFactory;
+import java.rmi.server.RemoteObject;
+import java.rmi.server.RemoteCall;
+import java.rmi.server.UnicastRemoteObject;
+import java.rmi.server.Operation;
+import java.rmi.server.ObjID;
+import java.rmi.server.UID;
+import java.lang.reflect.Method;
+import java.io.ObjectOutput;
+import java.io.ObjectInput;
+import java.io.IOException;
+import java.net.Socket;
+import java.net.InetAddress;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+
+public class UnicastRef
+ implements RemoteRef, ProtocolConstants {
+
+public ObjID objid;
+UnicastConnectionManager manager;
+
+/**
+ * Used by serialization.
+ */
+private UnicastRef() {
+}
+
+public UnicastRef(ObjID objid, String host, int port, RMIClientSocketFactory csf) {
+ this(objid);
+ manager = UnicastConnectionManager.getInstance(host, port, csf);
+}
+
+public UnicastRef(ObjID objid) {
+ this.objid = objid;
+}
+
+public Object invoke(Remote obj, Method method, Object[] params, long opnum) throws Exception {
+ return (invokeCommon(obj, method, params, -1, opnum));
+}
+
+private Object invokeCommon(Remote obj, Method method, Object[] params, int opnum, long hash) throws Exception {
+ UnicastConnection conn;
+ try {
+ conn = manager.getConnection();
+ }
+ catch (IOException e1) {
+ throw new RemoteException("connection failed to host: " + manager.serverName, e1);
+ }
+
+ ObjectOutputStream out;
+ DataOutputStream dout;
+ try {
+ dout = conn.getDataOutputStream();
+ dout.writeByte(MESSAGE_CALL);
+
+ out = conn.getObjectOutputStream();
+
+ objid.write(out);
+ out.writeInt(opnum);
+ out.writeLong(hash);
+ if (params != null) {
+ for (int i = 0; i < params.length; i++) {
+ if (params[i] instanceof UnicastRemoteObject) {
+ out.writeObject(UnicastRemoteObject.exportObject((UnicastRemoteObject)params[i]));
+ }
+ else {
+ out.writeObject(params[i]);
+ }
+ }
+ }
+
+ out.flush();
+ }
+ catch (IOException e2) {
+ throw new RemoteException("call failed: ", e2);
+ }
+
+ int returncode;
+ Object returnval;
+ DataInputStream din;
+ ObjectInputStream in;
+ UID ack;
+ try {
+ din = conn.getDataInputStream();
+ if (din.readUnsignedByte() != MESSAGE_CALL_ACK) {
+ throw new RemoteException("Call not acked");
+ }
+
+ in = conn.getObjectInputStream();
+
+ returncode = in.readUnsignedByte();
+ ack = UID.read(in);
+ returnval = in.readObject();
+ }
+ catch (IOException e3) {
+ throw new RemoteException("call return failed: ", e3);
+ }
+
+ manager.discardConnection(conn);
+
+ if (returncode != RETURN_ACK) {
+ throw (Exception)returnval;
+ }
+
+ return (returnval);
+}
+
+/**
+ * @deprecated
+ */
+public RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash) throws RemoteException {
+ return (new UnicastRemoteCall(obj, opnum, hash));
+}
+
+/**
+ * @deprecated
+ */
+public void invoke(RemoteCall call) throws Exception {
+ UnicastRemoteCall c = (UnicastRemoteCall)call;
+ Object ret = invokeCommon((Remote)c.getObject(), (Method)null, c.getArguments(), c.getOpnum(), c.getHash());
+ c.setReturnValue(ret);
+}
+
+/**
+ * @deprecated
+ */
+public void done(RemoteCall call) throws RemoteException {
+ /* Does nothing */
+}
+
+public void writeExternal(ObjectOutput out) throws IOException {
+ if (manager == null) {
+ throw new IOException("no connection");
+ }
+ manager.write(out);
+ objid.write(out);
+ out.writeByte(RETURN_ACK);
+}
+
+public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ manager = UnicastConnectionManager.read(in);
+ objid = ObjID.read(in);
+ if (in.readByte() != RETURN_ACK) {
+ throw new IOException("no ack found");
+ }
+}
+
+public boolean remoteEquals(RemoteRef ref) {
+ throw new Error("Not implemented");
+}
+
+public int remoteHashCode() {
+ throw new Error("Not implemented");
+}
+
+public String getRefClass(ObjectOutput out) {
+ return ("UnicastRef");
+}
+
+public String remoteToString() {
+ throw new Error("Not implemented");
+}
+
+public void dump(UnicastConnection conn) {
+ try {
+ DataInputStream din = conn.getDataInputStream();
+ for (;;) {
+ int b = din.readUnsignedByte();
+ System.out.print(Integer.toHexString(b));
+ if (b >= 32 && b < 128) {
+ System.out.print(": " + (char)b);
+ }
+ System.out.println();
+ }
+ }
+ catch (IOException _) {
+ }
+}
+
+}
diff --git a/libjava/gnu/java/rmi/server/UnicastRemoteCall.java b/libjava/gnu/java/rmi/server/UnicastRemoteCall.java
new file mode 100644
index 0000000..42759e7
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/UnicastRemoteCall.java
@@ -0,0 +1,301 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+import java.lang.Exception;
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.io.ObjectInput;
+import java.io.StreamCorruptedException;
+import java.rmi.server.RemoteCall;
+import java.util.Vector;
+
+public class UnicastRemoteCall
+ implements RemoteCall {
+
+private UnicastConnection conn;
+private Object result;
+private Object object;
+private int opnum;
+private long hash;
+private Vector vec;
+private int ptr;
+
+/**
+ * Incoming call.
+ */
+UnicastRemoteCall(UnicastConnection conn) {
+ this.conn = conn;
+}
+
+/**
+ * Outgoing call.
+ */
+UnicastRemoteCall(Object obj, int opnum, long hash) {
+ this.object = obj;
+ this.opnum = opnum;
+ this.hash = hash;
+}
+
+public ObjectOutput getOutputStream() throws IOException {
+ vec = new Vector();
+ return (new DummyObjectOutputStream());
+}
+
+public void releaseOutputStream() throws IOException {
+ // Does nothing.
+}
+
+public ObjectInput getInputStream() throws IOException {
+ if (conn != null) {
+ return (conn.getObjectInputStream());
+ }
+ else {
+ ptr = 0;
+ return (new DummyObjectInputStream());
+ }
+}
+
+public void releaseInputStream() throws IOException {
+ // Does nothing.
+}
+
+public ObjectOutput getResultStream(boolean success) throws IOException, StreamCorruptedException {
+ vec = new Vector();
+ return (new DummyObjectOutputStream());
+}
+
+public void executeCall() throws Exception {
+ throw new Error("Not implemented");
+}
+
+public void done() throws IOException {
+ /* Does nothing */
+}
+
+Object returnValue() {
+ return (vec.elementAt(0));
+}
+
+Object[] getArguments() {
+ return (vec.toArray());
+}
+
+Object getObject() {
+ return (object);
+}
+
+int getOpnum() {
+ return (opnum);
+}
+
+long getHash() {
+ return (hash);
+}
+
+void setReturnValue(Object obj) {
+ vec.removeAllElements();
+ vec.addElement(obj);
+}
+
+/**
+ * Dummy object output class.
+ */
+private class DummyObjectOutputStream implements ObjectOutput {
+
+public void writeBoolean(boolean v) throws IOException {
+ vec.addElement(new Boolean(v));
+}
+
+public void writeByte(int v) throws IOException {
+ vec.addElement(new Byte((byte)v));
+}
+
+public void writeChar(int v) throws IOException {
+ vec.addElement(new Character((char)v));
+}
+
+public void writeDouble(double v) throws IOException {
+ vec.addElement(new Double(v));
+}
+
+public void writeFloat(float v) throws IOException {
+ vec.addElement(new Float(v));
+}
+
+public void writeInt(int v) throws IOException {
+ vec.addElement(new Integer(v));
+}
+
+public void writeLong(long v) throws IOException {
+ vec.addElement(new Long(v));
+}
+
+public void writeShort(int v) throws IOException {
+ vec.addElement(new Short((short)v));
+}
+
+public void writeObject(Object obj) throws IOException {
+ vec.addElement(obj);
+}
+
+public void write(byte b[]) throws IOException {
+ throw new IOException("not required");
+}
+
+public void write(byte b[], int off, int len) throws IOException {
+ throw new IOException("not required");
+}
+
+public void write(int b) throws IOException {
+ throw new IOException("not required");
+}
+
+public void writeBytes(String s) throws IOException {
+ throw new IOException("not required");
+}
+
+public void writeChars(String s) throws IOException {
+ throw new IOException("not required");
+}
+
+public void writeUTF(String str) throws IOException {
+ throw new IOException("not required");
+}
+
+public void flush() throws IOException {
+}
+
+public void close() throws IOException {
+}
+
+}
+
+/**
+ * Dummy object input class.
+ */
+private class DummyObjectInputStream implements ObjectInput {
+
+public boolean readBoolean() throws IOException {
+ Object obj = vec.elementAt(ptr++);
+ return (((Boolean)obj).booleanValue());
+}
+
+public byte readByte() throws IOException {
+ Object obj = vec.elementAt(ptr++);
+ return (((Byte)obj).byteValue());
+}
+
+public char readChar() throws IOException {
+ Object obj = vec.elementAt(ptr++);
+ return (((Character)obj).charValue());
+}
+
+public double readDouble() throws IOException {
+ Object obj = vec.elementAt(ptr++);
+ return (((Double)obj).doubleValue());
+}
+
+public float readFloat() throws IOException {
+ Object obj = vec.elementAt(ptr++);
+ return (((Float)obj).floatValue());
+}
+
+public int readInt() throws IOException {
+ Object obj = vec.elementAt(ptr++);
+ return (((Integer)obj).intValue());
+}
+
+public long readLong() throws IOException {
+ Object obj = vec.elementAt(ptr++);
+ return (((Long)obj).longValue());
+}
+
+public short readShort() throws IOException {
+ Object obj = vec.elementAt(ptr++);
+ return (((Short)obj).shortValue());
+}
+
+public Object readObject() throws IOException {
+ return (vec.elementAt(ptr++));
+}
+
+public int read(byte b[]) throws IOException {
+ throw new IOException("not required");
+}
+
+public int read(byte b[], int off, int len) throws IOException {
+ throw new IOException("not required");
+}
+
+public int read() throws IOException {
+ throw new IOException("not required");
+}
+
+public long skip(long n) throws IOException {
+ throw new IOException("not required");
+}
+
+public int available() throws IOException {
+ throw new IOException("not required");
+}
+
+public void readFully(byte b[]) throws IOException {
+ throw new IOException("not required");
+}
+
+public void readFully(byte b[], int off, int len) throws IOException {
+ throw new IOException("not required");
+}
+
+public String readLine() throws IOException {
+ throw new IOException("not required");
+}
+
+public String readUTF() throws IOException {
+ throw new IOException("not required");
+}
+
+public int readUnsignedByte() throws IOException {
+ throw new IOException("not required");
+}
+
+public int readUnsignedShort() throws IOException {
+ throw new IOException("not required");
+}
+
+public int skipBytes(int n) throws IOException {
+ throw new IOException("not required");
+}
+
+public void close() throws IOException {
+}
+
+}
+
+}
diff --git a/libjava/gnu/java/rmi/server/UnicastRemoteStub.java b/libjava/gnu/java/rmi/server/UnicastRemoteStub.java
new file mode 100644
index 0000000..244e7a8
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/UnicastRemoteStub.java
@@ -0,0 +1,40 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+import java.rmi.server.RemoteStub;
+import java.rmi.server.RemoteRef;
+
+public class UnicastRemoteStub
+ extends RemoteStub {
+
+public static void setStubRef(RemoteStub stub, RemoteRef ref) {
+ setRef(stub, ref);
+}
+
+}
diff --git a/libjava/gnu/java/rmi/server/UnicastServer.java b/libjava/gnu/java/rmi/server/UnicastServer.java
new file mode 100644
index 0000000..d2cc7dc
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/UnicastServer.java
@@ -0,0 +1,119 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.Hashtable;
+import java.net.UnknownHostException;
+import java.rmi.server.ObjID;
+import java.rmi.server.UnicastRemoteObject;
+import java.rmi.server.UID;
+import java.rmi.server.RemoteRef;
+import java.rmi.RemoteException;
+import java.rmi.NoSuchObjectException;
+import gnu.java.rmi.dgc.DGCImpl;
+
+public class UnicastServer
+ implements ProtocolConstants {
+
+static private Hashtable objects = new Hashtable();
+static private DGCImpl dgc;
+
+public static void exportObject(UnicastServerRef obj) {
+ startDGC();
+ objects.put(obj.objid, obj);
+ obj.manager.startServer();
+}
+
+private static synchronized void startDGC() {
+ if (dgc == null) {
+ try {
+ dgc = new DGCImpl();
+ ((UnicastServerRef)dgc.getRef()).exportObject(dgc);
+ }
+ catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+}
+
+public static void dispatch(UnicastConnection conn) throws Exception {
+ switch (conn.getDataInputStream().readUnsignedByte()) {
+ case MESSAGE_CALL:
+ incomingMessageCall(conn);
+ break;
+ default:
+ throw new Exception("bad method type");
+ }
+}
+
+private static void incomingMessageCall(UnicastConnection conn) throws IOException {
+ ObjectInputStream in = conn.getObjectInputStream();
+
+ ObjID objid = ObjID.read(in);
+ int method = in.readInt();
+ long hash = in.readLong();
+
+//System.out.println("ObjID: " + objid + ", method: " + method + ", hash: " + hash);
+
+ // Use the objid to locate the relevant UnicastServerRef
+ UnicastServerRef uref = (UnicastServerRef)objects.get(objid);
+ Object returnval;
+ int returncode = RETURN_ACK;
+ if (uref != null) {
+ try {
+ // Dispatch the call to it.
+ returnval = uref.incomingMessageCall(conn, method, hash);
+ }
+ catch (Exception e) {
+ returnval = e;
+ returncode = RETURN_NACK;
+ }
+ }
+ else {
+ returnval = new NoSuchObjectException("");
+ returncode = RETURN_NACK;
+ }
+
+ conn.getDataOutputStream().writeByte(MESSAGE_CALL_ACK);
+
+ ObjectOutputStream out = conn.getObjectOutputStream();
+
+ out.writeByte(returncode);
+ (new UID()).write(out);
+ out.writeObject(returnval);
+
+ out.flush();
+}
+
+}
diff --git a/libjava/gnu/java/rmi/server/UnicastServerRef.java b/libjava/gnu/java/rmi/server/UnicastServerRef.java
new file mode 100644
index 0000000..290ea09
--- /dev/null
+++ b/libjava/gnu/java/rmi/server/UnicastServerRef.java
@@ -0,0 +1,198 @@
+/*
+ Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.java.rmi.server;
+
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.server.RemoteStub;
+import java.rmi.server.ObjID;
+import java.rmi.server.ServerRef;
+import java.rmi.server.RemoteRef;
+import java.rmi.server.ServerNotActiveException;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.server.RMIServerSocketFactory;
+import java.rmi.server.UID;
+import java.rmi.server.Skeleton;
+import java.rmi.server.RemoteCall;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.Thread;
+import java.lang.Exception;
+import java.io.IOException;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Hashtable;
+
+public class UnicastServerRef
+ extends UnicastRef {
+
+final static private Class[] stubprototype = new Class[] { RemoteRef.class };
+
+Remote myself;
+private Skeleton skel;
+private RemoteStub stub;
+private Hashtable methods;
+
+public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory ssf) {
+ super(id);
+ manager = UnicastConnectionManager.getInstance(port, ssf);
+}
+
+public RemoteStub exportObject(Remote obj) throws RemoteException {
+ if (myself == null) {
+ myself = obj;
+
+ // Find and install the stub
+ Class cls = obj.getClass();
+ stub = (RemoteStub)getHelperClass(cls, "_Stub");
+ if (stub == null) {
+ throw new RemoteException("failed to export: " + cls);
+ }
+
+ // Find and install the skeleton (if there is one)
+ skel = (Skeleton)getHelperClass(cls, "_Skel");
+
+ // Build hash of methods which may be called.
+ buildMethodHash(obj.getClass());
+
+ // Export it.
+ UnicastServer.exportObject(this);
+ }
+
+ return (stub);
+}
+
+private Object getHelperClass(Class cls, String type) {
+ try {
+ String classname = cls.getName();
+ Class scls = Class.forName(classname + type);
+ if (type.equals("_Stub")) {
+ try {
+ // JDK 1.2 stubs
+ Constructor con = scls.getConstructor(stubprototype);
+ return (con.newInstance(new Object[]{this}));
+ }
+ catch (NoSuchMethodException e) {
+ }
+ catch (InstantiationException e) {
+ }
+ catch (IllegalAccessException e) {
+ }
+ catch (IllegalArgumentException e) {
+ }
+ catch (InvocationTargetException e) {
+ }
+ // JDK 1.1 stubs
+ RemoteStub stub = (RemoteStub)scls.newInstance();
+ UnicastRemoteStub.setStubRef(stub, this);
+ return (stub);
+ }
+ else {
+ // JDK 1.1 skel
+ return (scls.newInstance());
+ }
+ }
+ catch (ClassNotFoundException e) {
+ }
+ catch (InstantiationException e) {
+ }
+ catch (IllegalAccessException e) {
+ }
+ return (null);
+}
+
+public String getClientHost() throws ServerNotActiveException {
+ throw new Error("Not implemented");
+}
+
+private void buildMethodHash(Class cls) {
+ methods = new Hashtable();
+ Method[] meths = cls.getMethods();
+ for (int i = 0; i < meths.length; i++) {
+ /* Don't need to include any java.xxx related stuff */
+ if (meths[i].getDeclaringClass().getName().startsWith("java.")) {
+ continue;
+ }
+ long hash = RMIHashes.getMethodHash(meths[i]);
+ methods.put(new Long (hash), meths[i]);
+//System.out.println("meth = " + meths[i] + ", hash = " + hash);
+ }
+}
+
+public Object incomingMessageCall(UnicastConnection conn, int method, long hash) throws Exception {
+//System.out.println("method = " + method + ", hash = " + hash);
+ // If method is -1 then this is JDK 1.2 RMI - so use the hash
+ // to locate the method
+ if (method == -1) {
+ Method meth = (Method)methods.get(new Long (hash));
+//System.out.println("class = " + myself.getClass() + ", meth = " + meth);
+ if (meth == null) {
+ throw new NoSuchMethodException();
+ }
+
+ ObjectInputStream in = conn.getObjectInputStream();
+ int nrargs = meth.getParameterTypes().length;
+ Object[] args = new Object[nrargs];
+ for (int i = 0; i < nrargs; i++) {
+ /**
+ * For debugging purposes - we don't handle CodeBases
+ * quite right so we don't always find the stubs. This
+ * lets us know that.
+ */
+ try {
+ args[i] = in.readObject();
+ }
+ catch (Exception t) {
+ t.printStackTrace();
+ throw t;
+ }
+ }
+ return (meth.invoke(myself, args));
+ }
+ // Otherwise this is JDK 1.1 style RMI - we find the skeleton
+ // and invoke it using the method number. We wrap up our
+ // connection system in a UnicastRemoteCall so it appears in a
+ // way the Skeleton can handle.
+ else {
+ if (skel == null) {
+ throw new NoSuchMethodException();
+ }
+ UnicastRemoteCall call = new UnicastRemoteCall(conn);
+ skel.dispatch(myself, call, method, hash);
+ return (call.returnValue());
+ }
+}
+
+}