src/share/classes/com/sun/jndi/cosnaming/CNCtx.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 28,38 ****
import javax.naming.*;
import javax.naming.spi.NamingManager;
import javax.naming.spi.ResolveResult;
import java.util.Hashtable;
- import java.util.Vector;
import java.net.MalformedURLException;
import java.net.URL;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
--- 28,37 ----
*** 61,71 ****
ORB _orb; // used by ExceptionMapper and RMI/IIOP factory
public NamingContext _nc; // public for accessing underlying NamingContext
private NameComponent[] _name = null;
! Hashtable _env; // used by ExceptionMapper
static final CNNameParser parser = new CNNameParser();
private static final String FED_PROP = "com.sun.jndi.cosnaming.federation";
boolean federation = false;
--- 60,70 ----
ORB _orb; // used by ExceptionMapper and RMI/IIOP factory
public NamingContext _nc; // public for accessing underlying NamingContext
private NameComponent[] _name = null;
! Hashtable<String, java.lang.Object> _env; // used by ExceptionMapper
static final CNNameParser parser = new CNNameParser();
private static final String FED_PROP = "com.sun.jndi.cosnaming.federation";
boolean federation = false;
*** 80,111 ****
* The ORB can be passed in via the java.naming.corba.orb property
* or be created using properties in the environment properties.
* @param env Environment properties for initializing name service.
* @exception NamingException Cannot initialize ORB or naming context.
*/
! CNCtx(Hashtable env) throws NamingException {
if (env != null) {
! env = (Hashtable) env.clone();
}
! _env = env;
federation = "true".equals(env != null ? env.get(FED_PROP) : null);
initOrbAndRootContext(env);
}
private CNCtx() {
}
/**
* This method is used by the iiop and iiopname URL Context factories.
*/
! public static ResolveResult createUsingURL(String url, Hashtable env)
throws NamingException {
CNCtx ctx = new CNCtx();
if (env != null) {
! env = (Hashtable) env.clone();
}
! ctx._env = env;
String rest = ctx.initUsingUrl(
env != null ?
(org.omg.CORBA.ORB) env.get("java.naming.corba.orb")
: null,
url, env);
--- 79,112 ----
* The ORB can be passed in via the java.naming.corba.orb property
* or be created using properties in the environment properties.
* @param env Environment properties for initializing name service.
* @exception NamingException Cannot initialize ORB or naming context.
*/
! @SuppressWarnings("unchecked")
! CNCtx(Hashtable<?,?> env) throws NamingException {
if (env != null) {
! env = (Hashtable<?,?>)env.clone();
}
! _env = (Hashtable<String, java.lang.Object>)env;
federation = "true".equals(env != null ? env.get(FED_PROP) : null);
initOrbAndRootContext(env);
}
private CNCtx() {
}
/**
* This method is used by the iiop and iiopname URL Context factories.
*/
! @SuppressWarnings("unchecked")
! public static ResolveResult createUsingURL(String url, Hashtable<?,?> env)
throws NamingException {
CNCtx ctx = new CNCtx();
if (env != null) {
! env = (Hashtable<?,?>) env.clone();
}
! ctx._env = (Hashtable<String, java.lang.Object>)env;
String rest = ctx.initUsingUrl(
env != null ?
(org.omg.CORBA.ORB) env.get("java.naming.corba.orb")
: null,
url, env);
*** 126,137 ****
* orb object
* @param nctx The COS NamingContext object associated with this context
* @param name The name of this context relative to the root
*/
! CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx, Hashtable env,
! NameComponent[]name)
throws NamingException {
if (orb == null || nctx == null)
throw new ConfigurationException(
"Must supply ORB or NamingContext");
_orb = orb;
--- 127,138 ----
* orb object
* @param nctx The COS NamingContext object associated with this context
* @param name The name of this context relative to the root
*/
! CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx,
! Hashtable<String, java.lang.Object> env, NameComponent[]name)
throws NamingException {
if (orb == null || nctx == null)
throw new ConfigurationException(
"Must supply ORB or NamingContext");
_orb = orb;
*** 205,215 ****
*
* @param env Environment The possibly null environment.
* @exception NamingException When an error occurs while initializing the
* ORB or the naming context.
*/
! private void initOrbAndRootContext(Hashtable env) throws NamingException {
org.omg.CORBA.ORB inOrb = null;
String ncIor = null;
if (env != null) {
inOrb = (org.omg.CORBA.ORB) env.get("java.naming.corba.orb");
--- 206,216 ----
*
* @param env Environment The possibly null environment.
* @exception NamingException When an error occurs while initializing the
* ORB or the naming context.
*/
! private void initOrbAndRootContext(Hashtable<?,?> env) throws NamingException {
org.omg.CORBA.ORB inOrb = null;
String ncIor = null;
if (env != null) {
inOrb = (org.omg.CORBA.ORB) env.get("java.naming.corba.orb");
*** 238,248 ****
// in the PROVIDER_URL
String insName = initUsingUrl(inOrb, provUrl, env);
// If name supplied in URL, resolve it to a NamingContext
if (insName.length() > 0) {
! _name = parser.nameToCosName(parser.parse(insName));
try {
org.omg.CORBA.Object obj = _nc.resolve(_name);
_nc = NamingContextHelper.narrow(obj);
if (_nc == null) {
throw new ConfigurationException(insName +
--- 239,249 ----
// in the PROVIDER_URL
String insName = initUsingUrl(inOrb, provUrl, env);
// If name supplied in URL, resolve it to a NamingContext
if (insName.length() > 0) {
! _name = CNNameParser.nameToCosName(parser.parse(insName));
try {
org.omg.CORBA.Object obj = _nc.resolve(_name);
_nc = NamingContextHelper.narrow(obj);
if (_nc == null) {
throw new ConfigurationException(insName +
*** 269,279 ****
setOrbAndRootContext(inOrb, (String)null);
}
}
! private String initUsingUrl(ORB orb, String url, Hashtable env)
throws NamingException {
if (url.startsWith("iiop://") || url.startsWith("iiopname://")) {
return initUsingIiopUrl(orb, url, env);
} else {
return initUsingCorbanameUrl(orb, url, env);
--- 270,280 ----
setOrbAndRootContext(inOrb, (String)null);
}
}
! private String initUsingUrl(ORB orb, String url, Hashtable<?,?> env)
throws NamingException {
if (url.startsWith("iiop://") || url.startsWith("iiopname://")) {
return initUsingIiopUrl(orb, url, env);
} else {
return initUsingCorbanameUrl(orb, url, env);
*** 281,301 ****
}
/**
* Handles "iiop" and "iiopname" URLs (INS 98-10-11)
*/
! private String initUsingIiopUrl(ORB defOrb, String url, Hashtable env)
throws NamingException {
try {
IiopUrl parsedUrl = new IiopUrl(url);
- Vector addrs = parsedUrl.getAddresses();
- IiopUrl.Address addr;
NamingException savedException = null;
! for (int i = 0; i < addrs.size(); i++) {
! addr = (IiopUrl.Address)addrs.elementAt(i);
try {
if (defOrb != null) {
try {
String tmpUrl = "corbaloc:iiop:" + addr.host
--- 282,299 ----
}
/**
* Handles "iiop" and "iiopname" URLs (INS 98-10-11)
*/
! private String initUsingIiopUrl(ORB defOrb, String url, Hashtable<?,?> env)
throws NamingException {
try {
IiopUrl parsedUrl = new IiopUrl(url);
NamingException savedException = null;
! for (IiopUrl.Address addr : parsedUrl.getAddresses()) {
try {
if (defOrb != null) {
try {
String tmpUrl = "corbaloc:iiop:" + addr.host
*** 339,349 ****
}
/**
* Initializes using "corbaname" URL (INS 99-12-03)
*/
! private String initUsingCorbanameUrl(ORB orb, String url, Hashtable env)
throws NamingException {
try {
CorbanameUrl parsedUrl = new CorbanameUrl(url);
String corbaloc = parsedUrl.getLocation();
--- 337,347 ----
}
/**
* Initializes using "corbaname" URL (INS 99-12-03)
*/
! private String initUsingCorbanameUrl(ORB orb, String url, Hashtable<?,?> env)
throws NamingException {
try {
CorbanameUrl parsedUrl = new CorbanameUrl(url);
String corbaloc = parsedUrl.getLocation();
*** 729,739 ****
} catch (NotFound e) {
// If leaf is the one missing, return success
// as per JNDI spec
if (leafNotFound(e, path[path.length-1])) {
! ; // do nothing
} else {
throw ExceptionMapper.mapException(e, this, path);
}
} catch (Exception e) {
throw ExceptionMapper.mapException(e, this, path);
--- 727,737 ----
} catch (NotFound e) {
// If leaf is the one missing, return success
// as per JNDI spec
if (leafNotFound(e, path[path.length-1])) {
! // do nothing
} else {
throw ExceptionMapper.mapException(e, this, path);
}
} catch (Exception e) {
throw ExceptionMapper.mapException(e, this, path);
*** 827,860 ****
* @param name string
* @exception NamingException All exceptions thrown by lookup
* with a non-null argument
* @return a list of name-class objects as a NameClassEnumeration.
*/
! public NamingEnumeration list(String name) throws NamingException {
return list(new CompositeName(name));
}
/**
* Returns a NameClassEnumeration object which has a list of name
* class pairs. Lists the current context if the name is empty.
* @param name JNDI Name
* @exception NamingException All exceptions thrown by lookup
* @return a list of name-class objects as a NameClassEnumeration.
*/
! public NamingEnumeration list(Name name)
throws NamingException {
! return listBindings(name);
}
/**
* Returns a BindingEnumeration object which has a list of name
* object pairs. Lists the current context if the name is empty.
* @param name string
* @exception NamingException all exceptions returned by lookup
* @return a list of bindings as a BindingEnumeration.
*/
! public NamingEnumeration listBindings(String name)
throws NamingException {
return listBindings(new CompositeName(name));
}
/**
--- 825,859 ----
* @param name string
* @exception NamingException All exceptions thrown by lookup
* with a non-null argument
* @return a list of name-class objects as a NameClassEnumeration.
*/
! public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
return list(new CompositeName(name));
}
/**
* Returns a NameClassEnumeration object which has a list of name
* class pairs. Lists the current context if the name is empty.
* @param name JNDI Name
* @exception NamingException All exceptions thrown by lookup
* @return a list of name-class objects as a NameClassEnumeration.
*/
! @SuppressWarnings("unchecked")
! public NamingEnumeration<NameClassPair> list(Name name)
throws NamingException {
! return (NamingEnumeration)listBindings(name);
}
/**
* Returns a BindingEnumeration object which has a list of name
* object pairs. Lists the current context if the name is empty.
* @param name string
* @exception NamingException all exceptions returned by lookup
* @return a list of bindings as a BindingEnumeration.
*/
! public NamingEnumeration<javax.naming.Binding> listBindings(String name)
throws NamingException {
return listBindings(new CompositeName(name));
}
/**
*** 862,872 ****
* class pairs. Lists the current context if the name is empty.
* @param name JNDI Name
* @exception NamingException all exceptions returned by lookup.
* @return a list of bindings as a BindingEnumeration.
*/
! public NamingEnumeration listBindings(Name name)
throws NamingException {
if (_nc == null)
throw new ConfigurationException(
"Context does not have a corresponding NamingContext");
if (name.size() > 0) {
--- 861,871 ----
* class pairs. Lists the current context if the name is empty.
* @param name JNDI Name
* @exception NamingException all exceptions returned by lookup.
* @return a list of bindings as a BindingEnumeration.
*/
! public NamingEnumeration<javax.naming.Binding> listBindings(Name name)
throws NamingException {
if (_nc == null)
throw new ConfigurationException(
"Context does not have a corresponding NamingContext");
if (name.size() > 0) {
*** 1062,1076 ****
/**
* Returns the current environment.
* @return Environment.
*/
! public Hashtable getEnvironment() throws NamingException {
if (_env == null) {
! return new Hashtable(5, 0.75f);
} else {
! return (Hashtable)_env.clone();
}
}
public String composeName(String name, String prefix) throws NamingException {
return composeName(new CompositeName(name),
--- 1061,1076 ----
/**
* Returns the current environment.
* @return Environment.
*/
! @SuppressWarnings("unchecked")
! public Hashtable<String, java.lang.Object> getEnvironment() throws NamingException {
if (_env == null) {
! return new Hashtable<>(5, 0.75f);
} else {
! return (Hashtable<String, java.lang.Object>)_env.clone();
}
}
public String composeName(String name, String prefix) throws NamingException {
return composeName(new CompositeName(name),
*** 1088,1116 ****
*
* @param propName The property name.
* @param propVal The ORB.
* @return the previous value of this property if any.
*/
public java.lang.Object addToEnvironment(String propName,
java.lang.Object propValue)
throws NamingException {
if (_env == null) {
! _env = new Hashtable(7, 0.75f);
} else {
// copy-on-write
! _env = (Hashtable)_env.clone();
}
return _env.put(propName, propValue);
}
// Record change but do not reinitialize ORB
public java.lang.Object removeFromEnvironment(String propName)
throws NamingException {
if (_env != null && _env.get(propName) != null) {
// copy-on-write
! _env = (Hashtable)_env.clone();
return _env.remove(propName);
}
return null;
}
--- 1088,1118 ----
*
* @param propName The property name.
* @param propVal The ORB.
* @return the previous value of this property if any.
*/
+ @SuppressWarnings("unchecked")
public java.lang.Object addToEnvironment(String propName,
java.lang.Object propValue)
throws NamingException {
if (_env == null) {
! _env = new Hashtable<>(7, 0.75f);
} else {
// copy-on-write
! _env = (Hashtable<String, java.lang.Object>)_env.clone();
}
return _env.put(propName, propValue);
}
// Record change but do not reinitialize ORB
+ @SuppressWarnings("unchecked")
public java.lang.Object removeFromEnvironment(String propName)
throws NamingException {
if (_env != null && _env.get(propName) != null) {
// copy-on-write
! _env = (Hashtable<String, java.lang.Object>)_env.clone();
return _env.remove(propName);
}
return null;
}