summaryrefslogtreecommitdiff
path: root/java/rmi
diff options
context:
space:
mode:
authorWolfgang Baer <WBaer@gmx.de>2006-02-12 11:36:48 +0000
committerWolfgang Baer <WBaer@gmx.de>2006-02-12 11:36:48 +0000
commitc0f1ec0cffa290fc1d02f844782722a11bd638e2 (patch)
treec0daa59838e7402bf20338af64d184b166b74b66 /java/rmi
parenta2f209946634a3e2a4646b4579fed7fd326c0995 (diff)
downloadclasspath-c0f1ec0cffa290fc1d02f844782722a11bd638e2.tar.gz
2006-02-12 Wolfgang Baer <WBaer@gmx.de>
* java/rmi/MarshalledObject.java: Reformatted. * java/rmi/Naming.java: Likewise.
Diffstat (limited to 'java/rmi')
-rw-r--r--java/rmi/MarshalledObject.java65
-rw-r--r--java/rmi/Naming.java226
2 files changed, 156 insertions, 135 deletions
diff --git a/java/rmi/MarshalledObject.java b/java/rmi/MarshalledObject.java
index 9ec0ace0e..e07123804 100644
--- a/java/rmi/MarshalledObject.java
+++ b/java/rmi/MarshalledObject.java
@@ -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,43 @@ 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
*/
-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
{
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)
+
+ public boolean equals(Object obj)
{
if (! (obj instanceof MarshalledObject))
return false;
@@ -81,33 +87,34 @@ 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() {
+
+ 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;
}
-
+
}
diff --git a/java/rmi/Naming.java b/java/rmi/Naming.java
index d48df069d..b605da70d 100644
--- a/java/rmi/Naming.java
+++ b/java/rmi/Naming.java
@@ -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() {}
+ 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));
-}
+ /**
+ * 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);
-}
+ /**
+ * 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);
-}
+ /**
+ * 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);
-}
+ /**
+ * 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());
-}
+ /**
+ * 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 static Registry getRegistry(URL u) throws RemoteException
+ {
+ if (u.getPort() == - 1)
+ {
+ return (LocateRegistry.getRegistry(u.getHost()));
+ }
+ else
+ {
+ return (LocateRegistry.getRegistry(u.getHost(), u.getPort()));
+ }
+ }
/**
- * 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.
- *
+ * 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
+ 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));
+ 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());
+ throw new MalformedURLException("The URL syntax was invalid: "
+ + e.getMessage());
}
}
/**
- * Checks that the URL contains a name, and removes any leading
- * slashes.
- *
+ * 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;
}
-
}