/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.data.engine.core;

import java.util.Locale;

import org.eclipse.birt.data.engine.i18n.DataResourceHandle;

/**
 * 
 */

public class DataException extends Exception
{
	private String errorCode;
	private Object argv[];

	/** static ResourceHandle */
	private static DataResourceHandle resourceHandle = new DataResourceHandle( Locale.getDefault( ) );
	
	/*
	 * @see BirtException(errorCode)
	 */
	public DataException( String errorCode )
	{
		this.errorCode = errorCode;
	}
	
	/**
	 * Support provided additional parameter
	 * @param errorCode
	 * @param argv
	 */
	public DataException( String errorCode, Object argv )
	{
		this.errorCode = errorCode;
		this.argv = new Object[]{
			argv
		};
	}
	
	/**
	 * Support provided additional parameter
	 * @param errorCode
	 * @param argv[]
	 */
	public DataException( String errorCode, Object argv[] )
	{
		this.errorCode = errorCode;
		this.argv = argv;
	}
    
    /*
     * @see BirtException(message, errorCode)
     */
    public DataException( String errorCode, Throwable cause )
    {
    	super(cause);
    	this.errorCode = errorCode;
    }
    
    public DataException( String errorCode, Throwable cause, Object argv )
    {
    	super(cause);
    	this.errorCode = errorCode;
		this.argv = new Object[]{
				argv
			};
    }
    
    public DataException( String errorCode, Throwable cause, Object argv[] )
    {
    	super(cause);
    	this.errorCode = errorCode;
    	this.argv = argv;
    }
    
    /**
     * @return errrorCode
     */
    public String getErrorCode( )
    {
    	return errorCode;
    }
    
	/*
	 * @see java.lang.Throwable#getMessage()
	 */
	public String getMessage( )
	{
		if ( argv == null )
		{
			return resourceHandle.getMessage( errorCode );
		}
		else
		{
			return resourceHandle.getMessage( errorCode, argv );
		}
	}
	
}

@@ -622,53 +622,349 @@
 irt.
-data.engine.i18n.DataResourceHandle;%0A%0A/**%0A * 
+core.exception.BirtException;%0Aimport org.eclipse.birt.data.engine.i18n.DataResourceHandle;%0A%0A/**%0A * Implementation of BirtException in DtE project.%0A * Currently BirtException's methods are all overrided to avoid%0A * mistake in test, but this way will be changed to not overridding%0A * its main methods like getErrorCode and getLocalizedMessage.
 %0A */
@@ -1000,16 +1000,20 @@
 extends 
+Birt
 Exceptio
@@ -1200,16 +1200,80 @@
  ) );%0A%09%0A
+%09private static String ERROR_CODE_PREFIX = %22DATA_EXCEPTION_%22;%0A%09%0A
 %09/*%0A%09 * 
@@ -1348,24 +1348,83 @@
 orCode )%0A%09%7B%0A
+%09%09super( errorCode, resourceHandle.getResourceBundle( ) );%0A
 %09%09this.error
@@ -1589,24 +1589,89 @@
 t argv )%0A%09%7B%0A
+%09%09super( errorCode, argv, resourceHandle.getResourceBundle( ) );%0A
 %09%09this.error
@@ -1885,16 +1885,81 @@
 %5B%5D )%0A%09%7B%0A
+%09%09super( errorCode, argv, resourceHandle.getResourceBundle( ) );%0A
 %09%09this.e
@@ -2140,37 +2140,87 @@
    %7B%0A    %09super(
+ errorCode, resourceHandle.getResourceBundle( ), 
 cause
+ 
 );%0A    %09this.err
@@ -2334,32 +2334,87 @@
    %7B%0A    %09super(
+ errorCode, argv, resourceHandle.getResourceBundle( ), 
 cause);%0A    %09thi
@@ -2586,21 +2586,77 @@
  %09super(
+ errorCode, argv, resourceHandle.getResourceBundle( ), 
 cause
+ 
 );%0A    %09
@@ -2811,31 +2811,188 @@
 %09return 
-errorCode;%0A    
+ERROR_CODE_PREFIX + errorCode;%0A    %7D%0A    %0A%0A    /*%0A%09 * @see java.lang.Throwable#getLocalizedMessage()%0A%09 */%0A%09public String getLocalizedMessage( )%0A%09%7B%0A%09%09return getMessage( );%0A%09
 %7D%0A    %0A%09

Make DataException extend BirtException, and set DATA_EXCEPTION as error code prefix.