×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




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


This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.