01: package com.bostechcorp.cbesb.console.server;
02:
03: import java.io.File;
04: import java.util.Vector;
05:
06: import com.bostechcorp.cbesb.common.i18n.CoreMessageConstants;
07: import com.bostechcorp.cbesb.common.i18n.Messages;
08: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
09: import com.bostechcorp.cbesb.console.common.ServerSideException;
10: import com.bostechcorp.cbesb.console.pub.LogConfigItem;
11: import com.bostechcorp.cbesb.console.rpc.LogConfig;
12:
13: public class LogConfigImpl extends JmxServiceServlet implements
14: LogConfig {
15:
16: /**
17: *
18: */
19: private static final long serialVersionUID = 8177577166691317942L;
20:
21: private static String default_logLevel = "info";
22:
23: String filePath = EsbPathHelper.getCbesbHomeDir() + File.separator
24: + "log" + File.separator + "config" + File.separator;
25: String configFileName = filePath + "log4j.lst";
26:
27: public LogConfigItem[] getConfigNameArray()
28: throws ServerSideException {
29: try {
30: LogList logList = LogListReader
31: .readFromFile(configFileName);
32: String configFile = getLogConfig();
33:
34: Vector<LogConfigItem> result = new Vector<LogConfigItem>();
35: for (int i = 0; i < logList.getList().size(); i++) {
36: LogItem item = logList.getList().get(i);
37: LogConfigItem configItem = new LogConfigItem(item
38: .getName(), item.getFileName());
39: if ((filePath + configItem.getFileName())
40: .equalsIgnoreCase(configFile)) {
41: configItem.setSelected(true);
42: }
43: result.add(configItem);
44: }
45: return result.toArray(new LogConfigItem[] {});
46: } catch (Exception e) {
47: throw new ServerSideException(
48: (Messages
49: .get(CoreMessageConstants.FAILED_TO_READ_LOG4J_CONFIG_FILE)),
50: e);
51: }
52:
53: }
54:
55: public void setLogLevel(String configLevel)
56: throws ServerSideException {
57: LogList logList = new LogList();
58: try {
59: logList = LogListReader.readFromFile(configFileName);
60:
61: } catch (Exception e) {
62: throw new ServerSideException(
63: (Messages
64: .get(CoreMessageConstants.FAILED_TO_READ_LOG4J_CONFIG_FILE)),
65: e);
66: }
67: String fileName = logList.getFileNameFromName(configLevel);
68: String absoluteFileName = filePath + fileName;
69: String configFile = getLogConfig();
70: if (!absoluteFileName.equalsIgnoreCase(configFile))
71: getClientFromSession().setLogConfig(filePath + fileName);
72: }
73:
74: private String getLogConfig() throws ServerSideException {
75: String configFile = this .getClientFromSession().getLogConfig();
76: if (configFile == null) {
77: LogList logList = null;
78: try {
79: logList = LogListReader.readFromFile(configFileName);
80: } catch (Exception e) {
81: throw new ServerSideException(
82: (Messages
83: .get(CoreMessageConstants.FAILED_TO_READ_LOG4J_CONFIG_FILE)),
84: e);
85: }
86: return filePath
87: + logList.getFileNameFromName(default_logLevel);
88:
89: }
90: return configFile;
91: }
92: }
|