Package sonia.jdf.cmd

Source Code of sonia.jdf.cmd.CommandFactory

/**
* Copyright (c) 2011, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
*    this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
*    this list of conditions and the following disclaimer in the documentation
*    and/or other materials provided with the distribution.
* 3. Neither the name of JDF; nor the names of its
*    contributors may be used to endorse or promote products derived from this
*    software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* https://bitbucket.org/sdorra/jdf
*
*/



package sonia.jdf.cmd;

//~--- non-JDK imports --------------------------------------------------------

import sonia.jdf.SystemUtil;
import sonia.jdf.cmd.unix.UnixStartCommand;
import sonia.jdf.cmd.unix.UnixStodCommand;
import sonia.jdf.cmd.win.ControlWinServiceCommand;
import sonia.jdf.cmd.win.InstallWinServiceCommand;
import sonia.jdf.cmd.win.UninstallWinServiceCommand;

//~--- JDK imports ------------------------------------------------------------

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
*
* @author Sebastian Sdorra
*/
public class CommandFactory
{

  /** Field description */
  private static CommandFactory instance;

  //~--- constructors ---------------------------------------------------------

  /**
   * Constructs ...
   *
   */
  private CommandFactory()
  {
    commands.put(HelpCommand.VALUE_NAME, new HelpCommand());
    commands.put(ConsoleCommand.COMMAND_NAME, new ConsoleCommand());

    if (SystemUtil.isUnix() || SystemUtil.isMac())
    {
      commands.put(UnixStartCommand.COMMAND_NAME, new UnixStartCommand());
      commands.put(UnixStodCommand.COMMAND_NAME, new UnixStodCommand());
    }
    else
    {
      commands.put(InstallWinServiceCommand.COMMAND_NAME,
                   new InstallWinServiceCommand());
      commands.put(UninstallWinServiceCommand.COMMAND_NAME,
                   new UninstallWinServiceCommand());
      commands.put(ControlWinServiceCommand.COMMAND_NAME,
                   new ControlWinServiceCommand());
    }
  }

  //~--- get methods ----------------------------------------------------------

  /**
   * Method description
   *
   *
   * @return
   */
  public static CommandFactory getInstance()
  {
    if (instance == null)
    {
      instance = new CommandFactory();
    }

    return instance;
  }

  /**
   * Method description
   *
   *
   * @return
   */
  public List<Command> getAvailableCommands()
  {
    return new ArrayList<Command>(commands.values());
  }

  /**
   * Method description
   *
   *
   * @param name
   *
   * @return
   */
  public Command getCommand(String name)
  {
    return commands.get(name);
  }

  //~--- fields ---------------------------------------------------------------

  /** Field description */
  private Map<String, Command> commands = new HashMap<String, Command>();
}
TOP

Related Classes of sonia.jdf.cmd.CommandFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.