Revision 33720 branches/v2_0_0_prep/frameworks/_fwAndami/src/org/gvsig/andami/Launcher.java

View differences:

Launcher.java
132 132
import org.gvsig.andami.ui.splash.MultiSplashWindow;
133 133
import org.gvsig.andami.ui.theme.Theme;
134 134
import org.gvsig.andami.ui.wizard.UnsavedDataPanel;
135
import org.gvsig.tools.exception.ListBaseException;
135 136
import org.gvsig.tools.library.LibrariesInitializer;
136 137
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
137 138
import org.gvsig.utils.DateTime;
......
183 184
    // it seems castor uses this encoding
184 185
	protected static final String CASTORENCODING = "UTF8";
185 186
    
187
	protected static ListBaseException launcherrors = null;
188
	
186 189
	private static final class ProxyAuth extends Authenticator {
187 190
		private PasswordAuthentication auth;
188 191

  
......
197 200

  
198 201
    public static void main(String[] args) throws Exception {
199 202
    	Launcher launcher = new Launcher();
200
    	doMain(args,launcher);
203
    	launcher.doMain(args);
201 204
    }
202 205
  
203 206
	protected void downloadExtensions(String extDir) {
204 207
		// do nothing
205 208
	}
206 209

  
210
	public static class LaunchException extends ListBaseException{
211

  
212
		/**
213
		 * 
214
		 */
215
		private static final long serialVersionUID = 4541192746962684705L;
216

  
217
		public LaunchException() {
218
			super(
219
				"Errors in initialization of application.", 
220
				"_errors_in_initialization_of_application", 
221
				serialVersionUID
222
			);
223
		}
207 224
		
208
    public static void doMain(String[] args, Launcher launcher) throws Exception {
225
	}
226
	
227
	protected void addError(Throwable ex) {
228
		if( launcherrors == null ) {
229
			launcherrors = new LaunchException();
230
		}
231
		launcherrors.add(ex);
232
	}
233
	
234
	protected void addError(String msg, Throwable cause) {
235
		logger.error(msg,cause);
236
		this.addError(new RuntimeException(msg,cause));
237
	}
238
	
239
	protected void addError(String msg) {
240
		this.addError(msg, null);
241
	}
242
	
243
    public void doMain(String[] args) throws Exception {
209 244
    	try{
210 245

  
211 246
    		if (!validJVM()){
......
285 320
    			refresh() {}
286 321
    		});
287 322

  
288
    		initIconThemes();
323
    		try {
324
    			initIconThemes();
325
    		} catch(Exception ex) {
326
    			this.addError("Can't initialize icon theme",ex);
327
    		}
289 328
//    		Registramos los iconos base
290
    		registerIcons();
329
    		try {
330
    			registerIcons();
331
    		} catch(Exception ex) {
332
    			this.addError("Can't register icons",ex);
333
    		}
291 334
    		validate();
292 335

  
293 336
    		// Obtener la personalizaci?n de la aplicaci?n.
294
    		Theme theme=getTheme(andamiConfig.getPluginsDirectory());
337
    		Theme theme = null;
338
    		try {
339
    			theme=getTheme(andamiConfig.getPluginsDirectory());
340
    		} catch(Exception ex) {
341
    			this.addError("Can't get personalized theme for the application",ex);
342
    		}
295 343

  
296 344
    		// Mostrar la ventana de inicio
297 345
    		Frame f=new Frame();
......
305 353
    		// 2. TODO Buscar actualizaciones de los plugins
306 354
    		splashWindow.process(20,
307 355
    				PluginServices.getText(Launcher.class, "SplashWindow.looking_for_updates"));
308
    		launcher.downloadExtensions(andamiConfig.getPluginsDirectory());
356
    		try {
357
    			this.downloadExtensions(andamiConfig.getPluginsDirectory());
358
    		} catch(Exception ex) {
359
    			this.addError("Can't downloads plugins",ex);
360
    		}
309 361

  
310 362
    		// 3. Se leen los config.xml de los plugins -----++++
311 363
    		splashWindow.process(30,
312 364
    				PluginServices.getText(Launcher.class, "SplashWindow.reading_plugins_config.xml"));
313
    		loadPlugins(andamiConfig.getPluginsDirectory());
365
    		try {
366
    			this.loadPlugins(andamiConfig.getPluginsDirectory());
367
    		} catch(Exception ex) {
368
    			this.addError("Can't load plugins",ex);
369
    		}
314 370

  
315 371
    		// 4. Se configura el classloader del plugin
316 372
    		splashWindow.process(40,
317 373
    				PluginServices.getText(Launcher.class, "SplashWindow.setting_up_class_loaders"));
318
    		pluginsClassLoaders();
374
    		try {
375
    			this.pluginsClassLoaders();
376
    		} catch(Exception ex) {
377
    			this.addError("Can't initialize plugin's classloaders  ",ex);
378
    		}
319 379

  
320 380
    		// 5. Se carga un Skin si alguno de los plugins trae informaci?n para ello
321 381
    		splashWindow.process(50,
......
452 512
    			}
453 513
    		});
454 514
    		splashWindow.close();
515
    		if( launcherrors!=null ) {
516
    			NotificationManager.addError(launcherrors);
517
    		}
455 518
    	}catch(Exception e){
456 519
    		logger.error("excepci?n al arrancar", e);
457 520
    		System.exit(-1);
......
466 529
    	return new File("").getAbsolutePath();
467 530
    }
