View Javadoc

1   /********************************************************************************
2    *InternetCafe is a software solution that helps the management of Cybercafes 
3    * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4    * Copyright (C) 2006  Guido Angelo Ingenito
5   
6    * This program is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU General Public License
8    * as published by the Free Software Foundation; either version 2
9    * of the License, or (at your option) any later version.
10  
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19   *******************************************************************************/
20  package base.jdbs;
21  
22  import java.awt.BorderLayout;
23  import java.io.File;
24  
25  import org.apache.log4j.Logger;
26  import org.apache.log4j.xml.DOMConfigurator;
27  
28  import ui.dialog.UserDialog;
29  import ui.util.GeneralUtil;
30  import base.InternetCafe;
31  import base.jdbs.ui.JDBSMainFrame;
32  import base.jdbs.ui.JDBSMenuBar;
33  import base.jdbs.ui.dialog.RepositorySetupDialog;
34  import base.user.User;
35  import base.user.UserFactory;
36  
37  public class JDBS {
38  
39  	private static final transient Logger logger = Logger.getLogger(JDBS.class
40  			.getName());
41  
42  	/***
43  	 * @param args
44  	 */
45  	public static void main(String[] args) {
46  
47  		initJDBS();
48  
49  		JDBSMainFrame mainFrame = new JDBSMainFrame();
50  		mainFrame.setSize(1024, 768);
51  		mainFrame.setJMenuBar(new JDBSMenuBar());
52  		mainFrame.add(InternetCafe.getStatusBar(), BorderLayout.SOUTH);
53  		GeneralUtil.centerComponent(mainFrame);
54  		mainFrame.setVisible(true);
55  		// NetworkManager.getInstance();
56  	}
57  
58  	protected static void initJDBS() {
59  		// This call enables the log4j logs for JDBS.
60  		DOMConfigurator.configure("log4jConfiguration.xml");
61  		try {
62  			// First of all we must load the JDBS configurations.
63  			File configurationFile = new File(
64  					JDBSConstant.JDBS_CONFIGURATION_FILE);
65  
66  			if (configurationFile.exists()) { // Read It!
67  				logger.info("Configuration file : " + configurationFile
68  						+ " found. Loading configurations from it...");
69  				ConfigurationManager.loadConfiguration();
70  			} else {
71  				logger.info("Setting up the JDBS's user...");
72  				User user = UserFactory.newUser();
73  				UserDialog dialog = new UserDialog(user);
74  				dialog.setModal(true);
75  				dialog.setTitle("New User");
76  				dialog.setVisible(true);
77  				ConfigurationManager.getInstance().setUser(dialog.getUser());
78  				logger.info(dialog.getUser());
79  
80  				logger.info("Setting up the JDBS's repository...");
81  				RepositorySetupDialog repositorySetupDialog = new RepositorySetupDialog();
82  				repositorySetupDialog.setModal(true);
83  				GeneralUtil.centerComponent(repositorySetupDialog);
84  				repositorySetupDialog.setVisible(true);
85  
86  				ConfigurationManager.saveConfiguration();
87  			}
88  		} catch (Exception e) {
89  			logger.error(e.getMessage());
90  			e.printStackTrace();
91  		}
92  
93  		if (ConfigurationManager.getInstance().getRepository().getLocation()
94  				.exists()) {
95  			logger.info("Indexing the JDBS's repository...");
96  			ConfigurationManager.getInstance().getRepository()
97  					.indexRepository();
98  		}
99  	}
100 }