Imported GNU Classpath 0.90

Imported GNU Classpath 0.90
       * scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore.
       * gnu/classpath/jdwp/VMFrame.java (SIZE): New constant.
       * java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5.
       * java/lang/Math.java: New override file.
       * java/lang/Character.java: Merged from Classpath.
       (start, end): Now 'int's.
       (canonicalName): New field.
       (CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants.
       (UnicodeBlock): Added argument.
       (of): New overload.
       (forName): New method.
       Updated unicode blocks.
       (sets): Updated.
       * sources.am: Regenerated.
       * Makefile.in: Likewise.

From-SVN: r111942
This commit is contained in:
Mark Wielaard 2006-03-10 21:46:48 +00:00
parent 27079765d0
commit 8aa540d2f7
1367 changed files with 188789 additions and 22762 deletions

View file

@ -1,5 +1,6 @@
/* AccessException.java -- thrown if the caller does not have access
Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -43,7 +44,7 @@ package java.rmi;
*
* @author unknown
* @see Naming
* @see ActivationSystem
* @see java.rmi.activation.ActivationSystem
* @since 1.1
*/
public class AccessException extends RemoteException

View file

@ -1,5 +1,6 @@
/* AlreadyBoundException.java -- thrown if a binding is already bound
Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -42,8 +43,8 @@ package java.rmi;
* bound.
*
* @author unknown
* @see Naming#bind(String, Remote)
* @see Registry#bind(String, Remote)
* @see java.rmi.Naming#bind(String, Remote)
* @see java.rmi.registry.Registry#bind(String, Remote)
* @since 1.1
* @status updated to 1.4
*/

View file

@ -1,5 +1,6 @@
/* MarshalledObject.java --
Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2004, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -42,38 +43,68 @@ import gnu.java.rmi.RMIMarshalledObjectInputStream;
import gnu.java.rmi.RMIMarshalledObjectOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;
/**
* FIXME - doc missing
* A <code>MarshalledObject</code> consists of a serialized object which is
* marshalled according to the RMI specification.
* <p>
* An object passed to the constructor is serialized and tagged with the needed
* URL to retrieve its class definition for remote usage. If the object is a
* remote reference its stub is serialized instead. The instance of this
* marshalled object can be later retrieved by its <code>get()</code> method.
* </p>
*
* @author unknown
*/
public final class MarshalledObject implements Serializable
public final class MarshalledObject
implements Serializable
{
//The following fields are from Java API Documentation "Serialized form"
// The following fields are from Java API Documentation "Serialized form"
private static final long serialVersionUID = 8988374069173025854L;
byte[] objBytes;
byte[] locBytes;
int hash;
public MarshalledObject(Object obj) throws java.io.IOException
/**
* Constructs a <code>MarshalledObject</code> from the given object.
*
* @param obj the object to marshal
* @throws IOException if an I/O error during serialization occurs.
*/
public MarshalledObject(Object obj) throws IOException
{
ByteArrayOutputStream objStream = new ByteArrayOutputStream();
RMIMarshalledObjectOutputStream stream = new RMIMarshalledObjectOutputStream(objStream);
RMIMarshalledObjectOutputStream stream =
new RMIMarshalledObjectOutputStream(objStream);
stream.writeObject(obj);
stream.flush();
objBytes = objStream.toByteArray();
locBytes = stream.getLocBytes();
//The following algorithm of calculating hashCode is similar to String
// The following algorithm of calculating hashCode is similar to String
hash = 0;
for (int i = 0; i < objBytes.length; i++)
hash = hash * 31 + objBytes[i];
if(locBytes != null)
if (locBytes != null)
for (int i = 0; i < locBytes.length; i++)
hash = hash * 31 + locBytes[i];
hash = hash * 31 + locBytes[i];
}
public boolean equals(Object obj)
/**
* Checks if the given object is equal to this marshalled object.
*
* <p>Marshalled objects are considered equal if they contain the
* same serialized object. Codebase annotations where the class
* definition can be downloaded are ignored in the equals test.</p>
*
* @param obj the object to compare.
* @return <code>true</code> if equal, <code>false</code> otherwise.
*/
public boolean equals(Object obj)
{
if (! (obj instanceof MarshalledObject))
return false;
@ -81,33 +112,43 @@ public final class MarshalledObject implements Serializable
// hashCode even differs, don't do the time-consuming comparisons
if (obj.hashCode() != hash)
return false;
MarshalledObject aobj = (MarshalledObject)obj;
MarshalledObject aobj = (MarshalledObject) obj;
if (objBytes == null || aobj.objBytes == null)
return objBytes == aobj.objBytes;
if (objBytes.length != aobj.objBytes.length)
return false;
for (int i = 0; i < objBytes.length; i++)
for (int i = 0; i < objBytes.length; i++)
{
if (objBytes[i] != aobj.objBytes[i])
return false;
if (objBytes[i] != aobj.objBytes[i])
return false;
}
// Ignore comparison of locBytes(annotation)
return true;
}
public Object get()
throws java.io.IOException, java.lang.ClassNotFoundException
{
if(objBytes == null)
return null;
RMIMarshalledObjectInputStream stream =
new RMIMarshalledObjectInputStream(objBytes, locBytes);
return stream.readObject();
}
public int hashCode() {
/**
* Constructs and returns a copy of the internal serialized object.
*
* @return The deserialized object.
*
* @throws IOException if an I/O exception occurs during deserialization.
* @throws ClassNotFoundException if the class of the deserialized object
* cannot be found.
*/
public Object get() throws IOException, ClassNotFoundException
{
if (objBytes == null)
return null;
RMIMarshalledObjectInputStream stream =
new RMIMarshalledObjectInputStream(objBytes, locBytes);
return stream.readObject();
}
public int hashCode()
{
return hash;
}
}

View file

@ -1,5 +1,6 @@
/* Naming.java --
Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2004, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -76,136 +77,150 @@ import java.rmi.registry.Registry;
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.1
*/
public final class Naming {
public final class Naming
{
/**
* This class isn't intended to be instantiated.
*/
private Naming() {}
/**
* Looks for the remote object that is associated with the named service.
* Name and location is given in form of a URL without a scheme:
*
* <pre>
* //host:port/service-name
* </pre>
*
* The port is optional.
*
* @param name the service name and location
* @return Remote-object that implements the named service
* @throws NotBoundException if no object implements the service
* @throws MalformedURLException
* @throws RemoteException
*/
public static Remote lookup(String name) throws NotBoundException, MalformedURLException, RemoteException {
URL u = parseURL(name);
String serviceName = getName(u);
return (getRegistry(u).lookup(serviceName));
}
/**
* Try to bind the given object to the given service name.
* @param name
* @param obj
* @throws AlreadyBoundException
* @throws MalformedURLException
* @throws RemoteException
*/
public static void bind(String name, Remote obj) throws AlreadyBoundException, MalformedURLException, RemoteException {
URL u = parseURL(name);
String serviceName = getName(u);
getRegistry(u).bind(serviceName, obj);
}
/**
* Remove a binding for a given service name.
* @param name
* @throws RemoteException
* @throws NotBoundException
* @throws MalformedURLException
*/
public static void unbind(String name) throws RemoteException, NotBoundException, MalformedURLException {
URL u = parseURL(name);
String serviceName = getName(u);
getRegistry(u).unbind(serviceName);
}
/**
* Forces the binding between the given Remote-object and the given service name, even
* if there was already an object bound to this name.
* @param name
* @param obj
* @throws RemoteException
* @throws MalformedURLException
*/
public static void rebind(String name, Remote obj) throws RemoteException, MalformedURLException {
URL u = parseURL(name);
String serviceName = getName(u);
getRegistry(u).rebind(serviceName, obj);
}
/**
* Lists all services at the named registry.
* @param name url that specifies the registry
* @return list of services at the name registry
* @throws RemoteException
* @throws MalformedURLException
*/
public static String[] list(String name) throws RemoteException, MalformedURLException {
return (getRegistry(parseURL(name)).list());
}
private static Registry getRegistry(URL u) throws RemoteException {
if (u.getPort() == -1) {
return (LocateRegistry.getRegistry(u.getHost()));
}
else {
return (LocateRegistry.getRegistry(u.getHost(), u.getPort()));
}
}
private Naming()
{
}
/**
* Parses the supplied URL and converts it to use the HTTP
* protocol. From an RMI perspective, the scheme is irrelevant
* and we want to be able to create a URL for which a handler is
* available.
*
* @param name the URL in String form.
* @throws MalformedURLException if the URL is invalid.
* Looks for the remote object that is associated with the named service.
* Name and location is given in form of a URL without a scheme:
*
* <pre>
* //host:port/service-name
* </pre>
*
* The port is optional.
*
* @param name the service name and location
* @return Remote-object that implements the named service
* @throws NotBoundException if no object implements the service
* @throws MalformedURLException
* @throws RemoteException
*/
private static URL parseURL(String name)
throws MalformedURLException
public static Remote lookup(String name) throws NotBoundException,
MalformedURLException, RemoteException
{
try
URL u = parseURL(name);
String serviceName = getName(u);
return (getRegistry(u).lookup(serviceName));
}
/**
* Try to bind the given object to the given service name.
*
* @param name
* @param obj
* @throws AlreadyBoundException
* @throws MalformedURLException
* @throws RemoteException
*/
public static void bind(String name, Remote obj)
throws AlreadyBoundException, MalformedURLException, RemoteException
{
URL u = parseURL(name);
String serviceName = getName(u);
getRegistry(u).bind(serviceName, obj);
}
/**
* Remove a binding for a given service name.
*
* @param name
* @throws RemoteException
* @throws NotBoundException
* @throws MalformedURLException
*/
public static void unbind(String name) throws RemoteException,
NotBoundException, MalformedURLException
{
URL u = parseURL(name);
String serviceName = getName(u);
getRegistry(u).unbind(serviceName);
}
/**
* Forces the binding between the given Remote-object and the given service
* name, even if there was already an object bound to this name.
*
* @param name
* @param obj
* @throws RemoteException
* @throws MalformedURLException
*/
public static void rebind(String name, Remote obj) throws RemoteException,
MalformedURLException
{
URL u = parseURL(name);
String serviceName = getName(u);
getRegistry(u).rebind(serviceName, obj);
}
/**
* Lists all services at the named registry.
*
* @param name url that specifies the registry
* @return list of services at the name registry
* @throws RemoteException
* @throws MalformedURLException
*/
public static String[] list(String name) throws RemoteException,
MalformedURLException
{
return (getRegistry(parseURL(name)).list());
}
private static Registry getRegistry(URL u) throws RemoteException
{
if (u.getPort() == - 1)
{
URI uri = new URI(name);
String host = uri.getHost();
int port = uri.getPort();
String query = uri.getQuery();
String path = uri.getPath();
return new URL("http",
(host == null ? "localhost" : host),
(port == -1 ? 1099 : port),
uri.getPath() + (query == null ? "" : query));
return (LocateRegistry.getRegistry(u.getHost()));
}
catch (URISyntaxException e)
else
{
throw new MalformedURLException("The URL syntax was invalid: " +
e.getMessage());
return (LocateRegistry.getRegistry(u.getHost(), u.getPort()));
}
}
/**
* Checks that the URL contains a name, and removes any leading
* slashes.
*
* Parses the supplied URL and converts it to use the HTTP protocol. From an
* RMI perspective, the scheme is irrelevant and we want to be able to create
* a URL for which a handler is available.
*
* @param name the URL in String form.
* @throws MalformedURLException if the URL is invalid.
*/
private static URL parseURL(String name) throws MalformedURLException
{
try
{
URI uri = new URI(name);
String host = uri.getHost();
int port = uri.getPort();
String query = uri.getQuery();
String path = uri.getPath();
return new URL("http", (host == null ? "localhost" : host),
(port == - 1 ? 1099 : port), uri.getPath()
+ (query == null ? "" : query));
}
catch (URISyntaxException e)
{
throw new MalformedURLException("The URL syntax was invalid: "
+ e.getMessage());
}
}
/**
* Checks that the URL contains a name, and removes any leading slashes.
*
* @param url the URL to check.
* @throws MalformedURLException if no name is specified.
*/
private static String getName(URL url)
throws MalformedURLException
*/
private static String getName(URL url) throws MalformedURLException
{
String filename = url.getFile();
if (filename.length() == 0)
@ -216,5 +231,4 @@ private static Registry getRegistry(URL u) throws RemoteException {
return filename.substring(1);
return filename;
}
}

View file

@ -1,5 +1,6 @@
/* NoSuchObjectException.java -- thrown if the remote object no longer exists
Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -43,9 +44,9 @@ package java.rmi;
* obey the semantics of "at most once".
*
* @author unknown
* @see RemoteObject#toStub(Remote)
* @see UnicastRemoteObject#unexportObject(Remote, boolean)
* @see Activatable#unexportObject(Remote, boolean)
* @see java.rmi.server.RemoteObject#toStub(Remote)
* @see java.rmi.server.UnicastRemoteObject#unexportObject(Remote, boolean)
* @see java.rmi.activation.Activatable#unexportObject(Remote, boolean)
* @since 1.1
* @status updated to 1.4
*/

View file

@ -1,5 +1,6 @@
/* NotBoundException.java -- attempt to use a registry name with no binding
Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -42,10 +43,10 @@ package java.rmi;
* associated binding.
*
* @author unknown
* @see Naming#lookup(String)
* @see Naming#unbind(String)
* @see Registry#lookup(String)
* @see Registry#unbind(String)
* @see java.rmi.Naming#lookup(String)
* @see java.rmi.Naming#unbind(String)
* @see java.rmi.registry.Registry#lookup(String)
* @see java.rmi.registry.Registry#unbind(String)
* @since 1.1
* @status updated to 1.4
*/

View file

@ -1,5 +1,6 @@
/* RMISecurityException.java -- deprecated version of SecurityException
Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -38,11 +39,12 @@ exception statement from your version. */
package java.rmi;
/**
* Never thrown, but originally intended to wrap a java.lang.SecurityException.
* Never thrown, but originally intended to wrap a
* {@link java.lang.SecurityException} in the case of RMI.
*
* @author unknown
* @since 1.1
* @deprecated use {@link SecurityException} instead
* @deprecated use {@link java.lang.SecurityException} instead
* @status updated to 1.4
*/
public class RMISecurityException extends SecurityException
@ -55,7 +57,7 @@ public class RMISecurityException extends SecurityException
/**
* Create an exception with a message.
*
* @param s the message
* @param n the message
* @deprecated no longer needed
*/
public RMISecurityException(String n)
@ -66,8 +68,8 @@ public class RMISecurityException extends SecurityException
/**
* Create an exception with a message and a cause.
*
* @param s the message
* @param e the cause
* @param n the message
* @param a the cause (ignored)
* @deprecated no longer needed
*/
public RMISecurityException(String n, String a)

View file

@ -1,5 +1,5 @@
/* Remote.java
Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -37,5 +37,22 @@ exception statement from your version. */
package java.rmi;
/**
* Marker interface for interfaces which methods are invokable
* from outside of this virtual machine through remote method calls.
* <p>
* Remote invokable methods of remote object implementations are specified
* as the methods defined in the implemented remote interfaces. Typically
* remote object implementations are subclasses of the convenience classes
* {@link java.rmi.server.UnicastRemoteObject} or
* {@link java.rmi.activation.Activatable} implementing one or more remote
* interfaces indicating their remotely accessible methods. The convenience
* classes provide implementations for correct remote object creation,
* hash, equals and toString methods.
* </p>
*
* @author unknown
*/
public interface Remote {
// marker interface
}

View file

@ -1,5 +1,6 @@
/* RemoteException.java -- common superclass for exceptions in java.rmi
Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -86,7 +87,7 @@ public class RemoteException extends IOException
* Create an exception with the given message and cause.
*
* @param s the message
* @param ex the cause
* @param e the cause
*/
public RemoteException(String s, Throwable e)
{

View file

@ -1,5 +1,6 @@
/* StubNotFoundException.java -- thrown if a valid stub is not found
Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -41,8 +42,8 @@ package java.rmi;
* Thrown if a valid stub class is not found for an object when it is exported.
*
* @author unknown
* @see UnicastRemoteObject
* @see Activatable
* @see java.rmi.server.UnicastRemoteObject
* @see java.rmi.activation.Activatable
* @since 1.1
* @status updated to 1.4
*/

View file

@ -41,11 +41,40 @@ import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.ObjID;
public interface DGC extends Remote
/**
* The DGC implementation is used for the server side during the distributed
* garbage collection. This interface contains the two methods: dirty and clean.
* A dirty call is made when a remote reference is unmarshaled in a client. A
* corresponding clean call is made by client it no longer uses that remote
* reference. A reference to a remote object is also automatically released
* after so called lease period that starts after the dirty call is received. It
* is the client's responsibility to renew the leases, by making additional
* dirty calls before such leases expire.
*/
public interface DGC
extends Remote
{
Lease dirty (ObjID[] ids, long sequenceNum, Lease lease)
throws RemoteException;
/**
* Mark the given objects referecnes as used on the client side.
*
* @param ids the ids of the used objects.
* @param sequenceNum the number of the call (used to detect and discard late
* calls).
* @param lease the requested lease
* @return the granted lease
*/
Lease dirty(ObjID[] ids, long sequenceNum, Lease lease)
throws RemoteException;
void clean (ObjID[] ids, long sequenceNum, VMID vmid, boolean strong)
throws RemoteException;
/**
* Mark the given objects as no longer used on the client side.
*
* @param ids the ids of the objects that are no longer used.
* @param sequenceNum the number of the call (used to detect and discard late
* @param vmid the VMID of the client.
* @param strong make the "strong" clean call ("strong" calls are scheduled
* after the failed dirty calls).
*/
void clean(ObjID[] ids, long sequenceNum, VMID vmid, boolean strong)
throws RemoteException;
}

View file

@ -1,5 +1,6 @@
/* Lease.java
Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -7,7 +8,7 @@ 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
@ -39,29 +40,61 @@ package java.rmi.dgc;
import java.io.Serializable;
/**
* A lease object is used to request and grant leases for the remote objects. It
* contains the lease duration and the unique VM indentifier.
*/
public final class Lease
implements Serializable {
implements Serializable
{
static final long serialVersionUID = -5713411624328831948L;
static final long serialVersionUID = - 5713411624328831948L;
private VMID vmid;
private long value;
private VMID vmid;
public Lease(VMID id, long duration) {
vmid = id;
value = duration;
}
private long value;
public VMID getVMID() {
return (vmid);
}
/**
* Create the new lease with the given id and duration
*
* @param id the lease id
* @param duration the lease duration
*/
public Lease(VMID id, long duration)
{
vmid = id;
value = duration;
}
public long getValue() {
return (value);
}
/**
* Get the lease id.
*
* @return the lease id
*/
public VMID getVMID()
{
return (vmid);
}
public String toString() {
return ("[" + vmid.toString() + ", " + Long.toString(value) + "]");
}
/**
* Get the lease duration
*
* @return the lease duration
*/
public long getValue()
{
return (value);
}
/**
* Get the string representation of this lease
*
* @return the string represenation (lease id, followed by the lease
* duration).
*/
public String toString()
{
return ("[" + vmid.toString() + ", " + Long.toString(value) + "]");
}
}

View file

@ -40,7 +40,7 @@ exception statement from your version. -->
<head><title>GNU Classpath - java.rmi</title></head>
<body>
<p></p>
<p>Provides basic Remote Method Invocation (RMI) interfaces, classes and exceptions.</p>
</body>
</html>

View file

@ -47,7 +47,29 @@ import java.rmi.RemoteException;
public interface Registry extends Remote
{
int REGISTRY_PORT = 1099;
/**
* Find and return the reference to the object that was previously bound
* to the registry by this name. For remote objects, this method returns
* the stub instances, containing the code for remote invocations.
*
* Since jdk 1.5 this method does not longer require the stub class
* (nameImpl_Stub) to be present. If such class is not found, the stub is
* replaced by the dynamically constructed proxy class. No attempt to find
* and load the stubs is made if the system property
* java.rmi.server.ignoreStubClasses is set to true (set to reduce the
* starting time if the stubs are surely not present and exclusively 1.2
* RMI is used).
*
* @param name the name of the object
*
* @return the reference to that object on that it is possible to invoke
* the (usually remote) object methods.
*
* @throws RemoteException
* @throws NotBoundException
* @throws AccessException
*/
Remote lookup(String name)
throws RemoteException, NotBoundException, AccessException;

View file

@ -38,10 +38,13 @@ exception statement from your version. */
package java.rmi.server;
import gnu.classpath.ServiceFactory;
import gnu.classpath.SystemProperties;
import gnu.java.rmi.server.RMIClassLoaderImpl;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
/**
* This class provides a set of public static utility methods for supporting
@ -84,6 +87,16 @@ public class RMIClassLoader
return spi.loadClass(codebase, name, defaultLoader);
}
public static Class loadProxyClass (String codeBase, String[] interfaces,
ClassLoader defaultLoader)
throws MalformedURLException, ClassNotFoundException
{
RMIClassLoaderSpi spi = getProviderInstance();
if (spi == null)
spi = getDefaultProviderInstance();
return spi.loadProxyClass(codeBase, interfaces, defaultLoader);
}
/**
* Loads a class from <code>codeBase</code>.
*
@ -171,7 +184,20 @@ public class RMIClassLoader
*/
private static RMIClassLoaderSpi getProviderInstance()
{
// TODO: Do something more useful here.
return null;
// If the user asked for the default, return it. We do a special
// check here because our standard service lookup function does not
// handle this -- nor should it.
String prop = SystemProperties.getProperty("java.rmi.server.RMIClassLoaderSpi");
if ("default".equals(prop))
return null;
Iterator it = ServiceFactory.lookupProviders(RMIClassLoaderSpi.class,
null);
if (it == null || ! it.hasNext())
return null;
// FIXME: the spec says we ought to throw an Error of some kind if
// the specified provider is not suitable for some reason. However
// our service factory simply logs the problem and moves on to the next
// provider in this situation.
return (RMIClassLoaderSpi) it.next();
}
}

View file

@ -0,0 +1,221 @@
/* RemoteObjectInvocationHandler.java -- RMI stub replacement.
Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.rmi.server;
import gnu.java.rmi.server.RMIHashes;
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.UnexpectedException;
import java.rmi.registry.Registry;
import java.rmi.server.RemoteObject;
import java.rmi.server.RemoteRef;
import java.rmi.server.UnicastRemoteObject;
import java.util.Hashtable;
/**
* Together with dynamic proxy instance, this class replaces the generated RMI
* stub (*_Stub) classes that (following 1.5 specification) should be no longer
* required. It is unusual to use the instances of this class directly in the
* user program. Such instances are automatically created and returned by
* {@link Registry} or {@link UnicastRemoteObject} methods if the remote
* reference is known but the corresponding stub class is not accessible.
*
* @see Registry#lookup
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class RemoteObjectInvocationHandler extends RemoteObject implements
InvocationHandler, Remote, Serializable
{
/**
* Use the jdk 1.5 SUID for interoperability.
*/
static final long serialVersionUID = 2L;
/**
* The RMI method hash codes, computed once as described in the section 8.3
* of the Java Remote Method Invocation (RMI) Specification.
*/
static Hashtable methodHashCodes = new Hashtable();
/**
* The empty class array to define parameters of .hashCode and .toString.
*/
static final Class[] noArgsC = new Class[0];
/**
* The class array to define parameters of .equals
*/
static final Class[] anObjectC = new Class[] { Object.class };
/**
* Construct the remote invocation handler that forwards calls to the given
* remote object.
*
* @param reference the reference to the remote object where the method
* calls should be forwarded.
*/
public RemoteObjectInvocationHandler(RemoteRef reference)
{
super(reference);
}
/**
* Invoke the remote method. When the known method is invoked on a created RMI
* stub proxy class, the call is delivered to this method and then transferred
* to the {@link RemoteRef#invoke(Remote, Method, Object[], long)} of the
* remote reference that was passed in constructor. The methods are handled as
* following:
* <ul>
* <li> The toString() method is delegated to the passed proxy instance.</li>
* <li>The .equals method only returns true if the passed object is an
* instance of proxy class and its invocation handler is equal to this
* invocation handles.</li>
* <li>The .hashCode returns the hashCode of this invocation handler (if the.</li>
* <li>All other methods are converted to remote calls and forwarded to the
* remote reference. </li>
* </ul>
*
* @param proxyInstance
* the instance of the proxy stub
* @param method
* the method being invoked
* @param parameters
* the method parameters
* @return the method return value, returned by RemoteRef.invoke
* @throws IllegalAccessException
* if the passed proxy instance does not implement Remote interface.
* @throws UnexpectedException
* if remote call throws some exception, not listed in the
* <code>throws</code> clause of the method being called.
* @throws Throwable
* that is thrown by remote call, if that exception is listend in
* the <code>throws</code> clause of the method being called.
*/
public Object invoke(Object proxyInstance, Method method, Object[] parameters)
throws Throwable
{
if (!(proxyInstance instanceof Remote))
{
String name = proxyInstance == null ? "null"
: proxyInstance.getClass().getName();
throw new IllegalAccessException(name + " does not implement "
+ Remote.class.getName());
}
String name = method.getName();
switch (name.charAt(0))
{
case 'e':
if (parameters.length == 1 && name.equals("equals")
&& method.getParameterTypes()[0].equals(Object.class))
{
if (parameters[0] instanceof Proxy)
{
Object handler = Proxy.getInvocationHandler(parameters[0]);
if (handler == null)
return Boolean.FALSE;
else
return handler.equals(this) ? Boolean.TRUE : Boolean.FALSE;
}
else
return Boolean.FALSE;
}
break;
case 'h':
if (parameters.length == 0 && name.equals("hashCode"))
{
int hashC = Proxy.getInvocationHandler(proxyInstance).hashCode();
return new Integer(hashC);
}
break;
case 't':
if (parameters.length == 0 && name.equals("toString"))
return proxyInstance.toString();
break;
default:
break;
}
Long hash = (Long) methodHashCodes.get(method);
if (hash == null)
{
hash = new Long(RMIHashes.getMethodHash(method));
methodHashCodes.put(method, hash);
}
try
{
return getRef().invoke((Remote) proxyInstance, method, parameters,
hash.longValue());
}
catch (RuntimeException exception)
{
// RuntimeException is always supported.
throw exception;
}
catch (RemoteException exception)
{
// All remote methods can throw RemoteException.
throw exception;
}
catch (Error exception)
{
throw exception;
}
catch (Exception exception)
{
Class[] exceptions = method.getExceptionTypes();
Class exceptionClass = exception.getClass();
for (int i = 0; i < exceptions.length; i++)
{
if (exceptions[i].equals(exceptionClass))
throw exception;
}
throw new UnexpectedException(method.getName(), exception);
}
}
}

View file

@ -1,5 +1,6 @@
/* RemoteRef.java --
Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2004, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -44,8 +45,16 @@ import java.lang.reflect.Method;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* Represents a handler to the remote object. Each instance of the
* {@link RemoteStub} contains such handler and uses it to invoke remote
* methods via {@link #invoke(Remote, Method, Object[], long)}.
*/
public interface RemoteRef extends Externalizable
{
/**
* Indicates compatibility with JDK 1.1.*
*/
long serialVersionUID = 3632638527362204081L;
/**
@ -55,29 +64,74 @@ public interface RemoteRef extends Externalizable
String packagePrefix = "sun.rmi.server";
/**
* @deprecated
* @deprecated use {@link #invoke(Remote, Method, Object[], long)} instead.
*/
void invoke (RemoteCall call) throws Exception;
Object invoke (Remote obj, Method method, Object[] params, long opnum)
/**
* Invoke a method. This method either returns the result of remote invocation
* or throws RemoteException if the remote call failed. Other exceptions may
* be thrown if some problem has occured in the application level.
*
* @param obj the object, containing the remote reference (for instance,
* remote stub, generated by rmic).
* @param method the method to invoke
* @param params the method parameters
* @param methodHash a persistent hash code that can be used to represent a
* method
* @return the result of the remote invocation
* @throws RemoteException if the remote call has failed
* @throws Exception if one is raised at the application level
*/
Object invoke (Remote obj, Method method, Object[] params, long methodHash)
throws Exception;
/**
* @deprecated
* @deprecated use {@link #invoke(Remote, Method, Object[], long)} instead.
*/
RemoteCall newCall (RemoteObject obj, Operation[] op, int opnum, long hash)
throws RemoteException;
/**
* @deprecated
* @deprecated use {@link #invoke(Remote, Method, Object[], long)} instead.
*/
void done (RemoteCall call) throws RemoteException;
/**
* Compare two remote objects for equality. The references are equal if
* they point to the same remote object.
*
* @param ref the reference to compare.
*
* @return true if this and passed references both point to the same remote
* object, false otherwise.
*/
boolean remoteEquals (RemoteRef ref);
/**
* Get the hashcode for a remote object. Two remote object stubs, referring
* to the same remote object, have the same hash code.
*
* @return the hashcode of the remote object
*/
int remoteHashCode();
/**
* Returns the class name of the reference type that must be written to the
* given stream. When writing, this returned name is passed first, and
* the reference.writeExternal(out) writes the reference specific data.
*
* @param out the stream, where the data must be written
*
* @return the class name.
*/
String getRefClass (ObjectOutput out);
/**
* Get the string representation of this remote reference.
*
* @return the string representation.
*/
String remoteToString();
}

View file

@ -37,21 +37,40 @@ exception statement from your version. */
package java.rmi.server;
/**
* This is a base class for the automatically generated RMI stubs.
*/
public abstract class RemoteStub extends RemoteObject
{
/**
* Use serialVersionUID for interoperability.
*/
static final long serialVersionUID = -1585587260594494182l;
/**
* Constructs the remote stub with no reference set.
*/
protected RemoteStub ()
{
super ();
}
/**
* Constructs the remote stub that uses given remote reference for the
* method invocations.
*
* @param ref the remote reference for the method invocation.
*/
protected RemoteStub (RemoteRef ref)
{
super (ref);
}
/**
* Sets the given remote reference for the given stub. This method is
* deprecated. Pass the stub remote reference to the RemoteStub
* constructor instead.
*
* @deprecated
*/
protected static void setRef (RemoteStub stub, RemoteRef ref)

View file

@ -1,5 +1,6 @@
/* UnicastRemoteObject.java --
Copyright (c) 1996, 1997, 1998, 1999, 2002, 2003 Free Software Foundation, Inc.
Copyright (c) 1996, 1997, 1998, 1999, 2002, 2003, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -44,61 +45,175 @@ import java.rmi.NoSuchObjectException;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* This class obtains stub that communicates with the remote object.
*/
public class UnicastRemoteObject extends RemoteServer
{
private static final long serialVersionUID = 4974527148936298033L;
//The following serialized fields are from Java API Documentation "Serialized form"
private int port = 0;
private RMIClientSocketFactory csf = null;
private RMIServerSocketFactory ssf = null;
/**
* Use SVUID for interoperability.
*/
private static final long serialVersionUID = 4974527148936298033L;
protected UnicastRemoteObject() throws RemoteException {
//The following serialized fields are from Java API Documentation
// "Serialized form"
/**
* The port, on that the created remote object becomes available,
* zero meaning the anonymous port.
*/
private int port;
/**
* The client socket factory for producing client sockets, used by this
* object.
*/
private RMIClientSocketFactory csf;
/**
* The server socket factory for producing server sockets, used by this
* object.
*/
private RMIServerSocketFactory ssf;
/**
* Create and export new remote object without specifying the port value.
*
* @throws RemoteException if the attempt to export the object failed.
*/
protected UnicastRemoteObject()
throws RemoteException
{
this(0);
}
}
/**
* Create and export the new remote object, making it available at the
* given port, local host.
*
* @param port the port, on that the object should become available.
* Zero means anonymous port.
*
* @throws RemoteException if the attempt to export the object failed.
*/
protected UnicastRemoteObject(int port)
throws RemoteException
{
this(port, RMISocketFactory.getSocketFactory(),
RMISocketFactory.getSocketFactory());
}
protected UnicastRemoteObject(int port) throws RemoteException {
this(port, RMISocketFactory.getSocketFactory(), RMISocketFactory.getSocketFactory());
}
/**
* Create and export the new remote object, making it available at the
* given port, using sockets, produced by the specified factories.
*
* @param port the port, on that the object should become available.
* Zero means anonymous port.
*
* @param clientSocketFactory the client socket factory
* @param serverSocketFactory the server socket factory
*
* @throws RemoteException if the attempt to export the object failed.
*/
protected UnicastRemoteObject(int port,
RMIClientSocketFactory clientSocketFactory,
RMIServerSocketFactory serverSocketFactory)
throws RemoteException
{
this.port = port;
//Is RMIXXXSocketFactory serializable
//this.csf = csf;
//this.ssf = ssf;
this.ref = new UnicastServerRef(new ObjID(), port, serverSocketFactory);
exportObject(this, port);
}
protected UnicastRemoteObject(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws RemoteException {
this.port = port;
//Is RMIXXXSocketFactory serializable
//this.csf = csf;
//this.ssf = ssf;
this.ref = new UnicastServerRef(new ObjID(), port, ssf);
exportObject(this);
}
protected UnicastRemoteObject(RemoteRef ref)
throws RemoteException
{
super((UnicastServerRef) ref);
exportObject(this, 0);
}
protected UnicastRemoteObject(RemoteRef ref) throws RemoteException {
super((UnicastServerRef)ref);
exportObject(this);
}
public Object clone() throws CloneNotSupportedException {
public Object clone()
throws CloneNotSupportedException
{
throw new Error("Not implemented");
}
}
/**
* Export object, making it available for the remote calls at the
* anonymous port.
*
* This method returns the instance of the abstract class, not an interface.
* Hence it will not work with the proxy stubs that are supported since
* jdk 1.5 (such stubs cannot be derived from the RemoteStub). Only use
* this method if you are sure that the stub class will be accessible.
*
* @param obj the object being exported.
*
* @return the remote object stub
*
* @throws RemoteException if the attempt to export the object failed.
*/
public static RemoteStub exportObject(Remote obj)
throws RemoteException
{
return (RemoteStub) exportObject(obj, 0);
}
public static RemoteStub exportObject(Remote obj) throws RemoteException {
UnicastServerRef sref = (UnicastServerRef)((RemoteObject)obj).getRef();
return (sref.exportObject(obj));
}
public static Remote exportObject(Remote obj, int port) throws RemoteException
/**
* Export object, making it available for the remote calls at the
* specified port.
*
* Since jdk 1.5 this method does not longer require the stub class to be
* present. If such class is not found, the stub is replaced by the
* dynamically constructed proxy class. No attempt to find and load the stubs
* is made if the system property java.rmi.server.ignoreStubClasses
* is set to true (set to reduce the starting time if the stubs are
* surely not present and exclusively 1.2 RMI is used).
*
* @param obj the object being exported.
* @param port the remote object port
*
* @return the remote object stub
*
* @throws RemoteException if the attempt to export the object failed.
*/
public static Remote exportObject(Remote obj, int port)
throws RemoteException
{
return exportObject(obj, port, null);
}
static Remote exportObject(Remote obj, int port, RMIServerSocketFactory ssf)
throws RemoteException
/**
* Create and export the new remote object, making it available at the
* given port, using sockets, produced by the specified factories.
*
* Since jdk 1.5 this method does not longer require the stub class to be
* present. If such class is not found, the stub is replaced by the
* dynamically constructed proxy class. No attempt to find and load the stubs
* is made if the system property java.rmi.server.ignoreStubClasses
* is set to true (set to reduce the starting time if the stubs are
* surely not present and exclusively 1.2 RMI is used).
*
* @param port the port, on that the object should become available.
* Zero means anonymous port.
*
* @param serverSocketFactory the server socket factory
*/
static Remote exportObject(Remote obj, int port,
RMIServerSocketFactory serverSocketFactory)
throws RemoteException
{
UnicastServerRef sref = null;
if (obj instanceof RemoteObject)
sref = (UnicastServerRef)((RemoteObject)obj).getRef ();
if(sref == null)
{
sref = new UnicastServerRef(new ObjID (), port, ssf);
}
Remote stub = sref.exportObject (obj);
sref = (UnicastServerRef) ((RemoteObject) obj).getRef();
if (sref == null)
sref = new UnicastServerRef(new ObjID(), port, serverSocketFactory);
Remote stub = sref.exportObject(obj);
addStub(obj, stub);
return stub;
}
@ -106,8 +221,9 @@ public static RemoteStub exportObject(Remote obj) throws RemoteException {
/**
* FIXME
*/
public static Remote exportObject(Remote obj, int port, RMIClientSocketFactory csf,
RMIServerSocketFactory ssf)
public static Remote exportObject(Remote obj, int port,
RMIClientSocketFactory csf,
RMIServerSocketFactory ssf)
throws RemoteException
{
return (exportObject(obj, port, ssf));
@ -118,14 +234,15 @@ public static RemoteStub exportObject(Remote obj) throws RemoteException {
{
if (obj instanceof RemoteObject)
{
deleteStub(obj);
UnicastServerRef sref = (UnicastServerRef)((RemoteObject)obj).getRef();
return sref.unexportObject(obj, force);
deleteStub(obj);
UnicastServerRef sref =
(UnicastServerRef) ((RemoteObject) obj).getRef();
return sref.unexportObject(obj, force);
}
else
{
//FIX ME
;
// FIXME
;
}
return true;
}