extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/FtpServiceControllerFactory.java

Code
Comments
Other
Rev Date Author Line
716 02 Jun 08 nicklas 1 /**
716 02 Jun 08 nicklas 2   $Id $
716 02 Jun 08 nicklas 3
716 02 Jun 08 nicklas 4   Copyright (C) 2008 Nicklas Nordborg
716 02 Jun 08 nicklas 5
1381 15 Aug 11 martin 6   This file is part of the FTP Server extension for BASE.
716 02 Jun 08 nicklas 7   Available at http://baseplugins.thep.lu.se/
1381 15 Aug 11 martin 8   BASE main site: http://base.thep.lu.se/
1381 15 Aug 11 martin 9   -----------------------------------------------------------
1381 15 Aug 11 martin 10   
1381 15 Aug 11 martin 11   This is free software; you can redistribute it and/or
716 02 Jun 08 nicklas 12   modify it under the terms of the GNU General Public License
1381 15 Aug 11 martin 13   as published by the Free Software Foundation; either version 3
716 02 Jun 08 nicklas 14   of the License, or (at your option) any later version.
1381 15 Aug 11 martin 15   
1381 15 Aug 11 martin 16   The software is distributed in the hope that it will be useful,
716 02 Jun 08 nicklas 17   but WITHOUT ANY WARRANTY; without even the implied warranty of
716 02 Jun 08 nicklas 18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
716 02 Jun 08 nicklas 19   GNU General Public License for more details.
1381 15 Aug 11 martin 20   
1381 15 Aug 11 martin 21   You should have received a copy of the GNU General Public License
1381 15 Aug 11 martin 22   along with BASE. If not, see <http://www.gnu.org/licenses/>.
716 02 Jun 08 nicklas 23
716 02 Jun 08 nicklas 24 */
714 30 May 08 nicklas 25 package net.sf.basedb.clients.ftp;
714 30 May 08 nicklas 26
716 02 Jun 08 nicklas 27 import org.slf4j.Logger;
716 02 Jun 08 nicklas 28 import org.slf4j.LoggerFactory;
716 02 Jun 08 nicklas 29
714 30 May 08 nicklas 30 import net.sf.basedb.clients.web.extensions.service.ServiceControllerAction;
2312 04 Apr 14 nicklas 31 import net.sf.basedb.core.SessionControl;
714 30 May 08 nicklas 32 import net.sf.basedb.util.extensions.ActionFactory;
714 30 May 08 nicklas 33 import net.sf.basedb.util.extensions.InvokationContext;
714 30 May 08 nicklas 34
716 02 Jun 08 nicklas 35 /**
716 02 Jun 08 nicklas 36   An action factory for creating {@link FtpServiceController} actions.
716 02 Jun 08 nicklas 37   A single factory is tied to a single {@link BaseFtpServer}, which is
716 02 Jun 08 nicklas 38   created lazily when it is first needed. This usually happens when
716 02 Jun 08 nicklas 39   the {@link #getActions(InvokationContext)} method is called.
716 02 Jun 08 nicklas 40   <p>
716 02 Jun 08 nicklas 41   The action factory accepts the following parameters:
716 02 Jun 08 nicklas 42   <ul>
716 02 Jun 08 nicklas 43   <li>{@link #setConfig(String)}: The path to the configuration file. The
741 13 Aug 08 nicklas 44     default is: <code>/ftp-config.xml</code>
716 02 Jun 08 nicklas 45   </ul>
716 02 Jun 08 nicklas 46   
716 02 Jun 08 nicklas 47   @author Nicklas
716 02 Jun 08 nicklas 48   @version 1.0
716 02 Jun 08 nicklas 49 */
714 30 May 08 nicklas 50 public class FtpServiceControllerFactory 
714 30 May 08 nicklas 51   implements ActionFactory<ServiceControllerAction> 
714 30 May 08 nicklas 52 {
716 02 Jun 08 nicklas 53   private static final Logger log = LoggerFactory.getLogger(FtpServiceControllerFactory.class);
714 30 May 08 nicklas 54
716 02 Jun 08 nicklas 55   private FtpServiceController[] controller;
716 02 Jun 08 nicklas 56   private String config;
714 30 May 08 nicklas 57   
716 02 Jun 08 nicklas 58   /**
716 02 Jun 08 nicklas 59     Creates a new factory instance.
716 02 Jun 08 nicklas 60   */
714 30 May 08 nicklas 61   public FtpServiceControllerFactory()
714 30 May 08 nicklas 62   {}
714 30 May 08 nicklas 63   
716 02 Jun 08 nicklas 64   /*
716 02 Jun 08 nicklas 65     From the ActionFactory interface
716 02 Jun 08 nicklas 66     -------------------------------------------
716 02 Jun 08 nicklas 67   */
714 30 May 08 nicklas 68   @Override
714 30 May 08 nicklas 69   public ServiceControllerAction[] getActions(InvokationContext context)
714 30 May 08 nicklas 70   {
2312 04 Apr 14 nicklas 71     return getController(context.getClientContext().getSessionControl());
714 30 May 08 nicklas 72   }
714 30 May 08 nicklas 73
716 02 Jun 08 nicklas 74   /**
716 02 Jun 08 nicklas 75     Always TRUE.
716 02 Jun 08 nicklas 76   */
714 30 May 08 nicklas 77   @Override
714 30 May 08 nicklas 78   public boolean prepareContext(InvokationContext context) 
714 30 May 08 nicklas 79   {
714 30 May 08 nicklas 80     return true;
714 30 May 08 nicklas 81   }
716 02 Jun 08 nicklas 82   // -----------------------------------------------
714 30 May 08 nicklas 83
716 02 Jun 08 nicklas 84   /**
716 02 Jun 08 nicklas 85     Set the path to the configuration file to use. The path
716 02 Jun 08 nicklas 86     should be a path on the CLASSPATH. 
741 13 Aug 08 nicklas 87     @param config The path, or null to use the default path (/ftp-config.xml)
716 02 Jun 08 nicklas 88   */
716 02 Jun 08 nicklas 89   public void setConfig(String config)
714 30 May 08 nicklas 90   {
716 02 Jun 08 nicklas 91     this.config = config;
716 02 Jun 08 nicklas 92   }
716 02 Jun 08 nicklas 93
2312 04 Apr 14 nicklas 94   private FtpServiceController[] getController(SessionControl sc)
716 02 Jun 08 nicklas 95   {
714 30 May 08 nicklas 96     if (controller == null)
714 30 May 08 nicklas 97     {
716 02 Jun 08 nicklas 98       controller = new FtpServiceController[1];
717 03 Jun 08 nicklas 99       controller[0] = new FtpServiceController(config);
714 30 May 08 nicklas 100     }
2312 04 Apr 14 nicklas 101     controller[0].setSessionControl(sc);
714 30 May 08 nicklas 102     return controller;
714 30 May 08 nicklas 103   }
714 30 May 08 nicklas 104   
714 30 May 08 nicklas 105 }