浏览代码

修复异常。

YangZhiJie 8 年之前
父节点
当前提交
e6c84f4d43

+ 15 - 1
src/main/java/com/leanwo/management/ServerSettingJFrame.java

@@ -33,6 +33,9 @@ import javax.swing.JTextArea;
 import javax.swing.JTextField;
 import javax.swing.Timer;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.leanwo.management.exception.ConfigFileException;
 import org.leanwo.management.util.SpringUtil;
 import org.leanwo.management.util.XmlConfigPathService;
 
@@ -45,6 +48,9 @@ import com.leanwo.management.model.XmlConfigPath;
  *
  */
 public class ServerSettingJFrame  extends JFrame{
+	
+	private static Log logger = LogFactory.getLog(ServerSettingJFrame.class);
+
 	private ApplicationSetting applicationSetting;
 	private XmlConfigPath xmlConfigPath;
 	private XmlConfigPathService xmlConfigPathService;
@@ -69,7 +75,15 @@ public class ServerSettingJFrame  extends JFrame{
 		
 		this.xmlConfigPathService = (XmlConfigPathService) SpringUtil.getSingleBean(XmlConfigPathService.class);
 		this.applicationSetting = applicationSetting;
-		this.xmlConfigPathService.load(applicationSetting);
+		
+		try {
+			this.xmlConfigPathService.load(applicationSetting);
+		}catch(ConfigFileException ex) {
+			logger.error("配置文件异常", ex);
+			JOptionPane.showMessageDialog(null, ex.getMessage(), "配置文件异常", JOptionPane.ERROR_MESSAGE);
+			this.dispose();
+		}
+		
 		this.xmlConfigPath = applicationSetting.getXmlConfigPath();
 		this.innerPanel = new JPanel(new GridBagLayout());
 		

+ 12 - 0
src/main/java/org/leanwo/management/exception/ConfigFileException.java

@@ -0,0 +1,12 @@
+package org.leanwo.management.exception;
+
+/**
+ * 配置文件异常
+ * @author YangZhiJie
+ *
+ */
+public class ConfigFileException extends Exception {
+	public ConfigFileException(String msg) {
+		super(msg);
+	}
+}

+ 4 - 2
src/main/java/org/leanwo/management/util/XmlConfigPathService.java

@@ -24,6 +24,7 @@ import org.dom4j.Element;
 import org.dom4j.io.OutputFormat;
 import org.dom4j.io.SAXReader;
 import org.dom4j.io.XMLWriter;
+import org.leanwo.management.exception.ConfigFileException;
 
 import com.leanwo.management.model.ApplicationSetting;
 import com.leanwo.management.model.XmlConfigPath;
@@ -35,8 +36,9 @@ public class XmlConfigPathService {
 	 * 从xml配中获取node 的数据
 	 * ,contents等属性
 	 * @param setting
+	 * @throws ConfigFileException 
 	 */
-	public void load(ApplicationSetting setting) {
+	public void load(ApplicationSetting setting) throws ConfigFileException {
 		Map<String, String> contentMap = new HashMap<String, String>();
 		XmlConfigPath xmlConfigPath = setting.getXmlConfigPath();
 		String xmlFilePath = setting.getInstallPath() + "/" + xmlConfigPath.getXmlFileName();
@@ -77,7 +79,7 @@ public class XmlConfigPathService {
 				e.printStackTrace();
 			} 
 		}else{
-			throw new RuntimeException("文件:"+xmlFilePath+",不存在");
+			throw new ConfigFileException("文件:"+xmlFilePath+",不存在");
 		}
 		//读取propertis信息
 		String propertiesPath = setting.getInstallPath()+"/config/config.properties";