468 531

  
469
    private static void registerIcons(){
532
    private void registerIcons(){
470 533
    	PluginServices.getIconTheme().registerDefault(
471 534
    			"login-gvsig",
472 535
    			LoginUI.class.getClassLoader().getResource("images/login_gvsig.png")
......
499 562
     *
500 563
     * @return Theme
501 564
     */
502
    private static Theme getTheme(String pluginsDirectory) {
565
    private Theme getTheme(String pluginsDirectory) {
503 566
    	File themeFile;
504 567
    	Theme theme = new Theme();
505 568

  
......
557 620
     *Establece los datos que ten?amos guardados respecto de la configuraci?n
558 621
     *del proxy.
559 622
     */
560
	private static void configureProxy() {
623
	private void configureProxy() {
561 624
		String host = prefs.get("firewall.http.host", "");
562 625
		String port = prefs.get("firewall.http.port", "");
563 626

  
......
584 647
	 * TODO Pendiente de ver como se asigna un pluginServices para el launcher.
585 648
	 * @author LWS
586 649
	 */
587
	private static void restoreMDIStatus(XMLEntity xml) {
650
	private void restoreMDIStatus(XMLEntity xml) {
588 651
		if (xml == null) xml = new XMLEntity();
589 652
		//  restore frame size
590 653
		Dimension sz = new Dimension(700,580);
......
609 672
		frame.setExtendedState(state);
610 673
	}
611 674

  
612
	private static XMLEntity saveMDIStatus() {
675
	private XMLEntity saveMDIStatus() {
613 676
		XMLEntity xml = new XMLEntity();
614 677
		// save frame size
615 678
		int [] wh = new int[2];
......
626 689
		return xml;
627 690
	}
628 691

  
629
    private static boolean validJVM() {
692
    private boolean validJVM() {
630 693
        char thirdCharacter = System.getProperty("java.version").charAt(2);
631 694
        if (thirdCharacter < '4'){
632 695
            return false;
......
635 698
	    }
636 699
    }
637 700

  
638
	private static void loadPluginsPersistence() throws ConfigurationException {
701
	private void loadPluginsPersistence() throws ConfigurationException {
639 702
		XMLEntity entity = persistenceFromXML();
640 703

  
641 704
		for (int i = 0; i < entity.getChildrenCount(); i++) {
......
655 718
	 * Salva la persistencia de los plugins.
656 719
	 * @author LWS
657 720
	 */
658
	private static void savePluginPersistence() {
721
	private void savePluginPersistence() {
659 722
		Iterator i = pluginsConfig.keySet().iterator();
660 723

  
661 724
		XMLEntity entity = new XMLEntity();
......
678 741
		try {
679 742
			persistenceToXML(entity);
680 743
		} catch (ConfigurationException e1) {
681
			logger.error(Messages.getString(
744
			this.addError(Messages.getString(
682 745
					"Launcher.Se_produjo_un_error_guardando_la_configuracion_de_los_plugins"),
683 746
				e1);
684 747
		}
685 748
	}
686 749

  
687
	private static void installPluginsLabels() {
750
	private void installPluginsLabels() {
688 751
		Iterator i = pluginsConfig.keySet().iterator();
689 752

  
690 753
		while (i.hasNext()) {
......
701 764
					Class clase = loader.loadClass(ls[j].getClassName());
702 765
					frame.setStatusBarLabels(clase, ls[j].getLabel());
703 766
				} catch (ClassNotFoundException e) {
704
					logger.error(Messages.getString("Launcher.labelset_class"),
767
					this.addError(Messages.getString("Launcher.labelset_class"),
705 768
						e);
706 769
				}
707 770
			}
708 771
		}
709 772
	}
710 773

  
711
	private static String configureSkin(XMLEntity xml,String defaultSkin) {
774
	private String configureSkin(XMLEntity xml,String defaultSkin) {
712 775
		if (defaultSkin == null){
713 776
			for (int i = 0; i < xml.getChildrenCount(); i++) {
714 777
				if (xml.getChild(i).contains("Skin-Selected")) {
......
722 785
		return  defaultSkin;
723 786
	}
724 787

  
725
	private static void fixSkin(SkinExtension skinExtension,PluginClassLoader pluginClassLoader) throws MDIManagerLoadException{
788
	private void fixSkin(SkinExtension skinExtension,PluginClassLoader pluginClassLoader) throws MDIManagerLoadException{
726 789
		// now insert the skin selected.
727 790
		MDIManagerFactory.setSkinExtension(skinExtension, pluginClassLoader);
728 791
		// MDIManagerFactory.setSkinExtension(se,
......
770 833
	 *
771 834
	 * @throws MDIManagerLoadException
772 835
	 */
773
	private static void skinPlugin(String defaultSkin) throws MDIManagerLoadException {
836
	private void skinPlugin(String defaultSkin) throws MDIManagerLoadException {
774 837
		XMLEntity entity =null;
775 838
		try {
776 839
			entity = persistenceFromXML();
......
799 862
					skinExtensions.add(se[numExten]);
800 863
				}
801 864
				for (int j=0;j<se.length;j++){
802
					String configuredSkin = Launcher.configureSkin(entity,defaultSkin);
865
					String configuredSkin = this.configureSkin(entity,defaultSkin);
803 866
					if (configuredSkin!=null && configuredSkin.equals(se[j].getClassName())) {
804 867
						skinExtension = se[j];
805 868
						pluginClassLoader = ps.getClassLoader();
......
857 920
		}
858 921
	}
859 922

  
860
	private static void initializeExtensions() {
923
	private void initializeExtensions() {
861 924
		
862 925
		libInitializers = new ArrayList<LibrariesInitializer>(pluginsOrdered
863 926
				.size());
......
927 990
                    // logger.debug(extension.getClassName() + " initialized.");
928 991

  
929 992
                } catch (Exception e1) {
930
                    logger.error("Can't initialize extension '"+extension.getClassName()+"'.",e1);
993
                	this.addError("Can't initialize extension '"+extension.getClassName()+"'.",e1);
931 994
				} catch (NoClassDefFoundError e1) {
932
					logger.error("Can't found class extension ("+extension.getClassName()+")",e1);
995
					this.addError("Can't found class extension ("+extension.getClassName()+")",e1);
933 996
				}
934 997
			}
935 998
		}
936 999
	}
937 1000

  
938
	private static void postInitializeExtensions() {
1001
	private void postInitializeExtensions() {
939 1002
		// Post initialize all plugin libraries
940 1003
		for (int i = 0; i < libInitializers.size(); i++) {
941 1004
			libInitializers.get(i).postInitialize(true);
......
954 1017
			try {
955 1018
				extensionInstance.postInitialize();
956 1019
			} catch(Exception ex) {
957
				logger.error("postInitialize of extension '"+extensionInstance.getClass().getName()+"' failed",ex);
1020
				this.addError("postInitialize of extension '"+extensionInstance.getClass().getName()+"' failed",ex);
958 1021
			}
959 1022
		}
960 1023
	}
961 1024

  
962
	private static void installPluginsMenus() {
1025
	private void installPluginsMenus() {
963 1026
		TreeMap orderedMenus = new TreeMap(new MenuComparator());
964 1027

  
965 1028
		Iterator i = pluginsConfig.keySet().iterator();
......
983 1046
							exts[j], menus[k]);
984 1047

  
985 1048
					if (orderedMenus.containsKey(sm)) {
986
						logger.error(Messages.getString(
1049
						this.addError(Messages.getString(
987 1050
								"Launcher.Two_menus_with_the_same_position") + " - " +
988 1051
							menus[k].getText()+ " - " + exts[j].getClassName());
989 1052
					}
......
1005 1068
							skinExts[j], menu[k]);
1006 1069

  
1007 1070
					if (orderedMenus.containsKey(sm)) {
1008
						logger.error(Messages.getString(
1071
						this.addError(Messages.getString(
1009 1072
								"Launcher.Two_menus_with_the_same_position") +
1010 1073
							skinExts[j].getClassName());
1011 1074
					}
......
1026 1089

  
1027 1090
				frame.addMenu(sm.loader, sm.extension, sm.menu);
1028 1091
			} catch (ClassNotFoundException ex) {
1029
				logger.error(Messages.getString(
1092
				this.addError(Messages.getString(
1030 1093
						"Launcher.No_se_encontro_la_clase_de_la_extension"), ex);
1031 1094
			}
1032 1095
		}
......
1036 1099
	 * Installs the menus, toolbars, actiontools, selectable toolbars and combos.
1037 1100
	 * The order in which they are shown is determined here.
1038 1101
	 */
1039
	private static void installPluginsControls() {
1102
	private void installPluginsControls() {
1040 1103
		Iterator i = pluginsConfig.keySet().iterator();
1041 1104

  
1042 1105
		HashMap extensionPluginServices = new HashMap();
......
1056 1119
			for (int j = 0; j < exts.length; j++) { // iterate on the extensions
1057 1120
				if (exts[j].getActive()) {
1058 1121
					if (orderedExtensions.containsKey(exts[j])) {
1059
						logger.error(Messages.getString(
1122
						this.addError(Messages.getString(
1060 1123
						"Launcher.Two_extensions_with_the_same_priority") +
1061 1124
						exts[j].getClassName());
1062 1125
					}
......
1118 1181
						elements[currentElem] = Long.parseLong(elementsString[currentElem]);
1119 1182
					}
1120 1183
					catch (NumberFormatException nfex1) {
1121
						logger.error(ext.getClassName()+" -- "+Messages.getString( "error_parsing_comboscale_elements"));
1184
						this.addError(ext.getClassName()+" -- "+Messages.getString( "error_parsing_comboscale_elements"));
1122 1185
						elements[currentElem] = 0;
1123 1186
					}
1124 1187
				}
......
1128 1191
					combo.setScale(value);
1129 1192
				}
1130 1193
				catch (NumberFormatException nfex2) {
1131
					logger.error(ext.getClassName()+" -- "+Messages.getString( "error_parsing_comboscale_value"));
1194
					this.addError(ext.getClassName()+" -- "+Messages.getString( "error_parsing_comboscale_value"));
1132 1195
				}
1133 1196
				try {
1134 1197
					frame.addStatusBarControl(loader.loadClass(ext.getClassName()),combo);
1135 1198
				} catch (ClassNotFoundException e1) {
1136
					logger.error(Messages.getString("Launcher.error_getting_class_loader_for_status_bar_control"), e1);
1199
					this.addError(Messages.getString("Launcher.error_getting_class_loader_for_status_bar_control"), e1);
1137 1200
				}
1138 1201
			}
1139 1202

  
......
1149 1212
					ImageIcon icon;
1150 1213
					URL iconLocation = loader.getResource(element.getIcon());
1151 1214
					if (iconLocation==null)
1152
						logger.error(Messages.getString("Icon_not_found_")+element.getIcon());
1215
						this.addError(Messages.getString("Icon_not_found_")+element.getIcon());
1153 1216
					else {
1154 1217
						icon = new ImageIcon(iconLocation);
1155 1218
						JButton button = new JButton(icon);
......
1160 1223
				try {
1161 1224
					frame.addStatusBarControl(loader.loadClass(ext.getClassName()), combo);
1162 1225
				} catch (ClassNotFoundException e1) {
1163
					logger.error(Messages.getString("Launcher.error_getting_class_loader_for_status_bar_control"), e1);
1226
					this.addError(Messages.getString("Launcher.error_getting_class_loader_for_status_bar_control"), e1);
1164 1227
				}
1165 1228
			}
1166 1229
		}
......
1220 1283
				else
1221 1284
					frame.addTool(stb.loader, stb.extension,stb.toolbar, stb.selectabletool);
1222 1285
			} catch (ClassNotFoundException ex) {
1223
				logger.error(Messages.getString(
1286
				this.addError(Messages.getString(
1224 1287
				"Launcher.No_se_encontro_la_clase_de_la_extension"), ex);
1225 1288
			}
1226 1289
		}
......
1229 1292
	/**
1230 1293
	 * Adds new plugins to the the andami-config file.
1231 1294
	 */
1232
	private static void updateAndamiConfig() {
1295
	private void updateAndamiConfig() {
1233 1296
		HashSet olds = new HashSet();
1234 1297

  
1235 1298
		Plugin[] plugins = andamiConfig.getPlugin();
......
1253 1316
		}
1254 1317
	}
1255 1318

  
1256
	private static void pluginsClassLoaders() {
1319
	private void pluginsClassLoaders() {
1257 1320
		HashSet instalados = new HashSet();
1258 1321

  
1259 1322
		// Se itera hasta que est?n todos instalados
......
1278 1341

  
1279 1342
				for (int j = 0; j < dependencies.length; j++) {
1280 1343
					if (pluginsConfig.get(dependencies[j].getPluginName()) == null) {
1281
						logger.error(Messages.getString(
1344
						this.addError(Messages.getString(
1282 1345
								"Launcher.Dependencia_no_resuelta_en_plugin") +
1283 1346
							" " +pluginName + ": " +
1284 1347
							dependencies[j].getPluginName());
......
1316 1379
					try {
1317 1380
						urls[j] = new URL("file:" + jarFiles[j]);
1318 1381
					} catch (MalformedURLException e) {
1319
						logger.error(Messages.getString(
1382
						this.addError(Messages.getString(
1320 1383
								"Launcher.No_se_puede_acceder_a") +" " +
1321 1384
							jarFiles[j]);
1322 1385
					}
......
1341 1404

  
1342 1405
					circle = false;
1343 1406
				} catch (IOException e) {
1344
					logger.error(Messages.getString(
1407
					this.addError(Messages.getString(
1345 1408
							"Launcher.Error_con_las_librerias_del_plugin"), e);
1346 1409
					pluginsConfig.remove(pluginName);
1347 1410
					i = pluginsConfig.keySet().iterator();
......
1349 1412
			}
1350 1413

  
1351 1414
			if (circle) {
1352
				logger.error(Messages.getString(
1415
				this.addError(Messages.getString(
1353 1416
						"Launcher.Hay_dependencias_circulares"));
1354 1417

  
1355 1418
				break;
......
1371 1434
		}
1372 1435
	}
1373 1436

  
1374
	private static void pluginsMessages() {
1437
	private void pluginsMessages() {
1375 1438
		Iterator iterator = pluginsOrdered.iterator();
1376 1439
		PluginConfig config;
1377 1440
		PluginServices ps;
......
1404 1467
		return frame;
1405 1468
	}
1406 1469

  
1407
	private static void loadPlugins(String pluginsDirectory) {
1470
	private void loadPlugins(String pluginsDirectory) {
1408 1471
		File pDir = new File(pluginsDirectory);
1409 1472

  
1410 1473
		if (!pDir.exists()) {
......
1441 1504
				} catch (FileNotFoundException e) {
1442 1505
					logger.info("Plugin folder without config.xml. Skip plugin '"+pluginDirs[i].getAbsolutePath() +"'.");
1443 1506
				} catch (MarshalException e) {
1444
					logger.error("Can't load plugin '"+pluginDirs[i].getAbsolutePath() +"'." ,
1507
					this.addError("Can't load plugin '"+pluginDirs[i].getAbsolutePath() +"'." ,
1445 1508
							e
1446 1509
					);
1447 1510
				} catch (ValidationException e) {
1448
					logger.error("Can't load plugin '"+pluginDirs[i].getAbsolutePath() +"'." ,
1511
					this.addError("Can't load plugin '"+pluginDirs[i].getAbsolutePath() +"'." ,
1449 1512
							e
1450 1513
					);
1451 1514
				}
......
1905 1968
		session.setPluginDirectory( andamiConfig.getPluginsDirectory() );
1906 1969
		if (session.validationRequired()){
1907 1970
			if(session.Login()){
1908
				System.out.println("You are logged in");
1909
			}
1910
			else{
1971
				logger.info("You are logged in");
1972
			} else {
1911 1973
				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
1912 1974
						 "You are not logged in");
1913
				//System.exit(0);
1914 1975
			}
1915 1976
			PluginServices.setAuthentication(session);
1916 1977
		}

Also available in: Unified diff