// MobyDataElement.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.biomoby.shared.Utils;

import org.jdom.Element;

/**
 * A general "envelope" that can carry real Biomoby data objects. The
 * known sub-classes represents concepts from the Biomoby API (Simples
 * and Collections, for example). <p>
 *
 * Note that this is an envelope so it does not contain any value (any
 * real data). <p>
 *
 * @author <A HREF="mailto:martin.senger@gmail.com">Martin Senger</A>
 * @version $Id: MobyDataElement.java,v 1.2 2006/02/07 14:11:06 senger Exp $
 */

abstract public class MobyDataElement {

    protected String name = "";   // articleName

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

    /**************************************************************************
     * Format all non-empty public members in a human-readable way.
     *
     * @see #format for making the returned string better indented
     * @return a formatted string
     *************************************************************************/
    public String toString() {
	return ("Article name: " + name + "\n");
    }

    /**************************************************************************
     * Return the same contents as {@link #toString} method but
     * indented by level expressed in the parameter 'indent'. It is
     * useful when a hierarchy of objects call <tt>toString</tt>
     * methods on their children/members. <p>
     *
     * @param indent means a level of wanted indentation: number 1
     * means three spaces, number two six spaces, etc.
     * @return a formatted, and indented, string
     *************************************************************************/
    public String format (int indent) {
	return Utils.format (this, indent);
    }

    /**************************************************************************
     * Create an XML element representing this object. <p>
     *
     * @return a <a
     * href="http://www.jdom.org/docs/apidocs/org/jdom/Element.html">jDom
     * element</a> that can be easily incorporated into bigger a XML
     * document
     *************************************************************************/
    public Element toXML() {
	return toXML (getName());
    }

    /**************************************************************************
     * Create an XML element representing this object. <p>
     *
     * @return a <a
     * href="http://www.jdom.org/docs/apidocs/org/jdom/Element.html">jDom
     * element</a> that can be easily incorporated into bigger a XML
     * document
     *************************************************************************/
    public static Element toXML (String articleName) {
	Element elem =
	    MobyPackage.getXMLElement ("_dummy_");   // will be replaced by subclass
	MobyPackage.setXMLAttribute (elem, MobyTags.ARTICLENAME, articleName);
	return elem;
    }

    /**************************************************************************
     * A name here means an <em>article name of the top-level object</em>.
     *************************************************************************/
    public void setName (String name) {
	this.name = (name == null ? "" : name);
    }

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

}
