commit | author | age
|
c3b1d1
|
1 |
/* |
U |
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package de.uhilger.mediaz; |
|
7 |
|
|
8 |
import java.io.IOException; |
|
9 |
import java.util.HashMap; |
|
10 |
import java.util.logging.Level; |
|
11 |
import java.util.logging.Logger; |
|
12 |
|
|
13 |
/** |
|
14 |
* |
|
15 |
* @author ulrich |
|
16 |
*/ |
|
17 |
public class App { |
|
18 |
|
|
19 |
private static final Logger logger = Logger.getLogger(App.class.getName()); |
|
20 |
|
|
21 |
public static final String IP_PORT = "port"; |
|
22 |
public static final String IP_WWW_DATA = "www-data"; |
|
23 |
public static final String IP_CTX = "ctx"; |
|
24 |
|
|
25 |
private static HashMap initParams; |
|
26 |
|
|
27 |
/** |
|
28 |
* <p>Start-Methode dieser Anwendung</p> |
|
29 |
* |
|
30 |
* @param args Kommandozeilenparameter |
|
31 |
*/ |
|
32 |
public static void main(String[] args) { |
|
33 |
initParams = new HashMap(); |
|
34 |
for (String arg : args) { |
|
35 |
String[] argParts = arg.split("="); |
|
36 |
initParams.put(argParts[0], argParts[1]); |
|
37 |
} |
|
38 |
|
|
39 |
String portStr = getInitParameter(IP_PORT); |
|
40 |
if (portStr != null) { |
|
41 |
Server server = new Server(Integer.parseInt(portStr)); |
|
42 |
try { |
|
43 |
String ctxName = getInitParameter(IP_CTX); |
|
44 |
if (ctxName != null) { |
|
45 |
server.setContextName(ctxName); |
|
46 |
server.start(); |
|
47 |
} else { |
|
48 |
logger.severe("Der Parameter " + IP_CTX + " muss angegeben werden."); |
|
49 |
} |
|
50 |
} catch (IOException ex) { |
|
51 |
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); |
|
52 |
} |
|
53 |
} else { |
|
54 |
logger.severe("Der Parameter " + IP_PORT + " muss angegeben werden."); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* Diese Anwendung stoppen |
|
60 |
*/ |
|
61 |
public static void stop() { |
|
62 |
System.exit(0); |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* Einen Kommandozeilenparameter ermitteln |
|
67 |
* |
|
68 |
* @param pname Names des Parameters |
|
69 |
* @return Inhalt des Parameters oder null, wenn der Parameter nicht gefunden |
|
70 |
* wurde |
|
71 |
*/ |
|
72 |
public static String getInitParameter(String pname) { |
|
73 |
String param = null; |
|
74 |
Object o = initParams.get(pname); |
|
75 |
if (o != null) { |
|
76 |
param = o.toString(); |
|
77 |
} |
|
78 |
return param; |
|
79 |
} |
|
80 |
|
|
81 |
} |