1 /* |
1 /* |
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2008-2010 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 |
|
29 * @see InstallerExceptionBase |
27 * @see InstallerExceptionBase |
30 */ |
28 */ |
31 abstract public class ErrorMessageBase |
29 abstract public class ErrorMessageBase |
32 { |
30 { |
33 /*** ----------------------------- PUBLIC ------------------------------ */ |
31 /*** ----------------------------- PUBLIC ------------------------------ */ |
34 |
32 |
35 public static final int NO_MSG = 0; // Used when the error message is not available. |
33 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; |
36 |
47 |
37 /** |
48 /** |
38 * Method for retrieving the message of a certain error. |
49 * Method for retrieving the message of a certain error. |
39 * |
50 * |
40 * @param errorCode The error code whose message is queried |
51 * @param errorCode The error code whose message is queried |
49 String msgId = ((String)messageTable.get(new Integer(errorCode))); |
60 String msgId = ((String)messageTable.get(new Integer(errorCode))); |
50 if (msgId == null) |
61 if (msgId == null) |
51 { |
62 { |
52 return this.getClass().getName() + ": No message found for error " + errorCode; |
63 return this.getClass().getName() + ": No message found for error " + errorCode; |
53 } |
64 } |
54 return getResourceLoader().format(msgId, errorMessageParameters); |
65 ResourceLoader rl = getResourceLoader(); |
|
66 if (rl == null) |
|
67 { |
|
68 rl = getResourceLoader(errorCode); |
|
69 } |
|
70 return rl.format(msgId, errorMessageParameters); |
55 } |
71 } |
56 |
72 |
57 /*** ---------------------------- PROTECTED --------------------------- */ |
73 /*** ---------------------------- PROTECTED --------------------------- */ |
58 |
74 |
59 /** |
75 /** |
63 */ |
79 */ |
64 abstract protected Hashtable getMessageTable(); |
80 abstract protected Hashtable getMessageTable(); |
65 |
81 |
66 /** |
82 /** |
67 * Method for retrieving the ResourceLoader instance that is used |
83 * Method for retrieving the ResourceLoader instance that is used |
68 * to localise error messages. |
84 * to localise error messages. If this method returns null, |
|
85 * the ResourceLoader is obtained with getResourceLoader(int) |
|
86 * method variant which then must not return null. |
|
87 * |
69 * This method must be overriden in inheriting class. |
88 * This method must be overriden in inheriting class. |
70 */ |
89 */ |
71 abstract protected ResourceLoader getResourceLoader(); |
90 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 } |
72 |
141 |
73 /*** ----------------------------- PACKAGE ---------------------------- */ |
142 /*** ----------------------------- PACKAGE ---------------------------- */ |
74 /*** ----------------------------- PRIVATE ---------------------------- */ |
143 /*** ----------------------------- PRIVATE ---------------------------- */ |
75 /*** ----------------------------- NATIVE ----------------------------- */ |
144 /*** ----------------------------- NATIVE ----------------------------- */ |
76 } |
145 } |