View Javadoc
1   package com.starphoenixmedia.candle_pos;
2   
3   import java.io.File;
4   import java.lang.reflect.InvocationTargetException;
5   import java.lang.reflect.Method;
6   import java.util.ArrayList;
7   import java.util.Iterator;
8   import java.util.Map.Entry;
9   import java.util.logging.Level;
10  import java.util.logging.Logger;
11  
12  /**
13   *
14   * @author jlhawkwell
15   */
16  public class Starter
17  {
18  	public static void main(final String[] args)
19  	{
20  		for ( String s : args )
21  		{
22  			if ( "dumpvars".equals(s.toLowerCase()) )
23  			{
24  				Iterator<Entry<Object, Object>> it = System.getProperties().entrySet().iterator();
25  				Entry<Object, Object> e;
26  				while ( it.hasNext() )
27  				{
28  					e = it.next();
29  					System.out.print(e.getKey().toString());
30  					System.out.print("\t=\t");
31  					System.out.println(e.getValue().toString());
32  				}
33  				Iterator<Entry<String, String>>its = System.getenv().entrySet().iterator();
34  				Entry<String, String> es;
35  				while ( its.hasNext() )
36  				{
37  					es = its.next();
38  					System.out.print(es.getKey());
39  					System.out.print("\t=\t");
40  					System.out.println(es.getValue());
41  				}
42  				return;
43  			}
44  		}
45  
46  		final FireCodeClassLoader fccl = new FireCodeClassLoader(CandleStart.class.getClassLoader());
47  		fccl.init();
48  
49  		ArrayList<File> locs = new ArrayList<>();
50  
51  		Thread t = new Thread()
52  		{
53  			@Override public void run()
54  			{
55  				System.out.println("Booting...");
56  				Class cls = null;
57  				try { cls = fccl.loadClass("com.starphoenixmedia.candle_pos.CandleStart"); }
58  				catch (ClassNotFoundException ex)
59  				{ Logger.getLogger(CandleStart.class.getName()).log(Level.SEVERE, null, ex); return; }
60  
61  				/**if ( cls.isAssignableFrom(CandleStart.class) )
62  				{
63  					CandleStart fcl;
64  					try { fcl = (CandleStart) cls.newInstance(); }
65  					catch (InstantiationException | IllegalAccessException ex)
66  					{ Logger.getLogger(CandleStart.class.getName()).log(Level.SEVERE, null, ex); return; }
67  
68  					fcl.init(args);
69  				}
70  				else
71  				{ // */
72  					Method m = null;
73  					try { m = cls.getMethod("init", String[].class); }
74  					catch (NoSuchMethodException | SecurityException ex)
75  					{ Logger.getLogger(CandleStart.class.getName()).log(Level.SEVERE, null, ex); return; }
76  
77  					Object o = null;
78  					try { o = cls.newInstance(); }
79  					catch ( InstantiationException | IllegalAccessException ex)
80  					{ Logger.getLogger(CandleStart.class.getName()).log(Level.SEVERE, null, ex); }
81  
82  					if ( (m != null) && (o != null) )
83  					{
84  						try { m.invoke(o, (Object) args); }
85  						catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex)
86  						{
87  							if ( (ex instanceof InvocationTargetException) && (ex.getCause() != null) )
88  							{ Logger.getLogger(CandleStart.class.getName()).log(Level.SEVERE, null, ex.getCause()); }
89  							else { Logger.getLogger(CandleStart.class.getName()).log(Level.SEVERE, null, ex); }
90  						}
91  					}
92  				//}
93  			}
94  		};
95  
96  		t.setName("Candle-Main");
97  		t.setContextClassLoader(fccl);
98  		t.setDaemon(false);
99  		t.start();
100 	}
101 
102 	/*public static void filerDeeper(ArrayList<File> list, File loc)
103 	{
104 		if ( !loc.exists() ) { return; }
105 
106 		File[] fs = loc.listFiles();
107 
108 		if ( fs == null ) { return; }
109 		if ( fs.length == 0 ) { return; }
110 
111 		String pt;
112 
113 		for ( File f : fs )
114 		{
115 			if ( f.getName().isEmpty() ) { }
116 			else if ( f.getName().startsWith(".") ) { }
117 			else
118 			{
119 				if ( f.isFile() && f.getName().endsWith(".jar") )
120 				{
121 					try
122 					{
123 						pt = f.getCanonicalPath();
124 						list.add(new File(pt));
125 						System.out.println("Added ".concat(pt));
126 					}
127 					catch ( IOException x ) { }
128 				}
129 				else if ( f.isDirectory() ) { filerDeeper(list, f); }
130 			}
131 		}
132 	} // */
133 }