[Mc4j-cvs] mc4j/src/org/mc4j/console/connection/persistence ServerInstallSetDatabase.java,1.3,1.4 Co
Brought to you by:
ghinkl
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/connection/persistence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20162/src/org/mc4j/console/connection/persistence Modified Files: ServerInstallSetDatabase.java ConnectionSetDatabase.java Removed Files: ConnectionSettingsBeanInfo.java ConnectionSettings.java Log Message: Merging EMS into head for the 2.0 release work Index: ServerInstallSetDatabase.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/connection/persistence/ServerInstallSetDatabase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ServerInstallSetDatabase.java 15 Jan 2005 03:49:16 -0000 1.3 --- ServerInstallSetDatabase.java 12 Apr 2006 19:14:01 -0000 1.4 *************** *** 44,48 **** private final static String DATABASE_FILENAME = "ServerInstalls.db"; ! private static Set descriptors = Collections.synchronizedSet(new HashSet()); public synchronized static boolean addNode(ServerInstallInfo descriptor) { --- 44,48 ---- private final static String DATABASE_FILENAME = "ServerInstalls.db"; ! private static Set<ServerInstallInfo> descriptors = Collections.synchronizedSet(new HashSet()); public synchronized static boolean addNode(ServerInstallInfo descriptor) { *************** *** 64,71 **** int size = ServerInstallSetDatabase.descriptors.size(); outStream.writeInt( size ); ! Iterator iter = descriptors.iterator(); ! while (iter.hasNext()) { ! ServerInstallInfo element = (ServerInstallInfo)iter.next(); ! outStream.writeObject( element ); } } --- 64,69 ---- int size = ServerInstallSetDatabase.descriptors.size(); outStream.writeInt( size ); ! for (ServerInstallInfo element : descriptors) { ! outStream.writeObject(element); } } *************** *** 124,128 **** } ! public synchronized static Set getNodes() { if (ServerInstallSetDatabase.descriptors.isEmpty()) { loadNodes(); --- 122,126 ---- } ! public synchronized static Set<ServerInstallInfo> getNodes() { if (ServerInstallSetDatabase.descriptors.isEmpty()) { loadNodes(); --- ConnectionSettingsBeanInfo.java DELETED --- --- ConnectionSettings.java DELETED --- Index: ConnectionSetDatabase.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/connection/persistence/ConnectionSetDatabase.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ConnectionSetDatabase.java 15 Jan 2005 03:49:16 -0000 1.14 --- ConnectionSetDatabase.java 12 Apr 2006 19:14:01 -0000 1.15 *************** *** 18,22 **** ! import java.io.EOFException; import java.io.File; import java.io.FileInputStream; --- 18,27 ---- ! import org.mc4j.ems.connection.settings.ConnectionSettings; ! import org.openide.ErrorManager; ! ! import java.beans.XMLDecoder; ! import java.beans.XMLEncoder; ! import java.beans.DefaultPersistenceDelegate; import java.io.File; import java.io.FileInputStream; *************** *** 24,40 **** import java.io.FileOutputStream; import java.io.IOException; - import java.io.InvalidClassException; - import java.io.ObjectInputStream; - import java.io.ObjectOutputStream; - import java.io.StreamCorruptedException; - import java.util.Collections; - import java.util.HashSet; - import java.util.Iterator; import java.util.Set; ! ! import org.openide.ErrorManager; ! import org.openide.windows.IOProvider; /** * @author Corby Page 09.07.02 * @author Greg Hinkle (gh...@us...), December 2002 --- 29,41 ---- import java.io.FileOutputStream; import java.io.IOException; import java.util.Set; ! import java.util.SortedSet; ! import java.util.TreeSet; /** + * TODO GH: Maybe just translate this to util.prefs storage... + * it would be nice not to lose connections this on upgrade + * + * * @author Corby Page 09.07.02 * @author Greg Hinkle (gh...@us...), December 2002 *************** *** 43,178 **** public class ConnectionSetDatabase { ! private final static String DATABASE_FILENAME = "ConnectionNodes.db"; ! private static Set descriptors = Collections.synchronizedSet(new HashSet()); - public synchronized static boolean addNode(ConnectionSettings descriptor) { - ObjectOutputStream outStream = null; - ConnectionSetDatabase.descriptors.remove(descriptor); - ConnectionSetDatabase.descriptors.add(descriptor); - try { - if (getDatabaseFile() == null) { - File file = new File(DATABASE_FILENAME); - file.createNewFile(); - } - outStream = - new ObjectOutputStream( - new FileOutputStream( - getDatabaseFile())); - int size = ConnectionSetDatabase.descriptors.size(); - outStream.writeInt( size ); - Iterator iter = descriptors.iterator(); - while (iter.hasNext()) { - ConnectionSettings element = (ConnectionSettings)iter.next(); - outStream.writeObject( element ); - } - } - catch( Exception ex ) { ! org.openide.windows.IOProvider.getDefault().getStdOut().println( ! "Caught exception " + ex + " when adding node" ); ! ErrorManager.getDefault().notify(ex); ! ConnectionSetDatabase.descriptors.remove( descriptor ); ! } ! finally { ! try { ! outStream.close(); ! } ! catch( IOException ioEx ) { ! org.openide.windows.IOProvider.getDefault().getStdOut().println( ! "Could not close outputStream" ); ! } ! } - return true; } ! public synchronized static void removeNode(ConnectionSettings descriptor) { ! ObjectOutputStream outStream = null; ! ConnectionSetDatabase.descriptors.remove( descriptor ); try { - outStream = - new ObjectOutputStream( - new FileOutputStream( - getDatabaseFile())); ! int size = ConnectionSetDatabase.descriptors.size(); ! outStream.writeInt( size ); ! Iterator iter = descriptors.iterator(); ! while (iter.hasNext()) { ! ConnectionSettings element = (ConnectionSettings)iter.next(); ! outStream.writeObject( element ); ! } ! } catch( Exception ex ) { ! org.openide.windows.IOProvider.getDefault().getStdOut().println( ! "Caught exception " + ex + " when removing node" ); ! ConnectionSetDatabase.descriptors.add( descriptor ); } finally { try { ! outStream.close(); ! } catch( IOException ioEx ) { org.openide.windows.IOProvider.getDefault().getStdOut().println( ! "Could not close outputStream" ); } } } - public synchronized static Set getNodes() { - if (ConnectionSetDatabase.descriptors.isEmpty()) { - loadNodes(); - } - Set nodes = new HashSet(); - nodes.addAll(ConnectionSetDatabase.descriptors); - return nodes; //(new HashSet()).addAll(ConnectionSetDatabase.descriptors); - } protected synchronized static void loadNodes() { - ObjectInputStream inStream = null; ! //IOProvider.getDefault().getStdOut().println("Loading connections"); ! ConnectionSetDatabase.descriptors.clear(); ! try { ! inStream = ! new ObjectInputStream( ! new FileInputStream( ! getDatabaseFile())); ! //IOProvider.getDefault().getStdOut().println("Reading connections"); ! int size = inStream.readInt(); ! for ( int i=0; i<size; i++ ) { ! try { ! Object value = inStream.readObject(); ! ConnectionSettings setting = (ConnectionSettings) value; ! descriptors.add(setting); ! } catch (StreamCorruptedException sce) { ! // Ignore. We'll throw this away later... ! } catch (InvalidClassException ice) { ! // old version of class.. fur-get-about-it ! } catch(ClassCastException cce) { ! IOProvider.getDefault().getStdOut().println( ! "Unable to load old connection information."); ! } ! } ! } catch( FileNotFoundException ex ) { ! IOProvider.getDefault().getStdOut().println( ! "Node file missing: " + ex); ! ErrorManager.getDefault().notify(ex); ! } catch (EOFException eofe) { ! // Happens when there are no connections... its cool ! } catch( Exception ex ) { ! org.openide.windows.IOProvider.getDefault().getStdOut().println( ! "Caught exception " + ex + " when getting nodes" ); ! ErrorManager.getDefault().notify(ex); } finally { try { ! if ( inStream != null ) { ! inStream.close(); } } --- 44,123 ---- public class ConnectionSetDatabase { ! private final static String DATABASE_FILENAME = "ConnectionNodes.xml"; ! private static SortedSet<ConnectionSettings> descriptors = ! new TreeSet<ConnectionSettings>(); ! public synchronized static boolean addNode(ConnectionSettings descriptor) { ! boolean found = descriptors.add(descriptor); ! saveNodes(); ! return found; ! } ! public synchronized static void removeNode(ConnectionSettings descriptor) { ! descriptors.remove(descriptor); ! saveNodes(); } ! public synchronized static Set getNodes() { ! if (ConnectionSetDatabase.descriptors.isEmpty()) { ! loadNodes(); ! } ! return new TreeSet(ConnectionSetDatabase.descriptors); ! } ! protected synchronized static void saveNodes() { + FileOutputStream fos= null; try { ! fos = new FileOutputStream(getDatabaseFile(), false); ! XMLEncoder encoder = new XMLEncoder(fos); ! encoder.setPersistenceDelegate( ! File.class, ! new DefaultPersistenceDelegate(new String[] { "absolutePath" })); ! ! ! encoder.writeObject(descriptors); ! ! encoder.close(); ! } catch (FileNotFoundException e) { ! e.printStackTrace(); } finally { try { ! if ( fos != null ) { ! fos.close(); ! } ! } ! catch( IOException ioEx ) { org.openide.windows.IOProvider.getDefault().getStdOut().println( ! "Could not close inputStream" ); } } } protected synchronized static void loadNodes() { ! FileInputStream fis = null; ! try { ! fis = new FileInputStream(getDatabaseFile()); ! XMLDecoder decoder = new XMLDecoder(fis); ! ConnectionSetDatabase.descriptors.clear(); ! descriptors = (SortedSet<ConnectionSettings>) decoder.readObject(); ! ! } catch (FileNotFoundException e) { ! e.printStackTrace(); } finally { try { ! if ( fis != null ) { ! fis.close(); } } *************** *** 207,209 **** --- 152,156 ---- return connectionsFile; } + + } \ No newline at end of file |