1 10 package org.jgap.data.config; 11 12 import java.util.*; 13 import java.io.*; 14 import javax.swing.*; 15 16 23 public final class ConfigWriter { 24 25 private final static String CVS_REVISION = "$Revision: 1.7 $"; 26 27 30 private static ConfigWriter m_cWriter; 31 32 private Properties m_config; 34 35 42 public static ConfigWriter getInstance() { 43 if (m_cWriter == null) { 44 m_cWriter = new ConfigWriter(); 45 } 46 return m_cWriter; 47 } 48 49 55 private ConfigWriter() { 56 m_config = new Properties(); 57 } 58 59 66 public void write(final IConfigInfo a_cInfo) { 67 ConfigData cd = a_cInfo.getConfigData(); 68 String nsPrefix = cd.getNS() + "."; 69 String name; 70 List values; 71 for (int i = 0; i < cd.getNumLists(); i++) { 73 name = cd.getListNameAt(i); 74 values = cd.getListValuesAt(i); 75 int idx = 0; 76 for (Iterator iter = values.iterator(); iter.hasNext(); idx++) { 77 String tmpName = name + "[" + idx + "]"; 79 tmpName = nsPrefix + tmpName; 80 m_config.setProperty(tmpName, (String ) iter.next()); 81 } 82 } 83 String value = "", tmpName = ""; 84 for (int i = 0; i < cd.getNumTexts(); i++) { 85 name = cd.getTextNameAt(i); 86 value = cd.getTextValueAt(i); 87 tmpName = nsPrefix + name; 88 m_config.setProperty(tmpName, value); 89 } 90 try { 91 FileOutputStream out = new FileOutputStream(a_cInfo.getFileName()); 92 try { 93 m_config.store(out, "---JGAP Configuration File---"); 94 } finally { 95 out.close(); 96 } 97 } catch (IOException ioEx) { 98 JOptionPane.showMessageDialog(null, 99 "Exception " + ioEx.getMessage(), 100 "Configuration Exception", 101 JOptionPane.INFORMATION_MESSAGE); 102 ioEx.printStackTrace(); 103 } 104 } 105 } 106 | Popular Tags |