J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * @author Sun Microsystems, Inc. |
| 28 | * @build @BUILD_TAG_PLACEHOLDER@ |
| 29 | * |
| 30 | * @COPYRIGHT_MINI_LEGAL_NOTICE_PLACEHOLDER@ |
| 31 | */ |
| 32 | |
| 33 | package sun.management.jmxremote; |
| 34 | |
| 35 | import java.rmi.AccessException; |
| 36 | import java.rmi.NotBoundException; |
| 37 | import java.rmi.Remote; |
| 38 | import java.rmi.RemoteException; |
| 39 | import java.rmi.server.RMIClientSocketFactory; |
| 40 | import java.rmi.server.RMIServerSocketFactory; |
| 41 | |
| 42 | import sun.rmi.registry.RegistryImpl; |
| 43 | |
| 44 | /** A Registry that consists of a single entry that never changes. */ |
| 45 | public class SingleEntryRegistry extends RegistryImpl { |
| 46 | SingleEntryRegistry(int port, String name, Remote object) |
| 47 | throws RemoteException { |
| 48 | super(port); |
| 49 | this.name = name; |
| 50 | this.object = object; |
| 51 | } |
| 52 | |
| 53 | SingleEntryRegistry(int port, |
| 54 | RMIClientSocketFactory csf, |
| 55 | RMIServerSocketFactory ssf, |
| 56 | String name, |
| 57 | Remote object) |
| 58 | throws RemoteException { |
| 59 | super(port, csf, ssf); |
| 60 | this.name = name; |
| 61 | this.object = object; |
| 62 | } |
| 63 | |
| 64 | public String[] list() { |
| 65 | return new String[] {name}; |
| 66 | } |
| 67 | |
| 68 | public Remote lookup(String name) throws NotBoundException { |
| 69 | if (name.equals(this.name)) |
| 70 | return object; |
| 71 | throw new NotBoundException("Not bound: \"" + name + "\" (only " + |
| 72 | "bound name is \"" + this.name + "\")"); |
| 73 | } |
| 74 | |
| 75 | public void bind(String name, Remote obj) throws AccessException { |
| 76 | throw new AccessException("Cannot modify this registry"); |
| 77 | } |
| 78 | |
| 79 | public void rebind(String name, Remote obj) throws AccessException { |
| 80 | throw new AccessException("Cannot modify this registry"); |
| 81 | } |
| 82 | |
| 83 | public void unbind(String name) throws AccessException { |
| 84 | throw new AccessException("Cannot modify this registry"); |
| 85 | } |
| 86 | |
| 87 | private final String name; |
| 88 | private final Remote object; |
| 89 | } |