/*******************************************************************************
 * Copyright (C) 2013 Snowdream Mobile
 *
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/

package com.github.snowdream.android.app;


/**
 * @author snowdream <yanghui1986527@gmail.com>
 * @date Sep 29, 2013
 * @version v1.0
 */
public class DownloadException extends Exception {
    private int code = UNKNOWN;

    /** serialVersionUID **/
    private static final long serialVersionUID = -3804737584048978515L;

    public static final int UNKNOWN = 0;

    /**
     * The task is not valid.
     */
    public static final int DOWNLOAD_TASK_NOT_VALID = 1;
    
    /**
     * the operation is not valid.
     */
    public static final int OPERATION_NOT_VALID = 10;
    
    /**
     * The task failed.
     */
    public static final int DOWNLOAD_TASK_FAILED = 11;

    public DownloadException() {
    }

    public DownloadException(int code) {
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
}

@@ -971,16 +971,49 @@
 UNKNOWN;
+%0A    private String message = %22%22;
 %0A%0A    /*
@@ -1108,16 +1108,53 @@
 8515L;%0A%0A
+    /**%0A     * Unknown Error%0A     */%0A
     publ
@@ -1289,16 +1289,112 @@
 LID = 1;
+%0A%0A    /**%0A     * The context is NULL.%0A     */%0A    public static final int CONTEXT_NOT_VALID = 2;
 %0A    %0A  
@@ -1627,18 +1627,198 @@
 eption()
- 
 %7B
+%0A        this.code = UNKNOWN;%0A        generateMessageFromCode(code);%0A    %7D%0A%0A    public DownloadException(int code) %7B%0A        this.code = code;%0A        generateMessageFromCode(code);
 %0A    %7D%0A%0A
@@ -1846,32 +1846,47 @@
 ception(int code
+,String message
 ) %7B%0A        this
@@ -1895,24 +1895,56 @@
 ode = code;%0A
+        this.message = message;%0A
     %7D%0A%0A    p
@@ -2060,11 +2060,1025 @@
 e;%0A    %7D
+%0A%0A    public String getMessage() %7B%0A        return message;%0A    %7D%0A%0A    public void setMessage(String message) %7B%0A        this.message = message;%0A    %7D%0A%0A    /**%0A     * Generage the error message with the code%0A     * @param code%0A     */%0A    private void generateMessageFromCode(int code)%7B%0A        if (message != null && message != %22%22)%7B%0A            return;%0A        %7D%0A%0A        switch (code)%7B%0A            case DOWNLOAD_TASK_NOT_VALID:%0A                message = %22The DownloadTask is null or not valid!%22;%0A                break;%0A            case CONTEXT_NOT_VALID:%0A                message = %22The Context is null or not valid!%22;%0A                break;%0A            case OPERATION_NOT_VALID:%0A                message = %22The operation is not allowed!%22;%0A                break;%0A            case DOWNLOAD_TASK_FAILED:%0A                message = %22The Download Task is failed!%22;%0A                break;%0A            case UNKNOWN:%0A            default:%0A                    message = %22Unknown Error!%22;%0A                break;%0A        %7D%0A    %7D
 %0A%7D%0A

add message to DownloadException