Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
I'm looking for way of checking bind status of object and appropriate jndi name. For example, I've got some ldap jms queue name: "/TheRootContext/SomeSubContext/SOME.QUEUE.NAME:queue" I need to check that appropriate queue exists and it is binded with passed name. What will be the correct way to check "bind status"? I see such algorithm: Perform jndi lookup to ensure that provided name ex...
I'm using JUnit test cases to exercise my web service using embedded Tomcat. Under Tomcat 6 everything was working fine, but when I switched my project to Tomcat 7 I'm coming unstuck. The test code to setup the embedded Tomcat server is as follows: Tomcat 6 Embedded container = new Embedded(); container.setCatalinaHome("C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0.11"); containe...
  /*
   * Copyright 1999-2003 Sun Microsystems, Inc.  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.  Sun designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
  * have any questions.
  */
 
 package javax.naming;

This is the superclass of all exceptions thrown by operations in the Context and DirContext interfaces. The nature of the failure is described by the name of the subclass. This exception captures the information pinpointing where the operation failed, such as where resolution last proceeded to.
  • Resolved Name. Portion of name that has been resolved.
  • Resolved Object. Object to which resolution of name proceeded.
  • Remaining Name. Portion of name that has not been resolved.
  • Explanation. Detail explaining why name resolution failed.
  • Root Exception. The exception that caused this naming exception to be thrown.
null is an acceptable value for any of these fields. When null, it means that no such information has been recorded for that field.

A NamingException instance is not synchronized against concurrent multithreaded access. Multiple threads trying to access and modify a single NamingException instance should lock the object.

This exception has been retrofitted to conform to the general purpose exception-chaining mechanism. The root exception (or root cause) is the same object as the cause returned by the java.lang.Throwable.getCause() method.

