/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.dynamo.except;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;
import com.silverwrist.dynamo.iface.DynamicClass;

public class CallFailureException extends DynamicObjectException
{
  /*--------------------------------------------------------------------------------
   * Static data members
   *--------------------------------------------------------------------------------
   */

  private static final String BUNDLE = "com.silverwrist.dynamo.except.DynamoExceptionMessages";

  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private Object[] m_args;

  /*--------------------------------------------------------------------------------
   * Constructors
   *--------------------------------------------------------------------------------
   */

  public CallFailureException(DynamicClass klass, Throwable cause)
  {
    super("call to dynamic class " + klass.getName() + " failed with " + cause.getClass().getName(),cause);
    m_args = new Object[2];
    m_args[0] = klass.getName();
    m_args[1] = cause.getClass().getName();

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Overrides from class Throwable
   *--------------------------------------------------------------------------------
   */

  /**
   * Creates a localized description of this exception. Subclasses may override this method in
   * order to produce a locale-specific message. For subclasses that do not override this method,
   * the default implementation returns the same result as <CODE>getMessage()</CODE>.
   *
   * @return The localized description of this exception.
   */
  public String getLocalizedMessage()
  {
    return this.getLocalizedMessage(Locale.getDefault());

  } // end getLocalizedMessage

  /*--------------------------------------------------------------------------------
   * Overrides from class DynamoRuntimeException
   *--------------------------------------------------------------------------------
   */

  /**
   * Creates a localized description of this exception. Subclasses may override this method in
   * order to produce a locale-specific message. For subclasses that do not override this method,
   * the default implementation returns the same result as <CODE>getLocalizedMessage()</CODE>.
   *
   * @param locale The locale to render the message in.
   * @return The localized description of this exception.
   */
  public String getLocalizedMessage(Locale locale)
  {
    ResourceBundle b = ResourceBundle.getBundle(BUNDLE,locale,getClass().getClassLoader());
    return MessageFormat.format(b.getString("callFailure"),m_args);

  } // end getLocalizedMessage

  /*--------------------------------------------------------------------------------
   * External operations
   *--------------------------------------------------------------------------------
   */

  public Throwable getTargetException()
  {
    return getCause();

  } // end getTargetException

} // end class CallFailureException
