// MobySimple.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.datatypes.MobyObject;

import org.jdom.Element;

/**
 * A specialized "envelope" that can carry one real Biomoby data
 * object, and gives it (usually) a name, also known as an <em>article
 * name for top-level object</em>. <p>
 *
 * @author <A HREF="mailto:martin.senger@gmail.com">Martin Senger</A>
 * @version $Id: MobySimple.java,v 1.2 2006/02/07 14:11:06 senger Exp $
 */

public class MobySimple extends MobyDataElement {

    protected MobyObject data;

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

    /**************************************************************************
     *
     *************************************************************************/
    public String toString() {
	StringBuffer buf = new StringBuffer();
	buf.append ("(Simple) ");
	buf.append (super.toString());
	if (data != null) buf.append (data.format (1));
	return new String (buf);
    }

    /**************************************************************************
     *
     *************************************************************************/
    public Element toXML() {
	if (data == null)
	    return toXML (getName(), null);
	else
	    return toXML (getName(), data.toXML()); 
// 	Element elem = super.toXML();
// 	elem.setName (MobyTags.SIMPLE);
// 	    elem.addContent (data.toXML());
// 	return elem;
    }

    /**************************************************************************
     *
     *************************************************************************/
    public static Element toXML (String articleName, Element data) {
	Element elem = MobyDataElement.toXML (articleName);
	elem.setName (MobyTags.SIMPLE);
	if (data != null)
	    elem.addContent (data);
	return elem;
    }

    /**************************************************************************
     * Fill this envelope with a Biomoby object.
     *************************************************************************/
    public void setData (MobyObject data) {
	this.data = data;
    }

    /**************************************************************************
     * Return the contents of this envelope.
     *************************************************************************/
    public MobyObject getData() {
	return data;
    }

}
