/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// Needed for creating default ORB
/**
* Provides a bridge to the CosNaming server provided by
* JavaIDL. This class provides the InitialContext from CosNaming.
*
* @author Raj Krishnamurthy
* @author Rosanna Lee
*/
private final static boolean debug = false;
/*
* Implement one shared ORB among all CNCtx. However, there is a public constructor
* accepting an ORB, so we need the option of using a given ORB.
*/
if (_defaultOrb == null) {
}
return _defaultOrb;
}
boolean federation = false;
// Reference counter for tracking _orb references
int enumCount;
boolean isCloseCalled = false;
/**
* Create a CNCtx object. Gets the initial naming
* reference for the COS Naming Service from the ORB.
* 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.
*/
}
}
private CNCtx() {
}
/**
* This method is used by the iiop and iiopname URL Context factories.
*/
throws NamingException {
}
: null,
// rest is the INS name
// Return the parsed form to prevent subsequent lookup
// from parsing the string as a composite name
// The caller should be aware that a toString() of the name,
// which came from the environment will yield its INS syntax,
// rather than a composite syntax
}
/**
* Creates a CNCtx object which supports the javax.naming
* apis given a COS Naming Context object.
* @param orb The ORB used by this context
* @param tracker The ORB reuse tracker for tracking references to the
* orb object
* @param nctx The COS NamingContext object associated with this context
* @param name The name of this context relative to the root
*/
throws NamingException {
throw new ConfigurationException(
"Must supply ORB or NamingContext");
} else {
_orb = getDefaultOrb();
}
}
return child;
}
// parent
// child
return answer;
}
return "";
}
}
/**
* These are the URL schemes that need to be processed.
* IOR and corbaloc URLs can be passed directly to ORB.string_to_object()
*/
;
}
/**
* Initializes the COS Naming Service.
* This method initializes the three instance fields:
* _nc : The root naming context.
* getting the naming context (_nc) if one was not specified
* explicitly via PROVIDER_URL.
* _name: The name of the root naming context.
*<p>
* _orb is obtained from java.naming.corba.orb if it has been set.
* (if it contains an "iiop" or "iiopname" URL), or from initialization
* properties specified in env.
*<p>
* _nc is obtained from the IOR stored in PROVIDER_URL if it has been
* set and does not contain an "iiop" or "iiopname" URL. It can be
* a stringified IOR, "corbaloc" URL, "corbaname" URL,
* containing a stringified IOR. If PROVIDER_URL has not been
* set in this way, it is obtained from the result of
* ORB.resolve_initial_reference("NameService");
*<p>
* _name is obtained from the "iiop", "iiopname", or "corbaname" URL.
* It is the empty name by default.
*
* @param env Environment The possibly null environment.
* @exception NamingException When an error occurs while initializing the
* ORB or the naming context.
*/
}
// Extract PROVIDER_URL from environment
}
// Initialize the root naming context by using the IOR supplied
// in the PROVIDER_URL
// Initialize the root naming context by using the URL supplied
// in the PROVIDER_URL
// If name supplied in URL, resolve it to a NamingContext
try {
throw new ConfigurationException(insName +
" does not name a NamingContext");
}
throw new ConfigurationException(insName +
" does not name a NamingContext");
} catch (Exception e) {
}
}
} else {
// No PROVIDER_URL supplied; initialize using defaults
if (debug) {
}
}
}
throws NamingException {
} else {
}
}
/**
* Handles "iiop" and "iiopname" URLs (INS 98-10-11)
*/
throws NamingException {
defOrb = getDefaultOrb();
try {
try {
try {
if (debug) {
}
return parsedUrl.getStringName();
} catch (Exception e) {} // keep going
// Get ORB
if (debug) {
}
// Assign to fields
return parsedUrl.getStringName();
} catch (NamingException ne) {
savedException = ne;
}
}
if (savedException != null) {
throw savedException;
} else {
}
} catch (MalformedURLException e) {
throw new ConfigurationException(e.getMessage());
}
}
/**
* Initializes using "corbaname" URL (INS 99-12-03)
*/
throws NamingException {
orb = getDefaultOrb();
try {
return parsedUrl.getStringName();
} catch (MalformedURLException e) {
throw new ConfigurationException(e.getMessage());
}
}
throws NamingException {
try {
if (debug) {
}
} else {
}
if (debug) {
}
throw new ConfigurationException(
"Cannot convert IOR to a NamingContext: " + ncIor);
} else {
throw new ConfigurationException(
"ORB.resolve_initial_references(\"NameService\") does not return a NamingContext");
}
}
"COS Name Service not registered with ORB under the name 'NameService'");
throw ne;
new CommunicationException("Cannot connect to ORB");
ne.setRootCause(e);
throw ne;
"Invalid URL or IOR: " + ncIor);
ne.setRootCause(e);
throw ne;
"Invalid object reference: " + ncIor);
ne.setRootCause(e);
throw ne;
}
}
throws NamingException {
try {
throw new ConfigurationException(
"Cannot convert object reference to NamingContext: " + ncRef);
}
new CommunicationException("Cannot connect to ORB");
ne.setRootCause(e);
throw ne;
}
}
return url;
} else {
try {
in = u.openStream();
return str;
}
}
}
} catch (IOException e) {
ne.setRootCause(e);
throw ne;
} finally {
try {
}
} catch (IOException e) {
ne.setRootCause(e);
throw ne;
}
}
}
}
/**
* Does the job of calling the COS Naming API,
* resolve, and performs the exception mapping. If the resolved
* object is a COS Naming Context (sub-context), then this function
* returns a new JNDI naming context object.
* @param path the NameComponent[] object.
* @exception NotFound No objects under the name.
* @exception CannotProceed Unable to obtain a continuation context
* @exception InvalidName Name not understood.
* @return Resolved object returned by the COS Name Server.
*/
throws NamingException {
try {
try {
makeFullName(path));
} else {
return obj;
}
return obj;
}
} catch (Exception e) {
}
}
/**
* Converts the "String" name into a CompositeName
* returns the object resolved by the COS Naming api,
* resolve. Returns the current context if the name is empty.
* Returns either an org.omg.CORBA.Object or javax.naming.Context object.
* @param name string used to resolve the object.
* @exception NamingException See callResolve.
* @return the resolved object
*/
if (debug) {
}
}
/**
* Converts the "Name" name into a NameComponent[] object and
* returns the object resolved by the COS Naming api,
* resolve. Returns the current context if the name is empty.
* Returns either an org.omg.CORBA.Object or javax.naming.Context object.
* @param name JNDI Name used to resolve the object.
* @exception NamingException See callResolve.
* @return the resolved object
*/
throws NamingException {
throw new ConfigurationException(
"Context does not have a corresponding NamingContext");
return this; // %%% should clone() so that env can be changed
try {
try {
} catch (NamingException e) {
throw e;
} catch (Exception e) {
"problem generating object using object factory");
ne.setRootCause(e);
throw ne;
}
} catch (CannotProceedException cpe) {
}
}
/**
* Performs bind or rebind in the context depending on whether the
* flag rebind is set. The only objects allowed to be bound are of
* types org.omg.CORBA.Object, org.omg.CosNaming.NamingContext.
* You can use a state factory to turn other objects (such as
* Remote) into these acceptable forms.
*
* @param pth NameComponent[] object
* @param obj Object to be bound.
* @param rebind perform rebind ? if true performs a rebind.
* @exception NotFound No objects under the name.
* @exception CannotProceed Unable to obtain a continuation context
* @exception AlreadyBound An object is already bound to this name.
*/
throw new ConfigurationException(
"Context does not have a corresponding NamingContext");
try {
// Call state factories to convert
// Use naming context object reference
}
if (rebind)
else
if (rebind)
else
}
else
throw new IllegalArgumentException(
"Only instances of org.omg.CORBA.Object can be bound");
} catch (BAD_PARAM e) {
// probably narrow() failed?
ne.setRootCause(e);
throw ne;
} catch (Exception e) {
}
}
/**
* Converts the "Name" name into a NameComponent[] object and
* performs the bind operation. Uses callBindOrRebind. Throws an
* invalid name exception if the name is empty. We need a name to
* bind the object even when we work within the current context.
* @param name JNDI Name object
* @param obj Object to be bound.
* @exception NamingException See callBindOrRebind
*/
throws NamingException {
throw new InvalidNameException("Name is empty");
}
if (debug) {
}
try {
} catch (CannotProceedException e) {
}
}
throws NamingException {
try {
} catch (CannotProceedException e) {
"No object reference bound for specified name");
throw ne;
}
}
throw e;
}
}
/**
* Converts the "String" name into a CompositeName object and
* performs the bind operation. Uses callBindOrRebind. Throws an
* invalid name exception if the name is empty.
* @param name string
* @param obj Object to be bound.
* @exception NamingException See callBindOrRebind
*/
}
/**
* Converts the "Name" name into a NameComponent[] object and
* performs the rebind operation. Uses callBindOrRebind. Throws an
* invalid name exception if the name is empty. We must have a name
* to rebind the object to even if we are working within the current
* context.
* @param name string
* @param obj Object to be bound.
* @exception NamingException See callBindOrRebind
*/
throws NamingException {
throw new InvalidNameException("Name is empty");
}
try {
} catch (CannotProceedException e) {
}
}
/**
* Converts the "String" name into a CompositeName object and
* performs the rebind operation. Uses callBindOrRebind. Throws an
* invalid name exception if the name is an empty string.
* @param name string
* @param obj Object to be bound.
* @exception NamingException See callBindOrRebind
*/
throws NamingException {
}
/**
* Calls the unbind api of COS Naming and uses the exception mapper
* class to map the exceptions
* @param path NameComponent[] object
* @exception NotFound No objects under the name. If leaf
* is not found, that's OK according to the JNDI spec
* @exception CannotProceed Unable to obtain a continuation context
* @exception InvalidName Name not understood.
*/
throw new ConfigurationException(
"Context does not have a corresponding NamingContext");
try {
} catch (NotFound e) {
// If leaf is the one missing, return success
// as per JNDI spec
; // do nothing
} else {
}
} catch (Exception e) {
}
}
// This test is not foolproof because some name servers
// always just return one component in rest_of_name
// so you might not be able to tell whether that is
}
/**
* Converts the "String" name into a CompositeName object and
* performs the unbind operation. Uses callUnbind. If the name is
* empty, throws an invalid name exception. Do we unbind the
* current context (JNDI spec says work with the current context if
* the name is empty) ?
* @param name string
* @exception NamingException See callUnbind
*/
}
/**
* Converts the "Name" name into a NameComponent[] object and
* performs the unbind operation. Uses callUnbind. Throws an
* invalid name exception if the name is empty.
* @param name string
* @exception NamingException See callUnbind
*/
throws NamingException {
throw new InvalidNameException("Name is empty");
try {
} catch (CannotProceedException e) {
}
}
/**
* Renames an object. Since COS Naming does not support a rename
* api, this method unbinds the object with the "oldName" and
* creates a new binding.
* @param oldName string, existing name for the binding.
* @param newName string, name used to replace.
* @exception NamingException See bind
*/
throws NamingException {
}
/**
* Renames an object. Since COS Naming does not support a rename
* api, this method unbinds the object with the "oldName" and
* creates a new binding.
* @param oldName JNDI Name, existing name for the binding.
* @param newName JNDI Name, name used to replace.
* @exception NamingException See bind
*/
throws NamingException {
throw new ConfigurationException(
"Context does not have a corresponding NamingContext");
throw new InvalidNameException("One or both names empty");
}
/**
* Returns a NameClassEnumeration object which has a list of name
* class pairs. Lists the current context if the name is empty.
* @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.
*/
}
/**
* 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.
*/
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.
*/
throws NamingException {
}
/**
* Returns a BindingEnumeration 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 returned by lookup.
* @return a list of bindings as a BindingEnumeration.
*/
throws NamingException {
throw new ConfigurationException(
"Context does not have a corresponding NamingContext");
try {
return new CNBindingEnumeration(
} else {
}
} catch (NamingException ne) {
throw ne;
} catch (BAD_PARAM e) {
ne.setRootCause(e);
throw ne;
}
}
return new CNBindingEnumeration(this, false, _env);
}
/**
* Calls the destroy on the COS Naming Server
* @param nc The NamingContext object to use.
* @exception NotEmpty when the context is not empty and cannot be destroyed.
*/
throws NamingException {
throw new ConfigurationException(
"Context does not have a corresponding NamingContext");
try {
} catch (Exception e) {
}
}
/**
* Uses the callDestroy function to destroy the context. If name is
* empty destroys the current context.
* @param name string
* @exception OperationNotSupportedException when list is invoked
* with a non-null argument
*/
}
/**
* Uses the callDestroy function to destroy the context. Destroys
* the current context if name is empty.
* @param name JNDI Name
* @exception OperationNotSupportedException when list is invoked
* with a non-null argument
*/
throws NamingException {
throw new ConfigurationException(
"Context does not have a corresponding NamingContext");
try {
} catch (ClassCastException e) {
} catch (CannotProceedException e) {
return;
} catch (NameNotFoundException e) {
// If leaf is the one missing, return success
// as per JNDI spec
if (e.getRootCause() instanceof NotFound &&
return; // leaf missing OK
}
throw e;
} catch (NamingException e) {
throw e;
}
}
}
/**
* Calls the bind_new_context COS naming api to create a new subcontext.
* @param path NameComponent[] object
* @exception NotFound No objects under the name.
* @exception CannotProceed Unable to obtain a continuation context
* @exception InvalidName Name not understood.
* @exception AlreadyBound An object is already bound to this name.
* @return the new context object.
*/
throws NamingException {
throw new ConfigurationException(
"Context does not have a corresponding NamingContext");
try {
makeFullName(path));
} catch (Exception e) {
}
}
/**
* Uses the callBindNewContext convenience function to create a new
* context. Throws an invalid name exception if the name is empty.
* @param name string
* @exception NamingException See callBindNewContext
* @return the new context object.
*/
throws NamingException {
}
/**
* Uses the callBindNewContext convenience function to create a new
* context. Throws an invalid name exception if the name is empty.
* @param name string
* @exception NamingException See callBindNewContext
* @return the new context object.
*/
throws NamingException {
throw new InvalidNameException("Name is empty");
try {
return callBindNewContext(path);
} catch (CannotProceedException e) {
}
}
/**
* Is mapped to resolve in the COS Naming api.
* @param name string
* @exception NamingException See lookup.
* @return the resolved object.
*/
}
/**
* Is mapped to resolve in the COS Naming api.
* @param name string
* @exception NamingException See lookup.
* @return the resolved object.
*/
}
/**
* Allow access to the name parser object.
* @param String JNDI name, is ignored since there is only one Name
* Parser object.
* @exception NamingException --
* @return NameParser object
*/
return parser;
}
/**
* Allow access to the name parser object.
* @param Name JNDI name, is ignored since there is only one Name
* Parser object.
* @exception NamingException --
* @return NameParser object
*/
return parser;
}
/**
* Returns the current environment.
* @return Environment.
*/
} else {
}
}
}
}
/**
* Adds to the environment for the current context.
* Record change but do not reinitialize ORB.
*
* @param propName The property name.
* @param propVal The ORB.
* @return the previous value of this property if any.
*/
throws NamingException {
} else {
// copy-on-write
}
}
// Record change but do not reinitialize ORB
throws NamingException {
// copy-on-write
}
return null;
}
synchronized public void incEnumCount() {
enumCount++;
if (debug) {
}
}
synchronized public void decEnumCount()
throws NamingException {
enumCount--;
if (debug) {
" isCloseCalled:" + isCloseCalled);
}
close();
}
}
if (enumCount > 0) {
isCloseCalled = true;
return;
}
// Never destroy an orb in CNCtx.
// from elsewhere, so that orb is somebody else's reponsibility.
}
protected void finalize() {
try {
close();
} catch (NamingException e) {
// ignore failures
}
}
}