Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 324453

Summary: Provide an Activator base class that loads/stores a config object during start/stop
Product: [Modeling] EMF Reporter: Eike Stepper <stepper>
Component: cdo.net4jAssignee: 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 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