Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 324453 - Provide an Activator base class that loads/stores a config object during start/stop
Summary: Provide an Activator base class that loads/stores a config object during star...
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.net4j (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Eike Stepper CLA
QA Contact: Eike Stepper CLA
URL:
Whiteboard: Power to the People
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-03 12:45 EDT by Eike Stepper CLA
Modified: 2011-06-23 03:41 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eike Stepper CLA 2010-09-03 12:45:29 EDT
Provide abstract OSGiActivator.WithConfig
Comment 1 Eike Stepper CLA 2010-09-03 12:46:00 EDT
  /**
   * @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;
  }
Comment 2 Eike Stepper CLA 2010-09-03 12:46:49 EDT
Committed to HEAD
Comment 3 Eike Stepper CLA 2011-06-23 03:41:03 EDT
Available in R20110608-1407