-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava4Models.java
More file actions
127 lines (111 loc) · 3.46 KB
/
Java4Models.java
File metadata and controls
127 lines (111 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package models;
import java.io.FileReader;
import java.io.Reader;
import java.util.logging.ErrorManager;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import org.xmappr.*;
import configuration.Consts;
import configuration.TestConfiguration;
import configuration.Configuration;
/**
* The Class Java4Models.
*
*/
public class Java4Models {
private final static Logger LOGGER = Logger.getLogger(Java4Models.class.getName());
private static FileHandler fh = null;
/**
* The main method.
* Reads in konfiguration.xml and starts worker
*
* @param args the arguments
*/
public static void main(String[] args) {
// 0. Get Configs
// Inputfiles
// modelpath
// Outputfile
if (args.length != 1) {
writeHelp();
System.exit(1);
}
if (args[0].equals("--version")) {
writeHelp();
System.exit(1);
}
Reader reader = null;
Configuration config = null;
try {
reader = new FileReader(args[0]);
Xmappr xm = new Xmappr(Configuration.class);
config = (Configuration) xm.fromXML(reader);
} catch (Exception e) {
System.err.println("Fehler: Die Konfigurationsdatei "+ args[0] + " konnte nicht eingelesen werden.");
e.printStackTrace();
System.out.println();
writeHelp();
System.exit(1);
}
TestConfiguration tester = new TestConfiguration(config);
if (!tester.test()) {
writeHelp();
System.exit(1);
}
initLog(config.getLogfile());
Worker wrk = new Worker (config);
if ((wrk.init())
&& (wrk.process())
&& (wrk.finish())
)
LOGGER.log(Level.INFO,"Die Patienten wurden erfolgreich bearbeitet.");
else LOGGER.log(Level.SEVERE,"Das Programm wurde durch einen Fehler beendet.");
}
public static void writeHelp () {
System.out.println("Java4Models. Elsevier Health Analytics. Version: " + Consts.version);
System.out.println("Aufruf: java -jar java4models.jar <konfiguration.xml>");
System.out.println("Für schnelle Sortierung der Inputfiles-Files mit mehr Memory: java -Xmx2048m -Xms256m -jar java4models.jar <konfiguration.xml>");
}
private static void initLog(String file) {
LogManager.getLogManager().reset();
Logger l = Logger.getLogger("");
if (file != null && !file.equals("")) {
try {
fh=new FileHandler(file, false);
fh.setFormatter(new SimpleFormatter());
l.addHandler(fh);
} catch (Exception e) {
System.err.println("Fehler bei Erstellen des Logfiles");
e.printStackTrace();
System.exit(9);
}
}
Handler consoleHandler = new Handler(){
@Override
public void publish(LogRecord record) {
if (getFormatter() == null)
setFormatter(new SimpleFormatter());
try {
String message = getFormatter().format(record);
if (record.getLevel().intValue() >= Level.WARNING.intValue())
System.err.write(message.getBytes());
else
System.out.write(message.getBytes());
} catch (Exception exception) {
reportError(null, exception, ErrorManager.FORMAT_FAILURE);
}
}
@Override
public void close() throws SecurityException {}
@Override
public void flush(){}
};
l.addHandler(consoleHandler);
l.setLevel(Level.INFO);
}
}