javacommons/utils/javasrc/com/nokia/mj/impl/utils/ErrorMessageBase.java
branchRCL_3
changeset 83 26b2b12093af
parent 60 6c158198356e
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
     1 /*
     1 /*
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    22 import java.util.Hashtable;
    22 import java.util.Hashtable;
    23 
    23 
    24 /**
    24 /**
    25  * Base class for classes defining localized error messages.
    25  * Base class for classes defining localized error messages.
    26  *
    26  *
       
    27  * @author Nokia Corporation
       
    28  * @version 1.0
    27  * @see InstallerExceptionBase
    29  * @see InstallerExceptionBase
    28  */
    30  */
    29 abstract public class ErrorMessageBase
    31 abstract public class ErrorMessageBase
    30 {
    32 {
    31     /*** ----------------------------- PUBLIC ------------------------------ */
    33     /*** ----------------------------- PUBLIC ------------------------------ */
    32 
    34 
    33     public static final int NO_MSG = 0; // Used when the error message is not available.
    35     public static final int NO_MSG = 0; // Used when the error message is not available.
    34 
       
    35     /** Start of Runtime error message ids range. */
       
    36     public static final int RUNTIME_RANGE_START = 0;
       
    37     /** End of Runtime error message ids range. */
       
    38     public static final int RUNTIME_RANGE_END = 99;
       
    39     /** Start of Installer error message ids range. */
       
    40     public static final int INSTALLER_RANGE_START = 100;
       
    41     /** End of Installer error message ids range. */
       
    42     public static final int INSTALLER_RANGE_END = 199;
       
    43     /** Start of Security error message ids range. */
       
    44     public static final int SECURITY_RANGE_START = 200;
       
    45     /** End of Security error message ids range. */
       
    46     public static final int SECURITY_RANGE_END = 299;
       
    47 
    36 
    48     /**
    37     /**
    49      * Method for retrieving the message of a certain error.
    38      * Method for retrieving the message of a certain error.
    50      *
    39      *
    51      * @param errorCode The error code whose message is queried
    40      * @param errorCode The error code whose message is queried
    60         String msgId = ((String)messageTable.get(new Integer(errorCode)));
    49         String msgId = ((String)messageTable.get(new Integer(errorCode)));
    61         if (msgId == null)
    50         if (msgId == null)
    62         {
    51         {
    63             return this.getClass().getName() + ": No message found for error " + errorCode;
    52             return this.getClass().getName() + ": No message found for error " + errorCode;
    64         }
    53         }
    65         ResourceLoader rl = getResourceLoader();
    54         return getResourceLoader().format(msgId, errorMessageParameters);
    66         if (rl == null)
       
    67         {
       
    68             rl = getResourceLoader(errorCode);
       
    69         }
       
    70         return rl.format(msgId, errorMessageParameters);
       
    71     }
    55     }
    72 
    56 
    73     /*** ---------------------------- PROTECTED --------------------------- */
    57     /*** ---------------------------- PROTECTED --------------------------- */
    74 
    58 
    75     /**
    59     /**
    79      */
    63      */
    80     abstract protected Hashtable getMessageTable();
    64     abstract protected Hashtable getMessageTable();
    81 
    65 
    82     /**
    66     /**
    83      * Method for retrieving the ResourceLoader instance that is used
    67      * Method for retrieving the ResourceLoader instance that is used
    84      * to localise error messages. If this method returns null,
    68      * to localise error messages.
    85      * the ResourceLoader is obtained with getResourceLoader(int)
       
    86      * method variant which then must not return null.
       
    87      *
       
    88      * This method must be overriden in inheriting class.
    69      * This method must be overriden in inheriting class.
    89      */
    70      */
    90     abstract protected ResourceLoader getResourceLoader();
    71     abstract protected ResourceLoader getResourceLoader();
    91 
       
    92     /**
       
    93      * Method for retrieving the ResourceLoader instance that is used
       
    94      * to localise error message for specified error code.
       
    95      * This method must be overriden in inheriting class if
       
    96      * the getResourceLoader() method variant returns null.
       
    97      *
       
    98      * @param errorCode error code for which ResourceLoader is returned
       
    99      */
       
   100     protected ResourceLoader getResourceLoader(int errorCode)
       
   101     {
       
   102         return null;
       
   103     }
       
   104 
       
   105     /**
       
   106      * Method for retrieving the ResourceLoader instance.
       
   107      * This method is called from inheriting class
       
   108      * getResourceLoader(int) method variant.
       
   109      *
       
   110      * @param textFilename name for text file
       
   111      * @param textPrefix prefix for text ids
       
   112      */
       
   113     private static Hashtable iResourceLoaderTable = null;
       
   114     protected static ResourceLoader getResourceLoader(String textFilename, String textPrefix)
       
   115     {
       
   116         String key = textFilename + "::" + textPrefix;
       
   117         if (iResourceLoaderTable == null)
       
   118         {
       
   119             iResourceLoaderTable = new Hashtable();
       
   120         }
       
   121         ResourceLoader rl = (ResourceLoader)iResourceLoaderTable.get(key);
       
   122         if (rl == null)
       
   123         {
       
   124             rl = ResourceLoader.getInstance(textFilename, textPrefix);
       
   125             iResourceLoaderTable.put(key, rl);
       
   126         }
       
   127         return rl;
       
   128     }
       
   129 
       
   130     /**
       
   131      * Gets the Qt locale ID currently being used on the phone.
       
   132      *
       
   133      * @return Qt locale ID as provided by the platform
       
   134      */
       
   135     protected static String getLocaleIdQt()
       
   136     {
       
   137         // Change this after Qt localisation files are taken into use.
       
   138         //return ResourceLoader.getLocaleIdQt();
       
   139         return null;
       
   140     }
       
   141 
    72 
   142     /*** ----------------------------- PACKAGE ---------------------------- */
    73     /*** ----------------------------- PACKAGE ---------------------------- */
   143     /*** ----------------------------- PRIVATE ---------------------------- */
    74     /*** ----------------------------- PRIVATE ---------------------------- */
   144     /*** ----------------------------- NATIVE ----------------------------- */
    75     /*** ----------------------------- NATIVE ----------------------------- */
   145 }
    76 }