Author(s):
Rosanna Lee
Scott Seligman
Since:
1.3
 
 
 
 public class NamingException extends Exception {
    
Contains the part of the name that has been successfully resolved. It is a composite name and can be null. This field is initialized by the constructors. You should access and manipulate this field through its get and set methods.

 
     protected Name resolvedName;
    
Contains the object to which resolution of the part of the name was successful. Can be null. This field is initialized by the constructors. You should access and manipulate this field through its get and set methods.

 
     protected Object resolvedObj;
    
Contains the remaining name that has not been resolved yet. It is a composite name and can be null. This field is initialized by the constructors. You should access and manipulate this field through its get, set, "append" methods.

 
     protected Name remainingName;

    
Contains the original exception that caused this NamingException to be thrown. This field is set if there is additional information that could be obtained from the original exception, or if the original exception could not be mapped to a subclass of NamingException. Can be null.

This field predates the general-purpose exception chaining facility. The initCause(java.lang.Throwable) and getCause() methods are now the preferred means of accessing this information.

    protected Throwable rootException = null;

    
Constructs a new NamingException with an explanation. All unspecified fields are set to null.

Parameters:
explanation A possibly null string containing additional detail about this exception.
See also:
java.lang.Throwable.getMessage()
    public NamingException(String explanation) {
        super(explanation);
         =  = null;
         = null;
    }

    
Constructs a new NamingException. All fields are set to null.
    public NamingException() {
        super();
         =  = null;
         = null;
    }

    
Retrieves the leading portion of the name that was resolved successfully.

Returns:
The part of the name that was resolved successfully. It is a composite name. It can be null, which means the resolved name field has not been set.
See also:
getResolvedObj()
setResolvedName(javax.naming.Name)
    public Name getResolvedName() {
        return ;
    }

    
Retrieves the remaining unresolved portion of the name.

Returns:
The part of the name that has not been resolved. It is a composite name. It can be null, which means the remaining name field has not been set.
See also:
setRemainingName(javax.naming.Name)
appendRemainingName(javax.naming.Name)
appendRemainingComponent(java.lang.String)
    public Name getRemainingName() {
        return ;
    }

    
Retrieves the object to which resolution was successful. This is the object to which the resolved name is bound.

Returns:
The possibly null object that was resolved so far. null means that the resolved object field has not been set.
See also:
getResolvedName()
setResolvedObj(java.lang.Object)
    public Object getResolvedObj() {
        return ;
    }

    
Retrieves the explanation associated with this exception.

Returns:
The possibly null detail string explaining more about this exception. If null, it means there is no detail message for this exception.
See also:
java.lang.Throwable.getMessage()
    public String getExplanation() {
        return getMessage();
    }

    
Sets the resolved name field of this exception.

name is a composite name. If the intent is to set this field using a compound name or string, you must "stringify" the compound name, and create a composite name with a single component using the string. You can then invoke this method using the resulting composite name.

A copy of name is made and stored. Subsequent changes to name does not affect the copy in this NamingException and vice versa.

Parameters:
name The possibly null name to set resolved name to. If null, it sets the resolved name field to null.
See also:
getResolvedName()
    public void setResolvedName(Name name) {
        if (name != null)
             = (Name)(name.clone());
        else
             = null;
    }

    
Sets the remaining name field of this exception.

name is a composite name. If the intent is to set this field using a compound name or string, you must "stringify" the compound name, and create a composite name with a single component using the string. You can then invoke this method using the resulting composite name.

A copy of name is made and stored. Subsequent changes to name does not affect the copy in this NamingException and vice versa.

Parameters:
name The possibly null name to set remaining name to. If null, it sets the remaining name field to null.
See also:
getRemainingName()
appendRemainingName(javax.naming.Name)
appendRemainingComponent(java.lang.String)
    public void setRemainingName(Name name) {
        if (name != null)
             = (Name)(name.clone());
        else
             = null;
    }

    
Sets the resolved object field of this exception.

Parameters:
obj The possibly null object to set resolved object to. If null, the resolved object field is set to null.
See also:
getResolvedObj()
    public void setResolvedObj(Object obj) {
         = obj;
    }

    
Add name as the last component in remaining name.

Parameters:
name The component to add. If name is null, this method does not do anything.
See also:
setRemainingName(javax.naming.Name)
getRemainingName()
appendRemainingName(javax.naming.Name)
    public void appendRemainingComponent(String name) {
        if (name != null) {
            try {
                if ( == null) {
                     = new CompositeName();
                }
                .add(name);
            } catch (NamingException e) {
                throw new IllegalArgumentException(e.toString());
            }
        }
    }

    
Add components from 'name' as the last components in remaining name.

name is a composite name. If the intent is to append a compound name, you should "stringify" the compound name then invoke the overloaded form that accepts a String parameter.

Subsequent changes to name does not affect the remaining name field in this NamingException and vice versa.

Parameters:
name The possibly null name containing ordered components to add. If name is null, this method does not do anything.
See also:
setRemainingName(javax.naming.Name)
getRemainingName()
appendRemainingComponent(java.lang.String)
    public void appendRemainingName(Name name) {
        if (name == null) {
            return;
        }
        if ( != null) {
            try {
                .addAll(name);
            } catch (NamingException e) {
                throw new IllegalArgumentException(e.toString());
            }
        } else {
             = (Name)(name.clone());
        }
    }

    
Retrieves the root cause of this NamingException, if any. The root cause of a naming exception is used when the service provider wants to indicate to the caller a non-naming related exception but at the same time wants to use the NamingException structure to indicate how far the naming operation proceeded.

This method predates the general-purpose exception chaining facility. The getCause() method is now the preferred means of obtaining this information.

Returns:
The possibly null exception that caused this naming exception. If null, it means no root cause has been set for this naming exception.
See also:
setRootCause(java.lang.Throwable)
rootException
getCause()
    public Throwable getRootCause() {
        return ;
    }

    
Records the root cause of this NamingException. If e is this, this method does not do anything.

This method predates the general-purpose exception chaining facility. The initCause(java.lang.Throwable) method is now the preferred means of recording this information.

Parameters:
e The possibly null exception that caused the naming operation to fail. If null, it means this naming exception has no root cause.
See also:
getRootCause()
rootException
initCause(java.lang.Throwable)
    public void setRootCause(Throwable e) {
        if (e != this) {
             = e;
        }
    }

    
Returns the cause of this exception. The cause is the throwable that caused this naming exception to be thrown. Returns null if the cause is nonexistent or unknown.

Returns:
the cause of this exception, or null if the cause is nonexistent or unknown.
Since:
1.4
See also:
initCause(java.lang.Throwable)
    public Throwable getCause() {
        return getRootCause();
    }

    
Initializes the cause of this exception to the specified value. The cause is the throwable that caused this naming exception to be thrown.

This method may be called at most once.

Parameters:
cause the cause, which is saved for later retrieval by the getCause() method. A null value indicates that the cause is nonexistent or unknown.
Returns:
a reference to this NamingException instance.
Throws:
java.lang.IllegalArgumentException if cause is this exception. (A throwable cannot be its own cause.)
java.lang.IllegalStateException if this method has already been called on this exception.
Since:
1.4
See also:
getCause()
    public Throwable initCause(Throwable cause) {
        super.initCause(cause);
        setRootCause(cause);
        return this;
    }

    
Generates the string representation of this exception. The string representation consists of this exception's class name, its detailed message, and if it has a root cause, the string representation of the root cause exception, followed by the remaining name (if it is not null). This string is used for debugging and not meant to be interpreted programmatically.

Returns:
The non-null string containing the string representation of this exception.
    public String toString() {
        String answer = super.toString();
        if ( != null) {
            answer += " [Root exception is " +  + "]";
        }
        if ( != null) {
            answer += "; remaining name '" +  + "'";
        }
        return answer;
    }

    
Generates the string representation in more detail. This string representation consists of the information returned by the toString() that takes no parameters, plus the string representation of the resolved object (if it is not null). This string is used for debugging and not meant to be interpreted programmatically.

Parameters:
detail If true, include details about the resolved object in addition to the other information.
Returns:
The non-null string containing the string representation.
    public String toString(boolean detail) {
        if (!detail ||  == null) {
            return toString();
        } else {
            return (toString() + "; resolved object " + );
        }
    }

    
Use serialVersionUID from JNDI 1.1.1 for interoperability
    private static final long serialVersionUID = -1299181962103167177L;
};
New to GrepCode? Check out our FAQ X