upload tizen2.0 alpha installmanager source
[sdk/installer/install-manager.git] / InstallManager_java / src / org / tizen / installmanager / lib / ErrorController.java
1 /*
2 *  InstallManager
3 *
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact:
7 * Wooyoung Cho <wooyoung1.cho@samsung.com>
8 * Shihyun Kim <shihyun.kim@samsung.com>
9 * Taeyoung Son <taeyoung2.son@samsung.com>
10 * Yongsung kim <yongsung1.kim@samsung.com>
11 *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 * Contributors:
25 * - S-Core Co., Ltd
26 *
27 */
28
29 package org.tizen.installmanager.lib;
30
31 import org.tizen.installmanager.core.Config;
32
33 /**
34  * This class manages error codes and states
35  *
36  * @author Shihyun Kim <shihyun.kim@samsung.com>
37  */
38 public class ErrorController {
39         /**
40          * Define case of error
41          *
42          * @author Shihyun Kim <shihyun.kim@samsung.com>
43          *
44          */
45         public enum ErrorCode {
46                 CANNOT_FIND_CONFIG_FILE("The installmanager.conf file not found."),
47                 CANNOT_FIND_FILE_IN_REPOSITROY("Cannot connect to SDK package server."),
48                 CANNOT_CREATE_DOWNLOAD_FILE("Download file cannot be created."),
49                 CANNOT_CHECK_INSTLLED_FILE_LIST("Installed file list cannot be checked."),
50                 CANNOT_MOVE_FILE_TO_TARGET_DIRECTORY("File cannot be moved to the target directory."),
51                 CANNOT_CONNECT_TO_PROXY_SERVER("Proxy server connection fails."),
52                 WRONG_PACKAGE_URL("Package URLs are invalid."),
53                 CANCEL("Download canceled."),
54                 ERROR("Unknown error."),
55                 UNKNOWN_PACKAGE_EXTENSION("Package extension not supported."),
56                 INVALID_PACKAGE_VERSION("Invalid package version."),
57                 CANNOT_FIND_INSTALLABLE_OR_REMOVABLE_PACKAGES("Install or uninstall packages not found. Network connection may have failed."),
58                 CANNOT_FIND_FILE_IN_LOCAL("Local file not found."),
59                 CANNOT_SAVE_CONFIG("Configuration file cannot be saved."),
60                 CANNOT_CREATE_SHORTCUT("Shortcut creation failed."),
61                 CANNOT_CREATE_INSTALL_LIST("Install list creation failed."),
62                 CANNOT_CREATE_CONFIG_FILE("Configuration directory or file creation failed."),
63                 CANNOT_FIND_USER_CONFIG_FILE("User configuration file creation failed."),
64                 CANNOT_REGISTER_TARGET_DIR("Target directory registration failed."),
65                 CANNOT_PARSING_TEXT("Configuration file parsing failed."),
66                 CANNOT_SAVE_PROPERTY_FILE("The installmanager.conf or Package file cannot be saved."),
67                 CANNOT_UNPACK_PACKAGE("The package.zip file unpackaging failed."),
68                 CANNOT_CREATE_RESOURCE("Resource file creation failed."),
69                 CANNOT_FIND_PACKAGE("Required packages not found. The package server may be invalid."),
70                 CANNOT_REMOVE_PACKAGE("Package removal failed."),
71                 CANNOT_REMOVE_MISSING_PACKAGE("Missing package cannot be removed."),
72                 CANNOT_ACCESS_FILE("File access failed."),
73                 CANNOT_REMOVE_OLDSDK("Old SDK removal failed."),
74                 COPY_FILE_IS_FAIL("Copying the file to the target directory failed."),
75                 OLD_TIZEN_SDK_EXISTS("Old Tizen SDK is installed. Remove the old SDK and run the Tizen SDK Install Manager again."),
76                 UNSUPPORTED_PLATFORM("Platform not supported."),
77                 REMOVE_SCRIPT_NOT_EXISTS("Removal script not found."),
78                 REMOVE_SCRIPT_FATAL_ERROR("Fatal error occurred while uninstalling the Tizen SDK."),
79                 INSTALLATION_FAIL("Installation failed."),
80                 INSTALL_CANCELED("Installation canceled."),
81                 INSTALLED_VERSION_IS_HIGH("Installation progress failed due to high installed package version."),
82                 CANNOT_CREATE_FILE("File creation failed."),
83                 THREAD_INTERRUPTED("Thread execution interrupted."),
84                 CIRCULAR_PACKAGE_DEPENDENCY("Circular package dependency detected."),
85                 
86                 //Configuration file error
87                 CONFIG_CANNOT_PARSING_PACKAGE_LIST("Package list cannot be read. Check the repository or proxy server."),
88                 CONFIG_CANNOT_FIND_PACKAGE_LIST_FILE_IN_REPOSITORY("Package list file not found in the repository."),
89                 CONFIG_CANNOT_REMOVE_CONFLICT_PACKAGES("Conflict package removal failed."),
90                 CONFIG_CANNOT_REMOVE_UPDATABLE_PACKAGES("Updatable package removal failed."),
91                 CONFIG_CANNOT_READ_SERVER_TYPE("Server type cannot be read. Check the server type in the installmanager.conf file."),
92                 
93                 //Package error
94                 PACKAGE_WRONG_SIZE("Package size incorrect."),
95                 PACKAGE_WRONG_CHECKSUM("Package file checksum error."),
96                 PACKAGE_NOT_EXIST_TO_INSTALL_OR_UNINSTALL("Install or uninstall package not found."),
97                 INSTALL_SCRIPT_NOT_EXISTS("Install script files not found."),
98                 INSTALL_SCRIPT_FATAL_ERROR("Fatal error occurred while installing the Tizen SDK."),
99                 
100                 // Network error
101                 INTERNET_CONNECTION_ERROR("Server connection failed. Check the network status or try again with the '-proxy <address>:<port>'."),
102                 SERVER_CONNECTION_TIME_OUT("Server connection timed out."),
103                 PROXY_NOT_PROVIDED("Proxy setting missing. Use the '-proxy <proxy-address>:<port>' option."),
104                 PROXY_SERVER_IS_WRONG("Proxy server connection failed. Check the proxy server."),
105                 PROXY_CONNECT_ERROR("Proxy server connection failed. Check the proxy server."),
106                 URL_SECURITY_EXCEPTION("Proxy server URL security error."),
107                 URL_ADDRESS_IS_WRONG("Incorrect URL."),
108                 URL_PORT_IS_WRONG("Incorrect port number."),
109                 NO_ROUTE_TO_HOST("Server not found. Check the URL."),
110                 NOT_LOGGED_IN("Login failed."),
111                 NOT_SUPPORT_HTTPS_PROTOCOL("HTTPS not supported."),
112                 
113                 //Http Socket error message
114                 HTTP_ERROR_MESSAGE_403("403 Forbidden is returned by http protocol. " +
115                                 "The server can be reached, but the server declined to allow access to the page."),
116                 HTTP_ERROR_MESSAGE_401("Server requires authentication."),
117                 
118                 //option
119                 WRONG_OPTION("Incorrect option. Check it."),
120                 USESNAPSHOT_REPOSITORY_NOT_PROVIDED("Repository setting is missing. Use the '-snapShot <repository>' option."),
121                 REPOSITORY_NOT_PROVIDED("Repository setting is missing. Use the '-repository <repository>' option."),
122                 PACKAGES_NOT_PROVIDED("Repository setting is missing. Use the '-proxy <repository>' option."),
123                 
124                 //etc
125                 CANNOT_FIND_INSTALLED_FILE_LIST("Installation file list not found."),
126                 CANNOT_REMOVE_TARGET_DIR("Target directory removal failed."),
127                 INSTALLATION_STOP("Required packages for the META package not installed."),
128                 UNINSTALLATION_FAIL("Uninstallation failed."),
129                 FILE_NOT_FOUND("File not found."),
130                 REMOVE_OLD_SDK_OK("Old SDK uninstallation completed. Restart Install Manager."),
131                 INVALID_INSTALL_PATH("Invalid installation path."),
132                 DOWNLOAD_AND_EXIT("Packages downloaded successfully. Exit Install Manager."),
133                 CANNOT_DOWNLOAD_FILE("File download failed."),
134                 CANNOT_FIND_JAVA("\'JAVA\' not found. Check the java installation."),
135                 UNKOWN_ERROR("Unknown error."),
136                 NO_ERROR("Install Manager error. Send the log file to the Tizen SDK team."),
137                 ERROR_TEMP("Information retrieval from the default SDK package server failed.\n In Advanced Configuration, select the package server and distribution."),
138                 
139                 SNAPSHOT_PATH_IS_NULL("Snapshot path missing."),
140                 FAIL_TO_EXTRACT_SDK_IMAGE_FILE("SDK image file extraction failed."),
141                 
142                 //Using add extra repository dialog
143                 SPACE_IN_REPOSITORY_NAME("Name cannot contain spaces."),
144                 NOTHING_TO_REPOSITORY_NAME("Name must be more than 1 character long."),
145                 HANGUL_IN_REPOSITORY_NAME("Repository name must be in English."),
146                 WRONG_PACKAGE_SERVER("Package list files not found. Check the package list files on the package server."),
147                 WRONG_PACKAGE_LIST_FORMAT("Mandatory field missing in the package list file."),
148                 WRONG_URL_FORMAT_HTTP("URL must begin with 'http://'."),
149                 WRONG_URL_FORMAT("Incorrect URL format. Enter the URL in the correct format."),
150                 CANNOT_CONNECT_URL_ADDRESS("Connection to the URL failed. Enter the correct URL."),
151                 PACKAGE_NOT_IN_EXTENSION_SERVER("Package file not found on the package server."),
152                 OVERLAP_EXTENSION_REPOSITORY("Extension repository URL already exists.\nEnter a different extension repository URL."),
153                 OVERLAP_BUILT_IN_EXTENSION_REPOSITORY("Built-in extension repository URL already exists.\nEnter a different extension repository URL.");
154                 
155                 private String errorMessage = "";
156
157                 ErrorCode(String arg) {
158                         errorMessage = arg;
159                 }
160
161                 public String getErrorMessage() {
162                         return errorMessage;
163                 }
164                 
165                 public void setErrorMessage(String msg) {
166                         errorMessage = msg;
167                 }
168         }
169         
170         static public boolean isInstallManagerUpdatable = false;
171
172
173         static private ErrorCode mErrorCode = ErrorCode.NO_ERROR;
174         static private boolean mInstallationStatus = true;
175         static private String errorMsg = "";
176
177         private static int exitCode = Config.EXITCODE_NORMAL;
178
179         /**
180          * Set error code.
181          * @param errorCode
182          */
183         static public void setError(ErrorCode errorCode) {
184                 mErrorCode = errorCode;
185         }
186
187         /**
188          * 
189          * @return Latest error message.
190          */
191         static public String getErrorMessage() {
192                 if (mErrorCode != null) {                       
193                         return mErrorCode.getErrorMessage();
194                 } else {
195                         return errorMsg;
196                 }
197         }
198         
199         static public void setErrorMessage(String msg) {
200                 mErrorCode = null; 
201                 errorMsg = msg;
202         }
203
204         /** 
205          * @return Latest error code.
206          */
207         static public ErrorCode getErrorCode() {
208                 return mErrorCode;
209         }
210
211         /**
212          * Set status of installation.
213          * @param status
214          */
215         static public void setInstallationSuccess(boolean status) {
216                 Log.log("Set installation success: "+status);
217                 if (status == true) {
218                         mErrorCode = null;
219                 }
220                 mInstallationStatus = status;
221         }
222
223         /**
224          * Get status of installation.
225          * @return
226          */
227         static public boolean checkInstallationSuccess() {
228                 return mInstallationStatus;
229         }
230
231         /**
232          * Get error message of e
233          * @param e
234          * @return
235          */
236         public static String getMessage(ErrorCode e) {
237                 return e.getErrorMessage();
238         }
239
240         /**
241          * Sets exit code to be used on exit
242          * @param exitCode
243          */
244         public static void setExitCode(int exitCode) {
245                 ErrorController.exitCode = exitCode;
246         }
247
248         /**
249          * Gets exit code to be used on exit
250          */
251         public static int getExitCode() {
252                 return ErrorController.exitCode;
253         }
254 }