// MobyParameter.java
//
//    Created: August 2005
//
// This file is a component of the BioMoby project.
// Copyright Martin Senger (martin.senger@gmail.com).
//

package org.biomoby.shared.parser;

import org.jdom.Element;

/**
 * A mixture of an "envelope" (because it inherits from a general
 * envelope MobyDataElement, and Biomoby data, representing a
 * secondary input - a secondary means that it is not used in a
 * service discovery process. In practise, it means that it contains
 * just some control values, like command-like switches etc. <p>
 *
 * @author <A HREF="mailto:martin.senger@gmail.com">Martin Senger</A>
 * @version $Id: MobyParameter.java,v 1.4 2006/05/09 13:32:09 senger Exp $
 */

public class MobyParameter extends MobyDataElement {

    protected String value;

    /**************************************************************************
     * Default constructor.
     *************************************************************************/
    public MobyParameter() {
    }

    /**************************************************************************
     *
     *************************************************************************/
    public String toString() {
	StringBuffer buf = new StringBuffer();
	buf.append ("(Parameter) ");
	buf.append (super.toString());
	if (value != null) buf.append ("   Value: " + value + "\n");
	return new String (buf);
    }

    /**************************************************************************
     *
     *************************************************************************/
    public Element toXML() {
	return toXML (getName(), value);
    }

    /**************************************************************************
     *
     *************************************************************************/
    public static Element toXML (String articleName, String value) {
	Element elem = MobyDataElement.toXML (articleName);
	elem.setName (MobyTags.PARAMETER);
	if (value != null) {
	    Element valueElem = MobyPackage.getXMLElement (MobyTags.VALUE);
	    valueElem.setText (value);
	    elem.addContent (valueElem);
	}
	return elem;
    }

    /**************************************************************************
     * Fill in a value of this parameter.
     *************************************************************************/
    public void setValue (String value) {
	this.value = value;
    }

    /**************************************************************************
     *
     *************************************************************************/
    public String getValue() {
	return value;
    }

}
