diff options
author | Wolfgang Baer <WBaer@gmx.de> | 2006-02-12 11:36:48 +0000 |
---|---|---|
committer | Wolfgang Baer <WBaer@gmx.de> | 2006-02-12 11:36:48 +0000 |
commit | c0f1ec0cffa290fc1d02f844782722a11bd638e2 (patch) | |
tree | c0daa59838e7402bf20338af64d184b166b74b66 /java/rmi/Naming.java | |
parent | a2f209946634a3e2a4646b4579fed7fd326c0995 (diff) | |
download | classpath-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/Naming.java')
-rw-r--r-- | java/rmi/Naming.java | 226 |
1 files changed, 120 insertions, 106 deletions
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; } - } |