| Summary: | Provide an Activator base class that loads/stores a config object during start/stop | ||
|---|---|---|---|
| Product: | [Modeling] EMF | Reporter: | Eike Stepper <stepper> |
| Component: | cdo.net4j | Assignee: | Eike Stepper <stepper> |
| Status: | CLOSED FIXED | QA Contact: | Eike Stepper <stepper> |
| Severity: | enhancement | ||
| Priority: | P3 | ||
| Version: | 4.0 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | Power to the People | ||
|
Description
Eike Stepper
/**
* @author Eike Stepper
* @since 3.1
*/
public static abstract class WithConfig extends OSGiActivator
{
public WithConfig(OMBundle bundle)
{
super(bundle);
}
@Override
protected final void doStart() throws Exception
{
FileInputStream fis = null;
try
{
File configFile = OM.BUNDLE.getConfigFile();
if (configFile.exists())
{
fis = new FileInputStream(configFile);
ObjectInputStream ois = new ObjectInputStream(fis);
Object config = ois.readObject();
IOUtil.close(ois);
doStartWithConfig(config);
}
}
catch (Exception ex)
{
getOMBundle().logger().error(ex);
}
finally
{
IOUtil.close(fis);
}
}
@Override
protected final void doStop() throws Exception
{
FileOutputStream fos = null;
try
{
Object config = doStopWithConfig();
File configFile = OM.BUNDLE.getConfigFile();
fos = new FileOutputStream(configFile);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(config);
IOUtil.close(oos);
}
catch (Exception ex)
{
getOMBundle().logger().error(ex);
}
finally
{
IOUtil.close(fos);
}
}
protected abstract void doStartWithConfig(Object config) throws Exception;
protected abstract Object doStopWithConfig() throws Exception;
}
Committed to HEAD Available in R20110608-1407 |