midrange.com code scratchpad
Name:
Save subsystem specific properties
Scriptlanguage:
Java
Tabwidth:
4
Date:
12/13/2007 07:58:05 pm
IP:
Logged
Description:
The user was to lazy to give a description
Code:
  1. public void saveSubSystem(SubSystem _subsystem) throws Exception {
  2.     super.saveSubSystem(_subsystem);
  3.         
  4.     ImplementerSubSystem subsystem = (ImplementerSubSystem)_subsystem;
  5.         
  6.     Properties generalProperties = subsystem.getGeneralProperties();
  7.         
  8.     propertyFile = getPropertiesFile(_subsystem);
  9.         
  10.     saveProperties(generalProperties, propertyFile, 
  11.     "General Properties");
  12.         
  13. }
  14.  
  15. protected SubSystem restoreSubSystem(SystemConnection arg0, String arg1)
  16.     throws Exception {
  17.     ImplementerSubSystem subsystem = 
  18.     (ImplementerSubSystem)super.restoreSubSystem(arg0, arg1);
  19.  
  20.     propertyFile = getPropertiesFile(subsystem);
  21.  
  22.     Properties general = getProperties(propertyFile);
  23.         
  24.     subsystem.setGeneralProperties(general);
  25.         
  26.     return subsystem;
  27. }
  28.     
  29. private void saveProperties(Properties props, IFile file, 
  30.     String comment)
  31.     throws CoreException, IOException {
  32.  
  33.     if (file.exists()) {
  34.     file.delete(true, null);
  35.     }
  36.  
  37.     ByteArrayOutputStream os = new ByteArrayOutputStream();
  38.  
  39.     props.storeToXML(os, comment);
  40.  
  41.     ByteArrayInputStream is = 
  42.     new ByteArrayInputStream(os.toByteArray());
  43.  
  44.     file.create(is, true, null);
  45. }
  46.  
  47. private Properties getProperties(IFile file) throws CoreException, IOException {
  48.  
  49.     Properties props = new Properties();
  50.  
  51.     if (file.exists()) {
  52.     InputStream is = file.getContents();
  53.     props.loadFromXML(is);
  54.     }
  55.  
  56.     return props;
  57. }
  58.     
  59. private IFile getPropertiesFile(SubSystem subsystem) {
  60.         
  61.     IFolder connectionFolder =
  62.     getSubSystemsFolder(subsystem.getSystemConnection());
  63.         
  64.     return connectionFolder.getFile("general.props");
  65.         
  66. }
© 2004-2019 by midrange.com generated in 0.01s valid xhtml & css