Hi, i reformatted two rmi classes to be able to add javadocs.
2006-02-12 Wolfgang Baer <[EMAIL PROTECTED]> * java/rmi/MarshalledObject.java: Reformatted. * java/rmi/Naming.java: Likewise. Wolfgang
Index: java/rmi/Naming.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/rmi/Naming.java,v retrieving revision 1.10 diff -u -r1.10 Naming.java --- java/rmi/Naming.java 2 Jul 2005 20:32:40 -0000 1.10 +++ java/rmi/Naming.java 12 Feb 2006 11:35:19 -0000 @@ -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 @@ * @author Andrew John Hughes ([EMAIL PROTECTED]) * @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 @@ return filename.substring(1); return filename; } - } Index: java/rmi/MarshalledObject.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/rmi/MarshalledObject.java,v retrieving revision 1.9 diff -u -r1.9 MarshalledObject.java --- java/rmi/MarshalledObject.java 2 Jul 2005 20:32:40 -0000 1.9 +++ java/rmi/MarshalledObject.java 12 Feb 2006 11:35:19 -0000 @@ -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.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 @@ // 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; } - + }