View Javadoc

1   package org.minetti.astrodevice.client;
2   
3   import java.io.FileInputStream;
4   import java.io.FileNotFoundException;
5   import java.io.IOException;
6   import java.rmi.Remote;
7   import java.rmi.RemoteException;
8   import java.util.Locale;
9   import java.util.Properties;
10  
11  import javax.naming.Context;
12  import javax.naming.InitialContext;
13  import javax.rmi.PortableRemoteObject;
14  
15  import org.minetti.astrodevice.client.gui.SwtGui;
16  import org.minetti.astrodevice.client.orb.callback.ClientCallbackOrbHandlerImpl;
17  import org.minetti.astrodevice.common.orb.SelectedObservingSiteOrbProcess;
18  import org.minetti.astrodevice.common.orb.OrbProcessName;
19  import org.minetti.astrodevice.common.orb.PlatformOrbProcess;
20  import org.minetti.astrodevice.common.orb.callback.ClientCallbackOrbHandler;
21  import org.minetti.astrodevice.common.orb.exception.IiopException;
22  
23  /**
24   * Class responsible of application startup.
25   * @author Jean-Philippe MINETTI
26   */
27  public final class Startup {
28  
29  	/**
30  	 * Main function.
31  	 * @param args Arguments on the command line.
32  	 */
33  	public static void main(final String[] args) {
34  		Runtime.getRuntime().addShutdownHook(new Thread(new Shutdown()));
35  		System.out.println(About.getInstance().getApplicationName());
36  		System.out.println("Version " + About.getInstance().getApplicationVersion());
37  
38  		// ===================== TEST =============================
39  		final Properties props = new Properties();
40  		try {
41  			props.load(Startup.class.getResourceAsStream("/jndi.properties"));
42  		}
43  		catch (FileNotFoundException e) {
44  			System.err.println("le fichier jndi.properties n'a pas été trouvé");
45  			System.exit(1);
46  		}
47  		catch (IOException e) {
48  			System.err.println("une erreur d'entrée sortie s'est produite :" + e);
49  			e.printStackTrace();
50  			System.exit(2);
51  		}
52  		Context ic = null;
53  		try {
54  			ic = new InitialContext(props);
55  			// ic = new InitialContext();
56  		}
57  		catch (Exception e) {
58  			e.printStackTrace();
59  			System.err.println("Avez-vous lancé le serveur de nom (orbd) ?");
60  			System.exit(3);
61  		}
62  		try {
63  			// étape 1 : obtenir la référence au servant,
64  			// par un appel JNDI
65  			Object objref = ic.lookup(OrbProcessName.PLATFORM_PROCESS_NAME);
66  
67  			// étape 2 : narrow la référence à l'objet
68  			// vers son type réel et invoquer la méthode.
69  			PlatformOrbProcess platform = (PlatformOrbProcess) PortableRemoteObject.narrow(objref, PlatformOrbProcess.class);
70  			System.out.println("==================> " + platform.getServerVersion(Locale.getDefault()));
71  
72  			// Enregistrement/Désenregistrement callback
73  			final ClientCallbackOrbHandler callbackHandler = new ClientCallbackOrbHandlerImpl();
74  			PortableRemoteObject.exportObject(callbackHandler);
75  			platform.register(callbackHandler);
76  			platform.unregister(callbackHandler);
77  
78  			
79  //			objref = ic.lookup(OrbProcessName.SELECTED_OBSERVING_SITE_PROCESS_NAME);
80  //			SelectedObservingSiteOrbProcess selectedObservingSite = (SelectedObservingSiteOrbProcess) PortableRemoteObject.narrow(objref,
81  //					SelectedObservingSiteOrbProcess.class);
82  //			selectedObservingSite.select(Locale.getDefault(), 1);
83  
84  		}
85  		catch(RemoteException e) {
86  			if (e.getCause() instanceof IiopException) {
87  				final IiopException exception = (IiopException)(e.getCause());
88  				System.err.println(exception.getMessage());
89  				e.printStackTrace();
90  				System.err.println(exception.getUserShortMessage());
91  				System.err.println(exception.getUserLongMessage());
92  				System.err.println(exception.getUserSolution());
93  			}
94  			else {
95  				System.err.println("lancez le serveur !");
96  				System.err.println(e.getMessage());
97  				e.printStackTrace();
98  			}
99  			System.exit(3);
100 		}
101 		catch (Exception e) {
102 			System.err.println("lancez le serveur !");
103 			System.err.println(e.getMessage());
104 			e.printStackTrace();
105 			System.exit(3);
106 		}
107 		// ===================== TEST =============================
108 
109 		SwtGui.getInstance().build();
110 
111 		// TODO Auto-generated method stub
112 
113 	}
114 
115 }