sdeboy 2003/06/17 09:33:57 Modified: src/java/org/apache/log4j/chainsaw DisplayFilter.java LogUI.java src/java/org/apache/log4j/chainsaw/prefs SettingsManager.java src/java/org/apache/log4j/net SocketReceiver.java Log: Preventing a few exceptions when a user is first getting settings configured Printing a few exceptions if settings load fails for some reason Prevented a zero-len .columns file from resulting in no columns displayed on the screen Revision Changes Path 1.8 +2 -2 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/DisplayFilter.java Index: DisplayFilter.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/DisplayFilter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- DisplayFilter.java 14 Jun 2003 21:30:44 -0000 1.7 +++ DisplayFilter.java 17 Jun 2003 16:33:56 -0000 1.8 @@ -109,6 +109,7 @@ o2.writeObject(this); o2.flush(); } catch (FileNotFoundException fnfe) { + fnfe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } @@ -117,8 +118,7 @@ if (o2 != null) { o2.close(); } - } catch (IOException ioe) { - } + } catch (IOException ioe) {ioe.printStackTrace();} } public void setCustomFilterOverride(boolean customFilterOverride) { 1.100 +38 -28 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java Index: LogUI.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java,v retrieving revision 1.99 retrieving revision 1.100 diff -u -r1.99 -r1.100 --- LogUI.java 17 Jun 2003 06:40:16 -0000 1.99 +++ LogUI.java 17 Jun 2003 16:33:56 -0000 1.100 @@ -755,21 +755,23 @@ new File( SettingsManager.getInstance().getSettingsDirectory() + File.separator + ident + ChainsawConstants.SETTINGS_EXTENSION); - - try { - s = new ObjectInputStream( - new BufferedInputStream(new FileInputStream(f))); - d = (DisplayFilter) s.readObject(); - } catch (IOException ioe) { - } catch (ClassNotFoundException cnfe) { - } finally { - if (s != null) { + if (f.exists()) { try { - s.close(); - } catch (IOException ioe) { + s = new ObjectInputStream( + new BufferedInputStream(new FileInputStream(f))); + d = (DisplayFilter) s.readObject(); + } catch (IOException ioe) {ioe.printStackTrace(); + } catch (ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } + finally { + if (s != null) { + try { + s.close(); + } catch (IOException ioe) {ioe.printStackTrace();} + } } } - } if (d == null) { d = new DisplayFilter(ident); @@ -1855,16 +1857,15 @@ } o.flush(); - } catch (FileNotFoundException fnfe) { - } catch (IOException ioe) { - ioe.printStackTrace(); + } catch (FileNotFoundException fnfe) {fnfe.printStackTrace(); + } catch (IOException ioe) {ioe.printStackTrace(); } - - try { - if (o != null) { - o.close(); - } - } catch (IOException ioe) { + finally { + try { + if (o != null) { + o.close(); + } + } catch (IOException ioe) {ioe.printStackTrace();} } } @@ -1963,10 +1964,7 @@ + File.separator + ident + COLUMNS_EXTENSION); if (f.exists()) { - //remove columns from model - will be re-added in the correct order - for (int i = model.getColumnCount() - 1; i > -1; i--) { - model.removeColumn(model.getColumn(i)); - } + ArrayList newColumns = new ArrayList(); TableColumnData temp = null; ObjectInputStream s = null; @@ -1980,16 +1978,28 @@ TableColumn tc = new TableColumn(temp.getIndex(), temp.getWidth()); tc.setHeaderValue(temp.getColName()); - table.addColumn(tc); + newColumns.add(tc); } } catch (IOException ioe) { - } catch (ClassNotFoundException cnfe) { + //may generate an EOFException if save process created file but + //the file is zero length..won't remove columns in that case + ioe.printStackTrace(); + } catch (ClassNotFoundException cnfe) {cnfe.printStackTrace(); } finally { if (s != null) { try { s.close(); - } catch (IOException ioe) { + } catch (IOException ioe) {ioe.printStackTrace(); } + } + } + if (newColumns.size() > 0) { + //remove columns from model - will be re-added in the correct order + for (int i = model.getColumnCount() - 1; i > -1; i--) { + model.removeColumn(model.getColumn(i)); + } + for (Iterator iter=newColumns.iterator();iter.hasNext();) { + model.addColumn((TableColumn)iter.next()); } } } else { 1.7 +39 -27 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/prefs/SettingsManager.java Index: SettingsManager.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/prefs/SettingsManager.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SettingsManager.java 3 Jun 2003 06:32:59 -0000 1.6 +++ SettingsManager.java 17 Jun 2003 16:33:57 -0000 1.7 @@ -132,6 +132,16 @@ * */ public void loadSettings() { + /* + * Ok, note we ensure we have a .chainsaw directory in the users + * home folder, and create a chainsaw.settings.properties file.. + */ + File settingsDir = getSettingsDirectory(); + + if (!settingsDir.exists()) { + settingsDir.mkdir(); + } + EventListener[] listeners = listenerList.getListeners(SettingsListener.class); LoadSettingsEvent event = null; @@ -156,6 +166,16 @@ * */ public void saveSettings() { + /* + * Ok, note we ensure we have a .chainsaw directory in the users + * home folder, and create a chainsaw.settings.properties file.. + */ + File settingsDir = getSettingsDirectory(); + + if (!settingsDir.exists()) { + settingsDir.mkdir(); + } + EventListener[] listeners = listenerList.getListeners(SettingsListener.class); SaveSettingsEvent event = null; @@ -170,16 +190,6 @@ settingsListener.saveSettings(event); } - /** - * Ok, note we ensure we have a .chainsaw directory in the users - * home folder, and create a chainsaw.settings.properties file.. - */ - File settingsDir = getSettingsDirectory(); - - if (!settingsDir.exists()) { - settingsDir.mkdir(); - } - OutputStream os = null; try { @@ -220,23 +230,25 @@ Properties properties = new Properties(defaultProperties); InputStream is = null; - try { - is = - new BufferedInputStream( - new FileInputStream( - new File(getSettingsDirectory(), SETTINGS_FILE_NAME))); - - Properties toLoad = new Properties(); - toLoad.load(is); - properties.putAll(toLoad); - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e1) { - e1.printStackTrace(); + File f = new File(getSettingsDirectory(), SETTINGS_FILE_NAME); + if (f.exists()) { + try { + is = + new BufferedInputStream( + new FileInputStream(f)); + + Properties toLoad = new Properties(); + toLoad.load(is); + properties.putAll(toLoad); + } catch (IOException ioe) { + ioe.printStackTrace(); + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } } } } 1.6 +0 -1 jakarta-log4j-sandbox/src/java/org/apache/log4j/net/SocketReceiver.java Index: SocketReceiver.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/net/SocketReceiver.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SocketReceiver.java 17 Jun 2003 07:19:59 -0000 1.5 +++ SocketReceiver.java 17 Jun 2003 16:33:57 -0000 1.6 @@ -57,7 +57,6 @@ import java.net.Socket; import java.util.Enumeration; -import java.util.Iterator; import java.util.Vector;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]