ConfigUtils.java
7.7 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.airport.util;
import com.airport.bean.XMLHeader;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
public class ConfigUtils {
private static final Logger logger = Logger.getLogger(ConfigUtils.class);
public static String ROLE;
public static String IMF_USERNAME;
public static String IMF_PASSWORD;
public static final String IFM_CONSUMER = "config/imf_config.properties";
public static final String IMF_PRUDUCER = "config/imf_config.properties";
public static final String INDEX_FILE_NAME = "data/fid_index.txt";
public static int SEND_MESSAGE_INTERVAL = 1;
public static int RECORD_COUNT = 1000;
public static String XML_HEADER_SNDR = "";
public static String XML_HEADER_TYPE = "";
public static String XML_HEADER_STYPE = "";
public static String XML_HEADER_RCVR = "";
public static Map<Integer, XMLHeader> XML_HEADER_MAP = new HashMap();
public static String RCVR = "";
public static String APPID = "";
public static String SNDR = "";
public static String SQl="";
public static String SQlMax="";
public static Map<String, String> XTYPE_MAP = new HashMap();
public ConfigUtils() {
}
private void initMap() {
XTYPE_MAP.put("FSU_DEP", "UDEP");
XTYPE_MAP.put("FSU_RCF", "URCF");
XTYPE_MAP.put("FSU_FOH", "UFOH");
XTYPE_MAP.put("FZE_DEP", "EDEP");
XTYPE_MAP.put("FZE_RCF", "ERCF");
XTYPE_MAP.put("FZE_FOH", "EFOH");
XTYPE_MAP.put("CARGO_SERV", "CARG");
}
public void Initialize() throws LteException {
logger.debug("Loading all the config parameters...");
this.loadParameter();
this.initMap();
}
private final void loadParameter() throws LteException {
boolean ok = false;
logger.info("================Initialize system parameter =================");
Configuration config = (Configuration)SystemBean.getBean("configurationBean");
ROLE = config.getProperty("role").trim();
IMF_USERNAME = config.getProperty("imf_username").trim();
IMF_PASSWORD = config.getProperty("imf_password").trim();
SQl = config.getProperty("sql");
SQlMax = config.getProperty("sqlmax");
String interval = config.getProperty("interval").trim();
String record_count = config.getProperty("record_count").trim();
logger.info(String.format("role=%s", ROLE));
logger.info(String.format("imf_username=%s", IMF_USERNAME));
logger.info(String.format("imf_password=%s", IMF_PASSWORD));
logger.info(String.format("interval=%s", interval));
if (StringUtils.isBlank(ROLE)) {
logger.error("role 参数错误");
ok = true;
} else if ("R".equalsIgnoreCase(ROLE)) {
if (!isFileExists("config/imf_config.properties")) {
logger.error("如果要从IMF接收数据,需要在config/imf_config.properties 配置IMF参数");
ok = true;
}
} else if ("S".equalsIgnoreCase(ROLE)) {
if (!isFileExists("config/imf_config.properties")) {
logger.error("如果向IMF发送数据,需要在config/imf_config.properties 配置IMF参数");
ok = true;
}
} else {
logger.error("role 参数错误,必须是S(从IMF接收消息) 或者 R(发送消息到IMF)");
}
int int_total_group;
if ("S".equalsIgnoreCase(ROLE)) {
String total_group = config.getProperty("total_group").trim();
int_total_group = 0;
logger.info(String.format("record_count=%s", record_count));
logger.info(String.format("total_group=%s", total_group));
if (StringUtils.isBlank(total_group)) {
logger.error("total_group 参数错误");
ok = true;
} else {
int_total_group = Integer.parseInt(total_group);
if (int_total_group <= 10 && int_total_group >= 1) {
this.loadXMLHeaderParameter(config, int_total_group);
} else {
logger.error("total_group 参数设置错误,范围在1--10之间");
ok = true;
}
}
int x;
if (StringUtils.isBlank(record_count)) {
logger.error("record_count 参数错误");
ok = true;
} else {
x = Integer.parseInt(record_count);
if (x <= 10000 && x >= 100) {
RECORD_COUNT = x;
} else {
logger.error("record_count 参数设置错误,范围在100--10000之间");
ok = true;
}
}
if (StringUtils.isBlank(interval)) {
logger.error("interval 参数错误");
ok = true;
} else {
x = Integer.parseInt(interval);
if (x <= 60 && x >= 1) {
SEND_MESSAGE_INTERVAL = x * 1000;
} else {
logger.error("interval 参数设置错误,范围在1---60之间");
ok = true;
}
}
}
if (!isFileExists("data/")) {
File f = new File("data");
f.mkdir();
Utils.writeFIDIndex("data/fid_index.txt", 0);
int_total_group = Utils.readFIDIndex("data/fid_index.txt");
logger.info("FID=" + int_total_group);
} else {
logger.info("data/fid_index.txt exists");
}
boolean hasError = false;
hasError = this.validate(IMF_USERNAME, "imf_username 参数错误");
hasError = this.validate(IMF_PASSWORD, "imf_password 参数错误");
if (ok && !hasError) {
logger.error("参数错误 启动程序失败。");
System.exit(-1);
}
}
private void loadXMLHeaderParameter(Configuration config, int total) throws LteException {
String sndr = "";
String rcvr = "";
String type = "";
String stype = "";
for(int i = 1; i <= total; ++i) {
logger.info(String.format("group %d--------------------------", i));
sndr = config.getProperty("sndr_" + i).trim();
rcvr = config.getProperty("rcvr_" + i).trim();
type = config.getProperty("type_" + i).trim();
stype = config.getProperty("stype_" + i).trim();
logger.info(String.format("SNDR_%d=%s", i, sndr));
logger.info(String.format("RCVR_%d=%s", i, rcvr));
logger.info(String.format("TYPE_%d=%s", i, type));
logger.info(String.format("STYPE_%d=%s", i, stype));
XMLHeader header = new XMLHeader();
header.setSndr(sndr);
header.setRcvr(rcvr);
header.setType(type);
header.setStype(stype);
logger.info("group[" + i + "]\t" + header.toString());
XML_HEADER_MAP.put(i, header);
}
}
private boolean validate(String paraValue, String tipText) {
if (StringUtils.isBlank(paraValue)) {
logger.error(tipText);
return false;
} else {
return true;
}
}
private static boolean isFileExists(String filename) {
File f = new File(filename);
return f.exists();
}
public static void main(String[] argc) {
File f = new File("config/producer_imf_config.properties");
if (f.exists()) {
System.out.println("file exists");
} else {
System.out.println("file not exists");
}
}
}