javacommons/utils/javasrc/com/nokia/mj/impl/utils/ErrorMessageBase.java
branchRCL_3
changeset 19 04becd199f91
child 48 e0d6e9bd3ca7
child 60 6c158198356e
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 package com.nokia.mj.impl.utils;
       
    19 
       
    20 import com.nokia.mj.impl.utils.ResourceLoader;
       
    21 
       
    22 import java.util.Hashtable;
       
    23 
       
    24 /**
       
    25  * Base class for classes defining localized error messages.
       
    26  *
       
    27  * @author Nokia Corporation
       
    28  * @version 1.0
       
    29  * @see InstallerExceptionBase
       
    30  */
       
    31 abstract public class ErrorMessageBase
       
    32 {
       
    33     /*** ----------------------------- PUBLIC ------------------------------ */
       
    34 
       
    35     public static final int NO_MSG = 0; // Used when the error message is not available.
       
    36 
       
    37     /**
       
    38      * Method for retrieving the message of a certain error.
       
    39      *
       
    40      * @param errorCode The error code whose message is queried
       
    41      * @param errorMessageParameters The parameters to be filled into the
       
    42      * message
       
    43      * @return The corresponding message including the provided
       
    44      * parameters
       
    45      */
       
    46     public String get(int errorCode, String[] errorMessageParameters)
       
    47     {
       
    48         Hashtable messageTable = getMessageTable();
       
    49         String msgId = ((String)messageTable.get(new Integer(errorCode)));
       
    50         if (msgId == null)
       
    51         {
       
    52             return this.getClass().getName() + ": No message found for error " + errorCode;
       
    53         }
       
    54         return getResourceLoader().format(msgId, errorMessageParameters);
       
    55     }
       
    56 
       
    57     /*** ---------------------------- PROTECTED --------------------------- */
       
    58 
       
    59     /**
       
    60      * Method for getting message table where key is an Integer value for
       
    61      * the error code, and value is an error message String id.
       
    62      * This method must be overriden in inheriting class.
       
    63      */
       
    64     abstract protected Hashtable getMessageTable();
       
    65 
       
    66     /**
       
    67      * Method for retrieving the ResourceLoader instance that is used
       
    68      * to localise error messages.
       
    69      * This method must be overriden in inheriting class.
       
    70      */
       
    71     abstract protected ResourceLoader getResourceLoader();
       
    72 
       
    73     /*** ----------------------------- PACKAGE ---------------------------- */
       
    74     /*** ----------------------------- PRIVATE ---------------------------- */
       
    75     /*** ----------------------------- NATIVE ----------------------------- */
       
    76 }