/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2006 Bull S.A.S.
 * Contact: jonas-team@objectweb.org
 *
 * This library is free software; you can redistribute it and/or
 *
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or 1any later version.
 *
 * This library 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.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */
package org.objectweb.jonas_clusterd.xml;

import org.objectweb.jonas_lib.deployment.xml.AbsDescriptionElement;
import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
import org.objectweb.jonas_lib.deployment.xml.TopLevelElement;

/**
 * This class defines the configuration of the cluster daemon
 *
 * @author Benoit Pelletier
 */
public class ClusterDaemon extends AbsDescriptionElement implements TopLevelElement {

    /**
     * Version UID
     */
    private static final long serialVersionUID = 3212755715938568244L;

    /**
     * name
     */
    private String name = null;

    /**
     * Domain name
     */
    private String domainName = null;

    /**
     * JOnAS interaction mode : loosely/tighly coupled
     */
    private String jonasInteractionMode = null;

    /**
     * servers
     */
    private JLinkedList serverList = null;

    /**
     * Constructor
     */
    public ClusterDaemon() {
        super();
        serverList = new  JLinkedList("server");
    }

    /**
     * Add a new server element to this object
     * @param server the Server object
     */
    public void addServer(Server server) {
        serverList.add(server);
    }

    /**
     * @return Returns the serverList.
     */
    public JLinkedList getServerList() {
        return serverList;
    }

    /**
     * @param serverList The serverList to set.
     */
    public void setServerList(JLinkedList serverList) {
        this.serverList = serverList;
    }

    /**
     * Represents this element by it's XML description.
     * @param indent use this indent for prexifing XML representation.
     * @return the XML description of this object.
     */
    public String toXML(int indent) {
        StringBuffer sb = new StringBuffer();
        sb.append(indent(indent));
        sb.append("<cluster-daemon> "
                  +
                  "xmlns=\"http://www.objectweb.org/jonas/ns\" "
                  +
                  "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
                  +
                  "xsi:schemaLocation=\"http://www.objectweb.org/jonas/ns\" "
                  +
                  "http://www.objectweb.org/jonas/ns/jonas-clusterd_4_8.xsd");
        indent += 2;

        // name
        if (getName() != null) {
            sb.append(xmlElement(getName(), "name", indent));
        }

        // domain-name
        if (getDomainName() != null) {
            sb.append(xmlElement(getDomainName(), "domain-name", indent));
        }

        // jonas-interaction-mode
        if (getJonasInteractionMode() != null) {
            sb.append(xmlElement(getJonasInteractionMode(), "jonas-interaction-mode", indent));
        }


        // servers
        sb.append(getServerList().toXML(indent));

        indent -= 2;
        sb.append(indent(indent));
        sb.append("</cluster-daemon>\n");

        return sb.toString();
    }

    /**
     *
     * @return the domain name
     */
    public String getDomainName() {
        return domainName;
    }

    /**
     * set the domain name
     * @param domainName domain name
     */
    public void setDomainName(String domainName) {
        this.domainName = domainName;
    }

    /**
    *
    * @return the name
    */
   public String getName() {
       return name;
   }

   /**
    * set the name
    * @param name name
    */
   public void setName(String name) {
       this.name = name;
   }

    /**
     *
     * @return the interaction mode with JOnAS
     */
    public String getJonasInteractionMode() {
        return jonasInteractionMode;
    }


    /**
     * set the interaction mode with JOnAS
     * @param jonasInteraction interaction mode
     */
    public void setJonasInteractionMode(String jonasInteractionMode) {
        this.jonasInteractionMode = jonasInteractionMode;
    }

}
