mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
07.12.2009 300625b855bded33c79af6570d9bcdd6f9aca7c6
opendj-sdk/opends/src/ads/org/opends/admin/ads/ADSContextException.java
@@ -22,11 +22,13 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 */
package org.opends.admin.ads;
import static org.opends.messages.QuickSetupMessages.*;
import org.opends.messages.Message;
import org.opends.server.types.OpenDsException;
@@ -120,7 +122,7 @@
   */
  public ADSContextException(ErrorType error)
  {
    this.error = error;
    this(error, null);
  }
  /**
@@ -131,8 +133,14 @@
   */
  public ADSContextException(ErrorType error, Throwable x)
  {
    super(getMessage(error, x), x);
    this.error = error;
    this.embeddedException = x;
    toString = "ADSContextException: error type "+error+".";
    if (getCause() != null)
    {
      toString += "  Root cause: "+getCause().toString();
    }
  }
  /**
@@ -154,24 +162,6 @@
  }
  /**
   * Retrieves a message providing the reason for this exception.
   *
   * @return  A message providing the reason for this exception.
   */
  public Message getReason()
  {
    if (toString == null)
    {
      toString = "ADSContextException: error type "+error+".";
      if (getCause() != null)
      {
        toString += "  Root cause: "+getCause().toString();
      }
    }
    return Message.raw(toString); // TODO: i18n
  }
  /**
   * {@inheritDoc}
   */
  public void printStackTrace()
@@ -184,4 +174,35 @@
      System.out.println("}");
    }
  }
  /**
   * {@inheritDoc}
   */
  public String toString()
  {
    return toString;
  }
  private static Message getMessage(ErrorType error, Throwable x)
  {
    Message msg;
    if (x != null)
    {
      if (x instanceof OpenDsException)
      {
        msg = INFO_ADS_CONTEXT_EXCEPTION_WITH_DETAILS_MSG.get(error.toString(),
            ((OpenDsException)x).getMessageObject());
      }
      else
      {
        msg = INFO_ADS_CONTEXT_EXCEPTION_WITH_DETAILS_MSG.get(error.toString(),
            x.toString());
      }
    }
    else
    {
      msg = INFO_ADS_CONTEXT_EXCEPTION_MSG.get(error.toString());
    }
    return msg;
  }
}