David Gibbs wrote:
Does anyone know how to store complex information in a subsystem?
I figured out what I needed to do.
Basically, I'm storing the data I need in a simple Property object ...
and then storing the properties to a file in the subsystems directory.
Here's the code I added to my SubsystemFactory ...
public void saveSubSystem(SubSystem _subsystem) throws Exception {
super.saveSubSystem(_subsystem);
ImplementerSubSystem subsystem = (ImplementerSubSystem)_subsystem;
Properties generalProperties = subsystem.getGeneralProperties();
propertyFile = getPropertiesFile(_subsystem);
saveProperties(generalProperties, propertyFile,
"General Properties");
}
protected SubSystem restoreSubSystem(SystemConnection arg0, String arg1)
throws Exception {
ImplementerSubSystem subsystem =
(ImplementerSubSystem)super.restoreSubSystem(arg0, arg1);
propertyFile = getPropertiesFile(subsystem);
Properties general = getProperties(propertyFile);
subsystem.setGeneralProperties(general);
return subsystem;
}
private void saveProperties(Properties props, IFile file,
String comment)
throws CoreException, IOException {
if (file.exists()) {
file.delete(true, null);
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
props.storeToXML(os, comment);
ByteArrayInputStream is =
new ByteArrayInputStream(os.toByteArray());
file.create(is, true, null);
}
private Properties getProperties(IFile file) throws CoreException,
IOException {
Properties props = new Properties();
if (file.exists()) {
InputStream is = file.getContents();
props.loadFromXML(is);
}
return props;
}
private IFile getPropertiesFile(SubSystem subsystem) {
IFolder connectionFolder =
getSubSystemsFolder(subsystem.getSystemConnection());
return connectionFolder.getFile("general.props");
}
http://code.midrange.com/ce5a1c21a6.html
I'm not sure if the method of storing the properties is the best, but it
works.
david
As an Amazon Associate we earn from qualifying purchases.