/*!
 * This program is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 * or from the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * Copyright (c) 2002-2013 Pentaho Corporation..  All rights reserved.
 */
package org.pentaho.platform.dataaccess.datasource.wizard.service.impl;

import java.util.concurrent.Callable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.platform.api.engine.IPlatformReadyListener;
import org.pentaho.platform.api.engine.IPluginLifecycleListener;
import org.pentaho.platform.api.engine.PluginLifecycleException;
import org.pentaho.platform.engine.core.system.PentahoSystem;
import org.pentaho.platform.engine.security.SecurityHelper;
import org.pentaho.platform.repository2.unified.lifecycle.DelegatingBackingRepositoryLifecycleManager;

public class DataAccessLifecycleListener implements IPluginLifecycleListener, IPlatformReadyListener {

  private static final Log log = LogFactory.getLog( DataAccessLifecycleListener.class );

  @Override
  public void init() throws PluginLifecycleException {
  }

  @Override
  public void loaded() throws PluginLifecycleException {
  }

  @Override
  public void ready() throws PluginLifecycleException {

    // the platform is booted, spring initialized, all plugins init and loaded
    try {
      SecurityHelper.getInstance().runAsSystem( new Callable<Void>() {
        public Void call() throws Exception {
          AgileMartDatasourceLifecycleManager.getInstance().startup();
          return null;
        }
      } );
    } catch ( Exception e ) {
      log.warn( e.getMessage(), e );
    }

    DelegatingBackingRepositoryLifecycleManager manager =
        PentahoSystem
            .get( DelegatingBackingRepositoryLifecycleManager.class, "backingRepositoryLifecycleManager", null );
    manager.addLifeCycleManager( AgileMartDatasourceLifecycleManager.getInstance() );
  }

  @Override
  public void unLoaded() throws PluginLifecycleException {
  }

}

@@ -1146,32 +1146,94 @@
 ecycleListener;%0A
+import org.pentaho.platform.api.engine.IPluginResourceLoader;%0A
 import org.penta
@@ -1700,16 +1700,110 @@
 lass );%0A
+  private static final String ENABLE_AGILEMART_DATASOURCE = %22enable-agile-mart-datasource%22;%0A  
 %0A  @Over
@@ -2009,17 +2009,16 @@
 ption %7B%0A
-%0A
     // t
@@ -2096,14 +2096,444 @@
     
-try %7B%0A
+boolean enableAgilemartDatasource = false;%0A    try %7B%0A      IPluginResourceLoader resLoader = PentahoSystem.get( IPluginResourceLoader.class, null );%0A      enableAgilemartDatasource = Boolean.parseBoolean( resLoader.getPluginSetting( DataAccessLifecycleListener.class, ENABLE_AGILEMART_DATASOURCE, %22false%22 ) );%0A    %7D catch ( Throwable t ) %7B%0A      log.warn( t.getMessage(), t );%0A    %7D%0A    if ( enableAgilemartDatasource ) %7B%0A      try %7B%0A  
     
@@ -2595,24 +2595,26 @@
 e%3CVoid%3E() %7B%0A
+  
         publ
@@ -2657,16 +2657,18 @@
         
+  
 AgileMar
@@ -2730,16 +2730,18 @@
         
+  
 return n
@@ -2757,16 +2757,18 @@
     
+  
 %7D%0A      
 %7D );
@@ -2767,13 +2767,17 @@
     
+ 
+ 
 %7D );%0A
+  
     
@@ -2800,32 +2800,34 @@
 ion e ) %7B%0A      
+ 
+ 
 log.warn( e.getM
@@ -2837,24 +2837,26 @@
 age(), e );%0A
+  
     %7D%0A%0A    D
@@ -2854,16 +2854,18 @@
  %7D%0A%0A    
+  
 Delegati
@@ -2918,16 +2918,18 @@
         
+  
 PentahoS
@@ -2934,16 +2934,18 @@
 oSystem%0A
+  
         
@@ -3054,16 +3054,18 @@
  );%0A    
+ 
+ 
 manager.
@@ -3138,16 +3138,22 @@
 ce() );%0A
+    %7D%0A
   %7D%0A%0A  @

Disable the AgileBI connection from data-access