src/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java
Print this page
*** 44,54 ****
*/
public class RegistryContext implements Context, Referenceable {
! private Hashtable environment;
private Registry registry;
private String host;
private int port;
private static final NameParser nameParser = new AtomicNameParser();
private static final String SOCKET_FACTORY = "com.sun.jndi.rmi.factory.socket";
--- 44,54 ----
*/
public class RegistryContext implements Context, Referenceable {
! private Hashtable<String, Object> environment;
private Registry registry;
private String host;
private int port;
private static final NameParser nameParser = new AtomicNameParser();
private static final String SOCKET_FACTORY = "com.sun.jndi.rmi.factory.socket";
*** 65,78 ****
* If "host" is null, uses default host.
* If "port" is non-positive, uses default port.
* Cloning of "env" is handled by caller; see comments within
* RegistryContextFactory.getObjectInstance(), for example.
*/
! public RegistryContext(String host, int port, Hashtable env)
throws NamingException
{
! environment = ((env == null) ? new Hashtable(5) : env);
if (environment.get(SECURITY_MGR) != null) {
installSecurityMgr();
}
// chop off '[' and ']' in an IPv6 literal address
--- 65,81 ----
* If "host" is null, uses default host.
* If "port" is non-positive, uses default port.
* Cloning of "env" is handled by caller; see comments within
* RegistryContextFactory.getObjectInstance(), for example.
*/
! @SuppressWarnings("unchecked")
! public RegistryContext(String host, int port, Hashtable<?, ?> env)
throws NamingException
{
! environment = (env == null)
! ? new Hashtable<String, Object>(5)
! : (Hashtable<String, Object>) env;
if (environment.get(SECURITY_MGR) != null) {
installSecurityMgr();
}
// chop off '[' and ']' in an IPv6 literal address
*** 91,102 ****
* Returns a clone of a registry context. The context's private state
* is independent of the original's (so closing one context, for example,
* won't close the other).
*/
// %%% Alternatively, this could be done with a clone() method.
RegistryContext(RegistryContext ctx) {
! environment = (Hashtable)ctx.environment.clone();
registry = ctx.registry;
host = ctx.host;
port = ctx.port;
reference = ctx.reference;
}
--- 94,106 ----
* Returns a clone of a registry context. The context's private state
* is independent of the original's (so closing one context, for example,
* won't close the other).
*/
// %%% Alternatively, this could be done with a clone() method.
+ @SuppressWarnings("unchecked") // clone()
RegistryContext(RegistryContext ctx) {
! environment = (Hashtable<String, Object>)ctx.environment.clone();
registry = ctx.registry;
host = ctx.host;
port = ctx.port;
reference = ctx.reference;
}
*** 193,203 ****
public void rename(String name, String newName) throws NamingException {
rename(new CompositeName(name), new CompositeName(newName));
}
! public NamingEnumeration list(Name name) throws NamingException {
if (!name.isEmpty()) {
throw (new InvalidNameException(
"RegistryContext: can only list \"\""));
}
try {
--- 197,208 ----
public void rename(String name, String newName) throws NamingException {
rename(new CompositeName(name), new CompositeName(newName));
}
! public NamingEnumeration<NameClassPair> list(Name name) throws
! NamingException {
if (!name.isEmpty()) {
throw (new InvalidNameException(
"RegistryContext: can only list \"\""));
}
try {
*** 206,220 ****
} catch (RemoteException e) {
throw (NamingException)wrapRemoteException(e).fillInStackTrace();
}
}
! public NamingEnumeration list(String name) throws NamingException {
return list(new CompositeName(name));
}
! public NamingEnumeration listBindings(Name name)
throws NamingException
{
if (!name.isEmpty()) {
throw (new InvalidNameException(
"RegistryContext: can only list \"\""));
--- 211,226 ----
} catch (RemoteException e) {
throw (NamingException)wrapRemoteException(e).fillInStackTrace();
}
}
! public NamingEnumeration<NameClassPair> list(String name) throws
! NamingException {
return list(new CompositeName(name));
}
! public NamingEnumeration<Binding> listBindings(Name name)
throws NamingException
{
if (!name.isEmpty()) {
throw (new InvalidNameException(
"RegistryContext: can only list \"\""));
*** 225,235 ****
} catch (RemoteException e) {
throw (NamingException)wrapRemoteException(e).fillInStackTrace();
}
}
! public NamingEnumeration listBindings(String name) throws NamingException {
return listBindings(new CompositeName(name));
}
public void destroySubcontext(Name name) throws NamingException {
throw (new OperationNotSupportedException());
--- 231,242 ----
} catch (RemoteException e) {
throw (NamingException)wrapRemoteException(e).fillInStackTrace();
}
}
! public NamingEnumeration<Binding> listBindings(String name) throws
! NamingException {
return listBindings(new CompositeName(name));
}
public void destroySubcontext(Name name) throws NamingException {
throw (new OperationNotSupportedException());
*** 288,299 ****
installSecurityMgr();
}
return environment.put(propName, propVal);
}
! public Hashtable getEnvironment() throws NamingException {
! return (Hashtable)environment.clone();
}
public void close() {
environment = null;
registry = null;
--- 295,307 ----
installSecurityMgr();
}
return environment.put(propName, propVal);
}
! @SuppressWarnings("unchecked") // clone()
! public Hashtable<String, Object> getEnvironment() throws NamingException {
! return (Hashtable<String, Object>)environment.clone();
}
public void close() {
environment = null;
registry = null;
*** 481,495 ****
}
}
/**
! * An enumeration of name / class-name pairs. Since we don't know anything
! * about the classes, each class name is returned as the generic
! * "java.lang.Object".
*/
! class NameClassPairEnumeration implements NamingEnumeration {
private final String[] names;
private int nextName; // index into "names"
NameClassPairEnumeration(String[] names) {
this.names = names;
--- 489,501 ----
}
}
/**
! * An enumeration of name / class-name pairs.
*/
! class NameClassPairEnumeration implements NamingEnumeration<NameClassPair> {
private final String[] names;
private int nextName; // index into "names"
NameClassPairEnumeration(String[] names) {
this.names = names;
*** 498,508 ****
public boolean hasMore() {
return (nextName < names.length);
}
! public Object next() throws NamingException {
if (!hasMore()) {
throw (new java.util.NoSuchElementException());
}
// Convert name to a one-element composite name, so embedded
// meta-characters are properly escaped.
--- 504,514 ----
public boolean hasMore() {
return (nextName < names.length);
}
! public NameClassPair next() throws NamingException {
if (!hasMore()) {
throw (new java.util.NoSuchElementException());
}
// Convert name to a one-element composite name, so embedded
// meta-characters are properly escaped.
*** 516,526 ****
public boolean hasMoreElements() {
return hasMore();
}
! public Object nextElement() {
try {
return next();
} catch (NamingException e) { // should never happen
throw (new java.util.NoSuchElementException(
"javax.naming.NamingException was thrown"));
--- 522,532 ----
public boolean hasMoreElements() {
return hasMore();
}
! public NameClassPair nextElement() {
try {
return next();
} catch (NamingException e) { // should never happen
throw (new java.util.NoSuchElementException(
"javax.naming.NamingException was thrown"));
*** 539,549 ****
* The actual registry lookups are performed when next() is called. It would
* be nicer to defer this until the object (or its class name) is actually
* requested. The problem with that approach is that Binding.getObject()
* cannot throw NamingException.
*/
! class BindingEnumeration implements NamingEnumeration {
private RegistryContext ctx;
private final String[] names;
private int nextName; // index into "names"
BindingEnumeration(RegistryContext ctx, String[] names) {
--- 545,555 ----
* The actual registry lookups are performed when next() is called. It would
* be nicer to defer this until the object (or its class name) is actually
* requested. The problem with that approach is that Binding.getObject()
* cannot throw NamingException.
*/
! class BindingEnumeration implements NamingEnumeration<Binding> {
private RegistryContext ctx;
private final String[] names;
private int nextName; // index into "names"
BindingEnumeration(RegistryContext ctx, String[] names) {
*** 562,572 ****
ctx.close();
}
return (nextName < names.length);
}
! public Object next() throws NamingException {
if (!hasMore()) {
throw (new java.util.NoSuchElementException());
}
// Convert name to a one-element composite name, so embedded
// meta-characters are properly escaped.
--- 568,578 ----
ctx.close();
}
return (nextName < names.length);
}
! public Binding next() throws NamingException {
if (!hasMore()) {
throw (new java.util.NoSuchElementException());
}
// Convert name to a one-element composite name, so embedded
// meta-characters are properly escaped.
*** 582,592 ****
public boolean hasMoreElements() {
return hasMore();
}
! public Object nextElement() {
try {
return next();
} catch (NamingException e) {
throw (new java.util.NoSuchElementException(
"javax.naming.NamingException was thrown"));
--- 588,598 ----
public boolean hasMoreElements() {
return hasMore();
}
! public Binding nextElement() {
try {
return next();
} catch (NamingException e) {
throw (new java.util.NoSuchElementException(
"javax.naming.NamingException was thrown"));