4 * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 package uk.ac.ntu.n0521366.wsyd;
26 import java.lang.reflect.InvocationTargetException;
27 import java.lang.reflect.Method;
28 import java.util.ArrayList;
29 import java.util.logging.Level;
30 import java.util.logging.Logger;
31 import uk.ac.ntu.n0521366.wsyd.server.ServerSocial;
32 import uk.ac.ntu.n0521366.wsyd.management.ServerManagement;
33 import uk.ac.ntu.n0521366.wsyd.client.ClientGUI;
37 * @author Eddie Berrisford-Lynch <dev@fun2be.me>
39 public class Launcher {
41 static class App implements Runnable {
43 private final Class<?> _classRef;
44 private final String[] _args;
46 public App(Class<?> classRef, String[] args) {
54 ClassLoader cl = _classRef.getClassLoader();
56 Object o = cl.loadClass(_classRef.getName()).newInstance();
57 Class<?> newClass = o.getClass();
58 Method m = newClass.getMethod("main", String[].class);
59 m.invoke(null, (Object) this._args);
60 } catch (ClassNotFoundException ex) {
61 Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
62 } catch (InstantiationException ex) {
63 Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
65 } catch (NoSuchMethodException ex) {
66 Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
67 } catch (SecurityException ex) {
68 Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
69 } catch (IllegalAccessException ex) {
70 Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
71 } catch (IllegalArgumentException ex) {
72 Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
73 } catch (InvocationTargetException ex) {
74 Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
79 static ArrayList<App> apps;
81 public static void main(String[] args) {
83 apps = new ArrayList<>();
85 apps.add(new App( ServerSocial.class, args));
86 apps.add(new App(ServerManagement.class, args));
87 for (int qty = 1; qty <= 1; qty++) {
88 apps.add(new App(ClientGUI.class, args));
92 System.out.println("Starting app " + app._classRef.getTypeName());
93 new Thread(app).start();