package com.dbxml.db.server;

/*
 * dbXML - Native XML Database
 * Copyright (C) 1999-2004  The dbXML Group, L.L.C.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: SimpleService.java,v 1.2 2004/02/12 00:17:57 bradford Exp $
 */

import com.dbxml.util.Configuration;
import com.dbxml.util.SimpleConfigurable;
import com.dbxml.util.dbXMLException;

/**
 * SimpleService is a basic Service implementation that will manage the
 * the basic properties of a Service as well as implement default behavior
 * for the service management methods.
 */

public class SimpleService extends SimpleConfigurable implements Service {
   public static final String NAME = "name";

   protected int status = STATE_STOPPED;
   protected String statusMsg = "stopped";
   protected Server server;
   protected String name;

   protected void setName(String name) {
      this.name = name;
   }

   public void setServerInstance(Server server) {
      this.server = server;
   }

   public void setConfig(Configuration config) throws dbXMLException {
      super.setConfig(config);
      setName(config.getAttribute(NAME));
   }

   public String getName() {
      return name;
   }

   public int status() {
      return status;
   }

   public String statusMessage() {
      return statusMsg;
   }

   public int initialize() {
      return RESULT_OK;
   }

   public int start() {
      status = STATE_STARTED;
      statusMsg = "started";
      return RESULT_OK;
   }

   public int stop() {
      status = STATE_STOPPED;
      statusMsg = "stopped";
      return RESULT_OK;
   }

   public int suspend() {
      status = STATE_SUSPENDED;
      statusMsg = "suspended";
      return RESULT_OK;
   }

   public int resume() {
      status = STATE_STARTED;
      statusMsg = "started";
      return RESULT_OK;
   }

   public int uninitialize() {
      return RESULT_OK;
   }

   public void dispose() {
   }
}
