< prev index next >

src/java.naming/share/classes/javax/naming/NamingException.java

Print this page




 177     public Object getResolvedObj() {
 178         return resolvedObj;
 179     }
 180 
 181     /**
 182       * Retrieves the explanation associated with this exception.
 183       *
 184       * @return The possibly null detail string explaining more
 185       *         about this exception. If null, it means there is no
 186       *         detail message for this exception.
 187       *
 188       * @see java.lang.Throwable#getMessage
 189       */
 190     public String getExplanation() {
 191         return getMessage();
 192     }
 193 
 194     /**
 195      * Sets the resolved name field of this exception.
 196      *<p>
 197      * <tt>name</tt> is a composite name. If the intent is to set
 198      * this field using a compound name or string, you must
 199      * "stringify" the compound name, and create a composite
 200      * name with a single component using the string. You can then
 201      * invoke this method using the resulting composite name.
 202      *<p>
 203      * A copy of <code>name</code> is made and stored.
 204      * Subsequent changes to <code>name</code> do not
 205      * affect the copy in this NamingException and vice versa.
 206      *
 207      * @param name The possibly null name to set resolved name to.
 208      *          If null, it sets the resolved name field to null.
 209      * @see #getResolvedName
 210      */
 211     public void setResolvedName(Name name) {
 212         if (name != null)
 213             resolvedName = (Name)(name.clone());
 214         else
 215             resolvedName = null;
 216     }
 217 
 218     /**
 219      * Sets the remaining name field of this exception.
 220      *<p>
 221      * <tt>name</tt> is a composite name. If the intent is to set
 222      * this field using a compound name or string, you must
 223      * "stringify" the compound name, and create a composite
 224      * name with a single component using the string. You can then
 225      * invoke this method using the resulting composite name.
 226      *<p>
 227      * A copy of <code>name</code> is made and stored.
 228      * Subsequent changes to <code>name</code> do not
 229      * affect the copy in this NamingException and vice versa.
 230      * @param name The possibly null name to set remaining name to.
 231      *          If null, it sets the remaining name field to null.
 232      * @see #getRemainingName
 233      * @see #appendRemainingName
 234      * @see #appendRemainingComponent
 235      */
 236     public void setRemainingName(Name name) {
 237         if (name != null)
 238             remainingName = (Name)(name.clone());
 239         else
 240             remainingName = null;
 241     }
 242 
 243     /**
 244      * Sets the resolved object field of this exception.
 245      * @param obj The possibly null object to set resolved object to.
 246      *            If null, the resolved object field is set to null.
 247      * @see #getResolvedObj
 248      */


 258       * @see #getRemainingName
 259       * @see #appendRemainingName
 260       */
 261     public void appendRemainingComponent(String name) {
 262         if (name != null) {
 263             try {
 264                 if (remainingName == null) {
 265                     remainingName = new CompositeName();
 266                 }
 267                 remainingName.add(name);
 268             } catch (NamingException e) {
 269                 throw new IllegalArgumentException(e.toString());
 270             }
 271         }
 272     }
 273 
 274     /**
 275       * Add components from 'name' as the last components in
 276       * remaining name.
 277       *<p>
 278       * <tt>name</tt> is a composite name. If the intent is to append
 279       * a compound name, you should "stringify" the compound name
 280       * then invoke the overloaded form that accepts a String parameter.
 281       *<p>
 282       * Subsequent changes to <code>name</code> do not
 283       * affect the remaining name field in this NamingException and vice versa.
 284       * @param name The possibly null name containing ordered components to add.
 285       *                 If name is null, this method does not do anything.
 286       * @see #setRemainingName
 287       * @see #getRemainingName
 288       * @see #appendRemainingComponent
 289       */
 290     public void appendRemainingName(Name name) {
 291         if (name == null) {
 292             return;
 293         }
 294         if (remainingName != null) {
 295             try {
 296                 remainingName.addAll(name);
 297             } catch (NamingException e) {
 298                 throw new IllegalArgumentException(e.toString());
 299             }
 300         } else {
 301             remainingName = (Name)(name.clone());
 302         }


 309       * but at the same time wants to use the NamingException structure
 310       * to indicate how far the naming operation proceeded.
 311       *<p>
 312       * This method predates the general-purpose exception chaining facility.
 313       * The {@link #getCause()} method is now the preferred means of obtaining
 314       * this information.
 315       *
 316       * @return The possibly null exception that caused this naming
 317       *    exception. If null, it means no root cause has been
 318       *    set for this naming exception.
 319       * @see #setRootCause
 320       * @see #rootException
 321       * @see #getCause
 322       */
 323     public Throwable getRootCause() {
 324         return rootException;
 325     }
 326 
 327     /**
 328       * Records the root cause of this NamingException.
 329       * If <tt>e</tt> is <tt>this</tt>, this method does not do anything.
 330       *<p>
 331       * This method predates the general-purpose exception chaining facility.
 332       * The {@link #initCause(Throwable)} method is now the preferred means
 333       * of recording this information.
 334       *
 335       * @param e The possibly null exception that caused the naming
 336       *          operation to fail. If null, it means this naming
 337       *          exception has no root cause.
 338       * @see #getRootCause
 339       * @see #rootException
 340       * @see #initCause
 341       */
 342     public void setRootCause(Throwable e) {
 343         if (e != this) {
 344             rootException = e;
 345         }
 346     }
 347 
 348     /**
 349       * Returns the cause of this exception.  The cause is the
 350       * throwable that caused this naming exception to be thrown.
 351       * Returns <code>null</code> if the cause is nonexistent or
 352       * unknown.
 353       *
 354       * @return  the cause of this exception, or <code>null</code> if the
 355       *          cause is nonexistent or unknown.
 356       * @see #initCause(Throwable)
 357       * @since 1.4
 358       */
 359     public Throwable getCause() {
 360         return getRootCause();
 361     }
 362 
 363     /**
 364       * Initializes the cause of this exception to the specified value.
 365       * The cause is the throwable that caused this naming exception to be
 366       * thrown.
 367       *<p>
 368       * This method may be called at most once.
 369       *
 370       * @param  cause   the cause, which is saved for later retrieval by
 371       *         the {@link #getCause()} method.  A <tt>null</tt> value
 372       *         indicates that the cause is nonexistent or unknown.
 373       * @return a reference to this <code>NamingException</code> instance.
 374       * @throws IllegalArgumentException if <code>cause</code> is this
 375       *         exception.  (A throwable cannot be its own cause.)
 376       * @throws IllegalStateException if this method has already
 377       *         been called on this exception.
 378       * @see #getCause
 379       * @since 1.4
 380       */
 381     public Throwable initCause(Throwable cause) {
 382         super.initCause(cause);
 383         setRootCause(cause);
 384         return this;
 385     }
 386 
 387     /**
 388      * Generates the string representation of this exception.
 389      * The string representation consists of this exception's class name,
 390      * its detailed message, and if it has a root cause, the string
 391      * representation of the root cause exception, followed by
 392      * the remaining name (if it is not null).
 393      * This string is used for debugging and not meant to be interpreted
 394      * programmatically.




 177     public Object getResolvedObj() {
 178         return resolvedObj;
 179     }
 180 
 181     /**
 182       * Retrieves the explanation associated with this exception.
 183       *
 184       * @return The possibly null detail string explaining more
 185       *         about this exception. If null, it means there is no
 186       *         detail message for this exception.
 187       *
 188       * @see java.lang.Throwable#getMessage
 189       */
 190     public String getExplanation() {
 191         return getMessage();
 192     }
 193 
 194     /**
 195      * Sets the resolved name field of this exception.
 196      *<p>
 197      * {@code name} is a composite name. If the intent is to set
 198      * this field using a compound name or string, you must
 199      * "stringify" the compound name, and create a composite
 200      * name with a single component using the string. You can then
 201      * invoke this method using the resulting composite name.
 202      *<p>
 203      * A copy of {@code name} is made and stored.
 204      * Subsequent changes to {@code name} do not
 205      * affect the copy in this NamingException and vice versa.
 206      *
 207      * @param name The possibly null name to set resolved name to.
 208      *          If null, it sets the resolved name field to null.
 209      * @see #getResolvedName
 210      */
 211     public void setResolvedName(Name name) {
 212         if (name != null)
 213             resolvedName = (Name)(name.clone());
 214         else
 215             resolvedName = null;
 216     }
 217 
 218     /**
 219      * Sets the remaining name field of this exception.
 220      *<p>
 221      * {@code name} is a composite name. If the intent is to set
 222      * this field using a compound name or string, you must
 223      * "stringify" the compound name, and create a composite
 224      * name with a single component using the string. You can then
 225      * invoke this method using the resulting composite name.
 226      *<p>
 227      * A copy of {@code name} is made and stored.
 228      * Subsequent changes to {@code name} do not
 229      * affect the copy in this NamingException and vice versa.
 230      * @param name The possibly null name to set remaining name to.
 231      *          If null, it sets the remaining name field to null.
 232      * @see #getRemainingName
 233      * @see #appendRemainingName
 234      * @see #appendRemainingComponent
 235      */
 236     public void setRemainingName(Name name) {
 237         if (name != null)
 238             remainingName = (Name)(name.clone());
 239         else
 240             remainingName = null;
 241     }
 242 
 243     /**
 244      * Sets the resolved object field of this exception.
 245      * @param obj The possibly null object to set resolved object to.
 246      *            If null, the resolved object field is set to null.
 247      * @see #getResolvedObj
 248      */


 258       * @see #getRemainingName
 259       * @see #appendRemainingName
 260       */
 261     public void appendRemainingComponent(String name) {
 262         if (name != null) {
 263             try {
 264                 if (remainingName == null) {
 265                     remainingName = new CompositeName();
 266                 }
 267                 remainingName.add(name);
 268             } catch (NamingException e) {
 269                 throw new IllegalArgumentException(e.toString());
 270             }
 271         }
 272     }
 273 
 274     /**
 275       * Add components from 'name' as the last components in
 276       * remaining name.
 277       *<p>
 278       * {@code name} is a composite name. If the intent is to append
 279       * a compound name, you should "stringify" the compound name
 280       * then invoke the overloaded form that accepts a String parameter.
 281       *<p>
 282       * Subsequent changes to {@code name} do not
 283       * affect the remaining name field in this NamingException and vice versa.
 284       * @param name The possibly null name containing ordered components to add.
 285       *                 If name is null, this method does not do anything.
 286       * @see #setRemainingName
 287       * @see #getRemainingName
 288       * @see #appendRemainingComponent
 289       */
 290     public void appendRemainingName(Name name) {
 291         if (name == null) {
 292             return;
 293         }
 294         if (remainingName != null) {
 295             try {
 296                 remainingName.addAll(name);
 297             } catch (NamingException e) {
 298                 throw new IllegalArgumentException(e.toString());
 299             }
 300         } else {
 301             remainingName = (Name)(name.clone());
 302         }


 309       * but at the same time wants to use the NamingException structure
 310       * to indicate how far the naming operation proceeded.
 311       *<p>
 312       * This method predates the general-purpose exception chaining facility.
 313       * The {@link #getCause()} method is now the preferred means of obtaining
 314       * this information.
 315       *
 316       * @return The possibly null exception that caused this naming
 317       *    exception. If null, it means no root cause has been
 318       *    set for this naming exception.
 319       * @see #setRootCause
 320       * @see #rootException
 321       * @see #getCause
 322       */
 323     public Throwable getRootCause() {
 324         return rootException;
 325     }
 326 
 327     /**
 328       * Records the root cause of this NamingException.
 329       * If {@code e} is {@code this}, this method does not do anything.
 330       *<p>
 331       * This method predates the general-purpose exception chaining facility.
 332       * The {@link #initCause(Throwable)} method is now the preferred means
 333       * of recording this information.
 334       *
 335       * @param e The possibly null exception that caused the naming
 336       *          operation to fail. If null, it means this naming
 337       *          exception has no root cause.
 338       * @see #getRootCause
 339       * @see #rootException
 340       * @see #initCause
 341       */
 342     public void setRootCause(Throwable e) {
 343         if (e != this) {
 344             rootException = e;
 345         }
 346     }
 347 
 348     /**
 349       * Returns the cause of this exception.  The cause is the
 350       * throwable that caused this naming exception to be thrown.
 351       * Returns {@code null} if the cause is nonexistent or
 352       * unknown.
 353       *
 354       * @return  the cause of this exception, or {@code null} if the
 355       *          cause is nonexistent or unknown.
 356       * @see #initCause(Throwable)
 357       * @since 1.4
 358       */
 359     public Throwable getCause() {
 360         return getRootCause();
 361     }
 362 
 363     /**
 364       * Initializes the cause of this exception to the specified value.
 365       * The cause is the throwable that caused this naming exception to be
 366       * thrown.
 367       *<p>
 368       * This method may be called at most once.
 369       *
 370       * @param  cause   the cause, which is saved for later retrieval by
 371       *         the {@link #getCause()} method.  A {@code null} value
 372       *         indicates that the cause is nonexistent or unknown.
 373       * @return a reference to this {@code NamingException} instance.
 374       * @throws IllegalArgumentException if {@code cause} is this
 375       *         exception.  (A throwable cannot be its own cause.)
 376       * @throws IllegalStateException if this method has already
 377       *         been called on this exception.
 378       * @see #getCause
 379       * @since 1.4
 380       */
 381     public Throwable initCause(Throwable cause) {
 382         super.initCause(cause);
 383         setRootCause(cause);
 384         return this;
 385     }
 386 
 387     /**
 388      * Generates the string representation of this exception.
 389      * The string representation consists of this exception's class name,
 390      * its detailed message, and if it has a root cause, the string
 391      * representation of the root cause exception, followed by
 392      * the remaining name (if it is not null).
 393      * This string is used for debugging and not meant to be interpreted
 394      * programmatically.


< prev index next >