/*
 * 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) 2003 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 ParameterCountException extends DynamicObjectRuntimeException
{
  /*--------------------------------------------------------------------------------
   * Static data members
   *--------------------------------------------------------------------------------
   */

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

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

  private String[] m_args;
  private String m_message = null;

  /*--------------------------------------------------------------------------------
   * Constructor
   *--------------------------------------------------------------------------------
   */

  public ParameterCountException(DynamicClass dclass, String method_name, int desired_length, int actual_length)
  {
    super("");
    m_args = new String[4];
    m_args[0] = dclass.getName();
    m_args[1] = method_name;
    m_args[2] = String.valueOf(desired_length);
    m_args[3] = String.valueOf(actual_length);

  } // end constructor

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

  public String getMessage()
  {
    if (m_message==null)
      m_message = getLocalizedMessage(Locale.US);
    return m_message;

  } // end getMessage

  /**
   * 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,ParameterCountException.class.getClassLoader());
    return MessageFormat.format(b.getString(MESSAGE),m_args);

  } // end getLocalizedMessage

} // end class ParameterCountException
