
package uk.co.wingpath.gpx;

import java.io.*;
import java.util.*;
import uk.co.wingpath.xml.*;

// A person or organization.

public class Person
    implements Xml.Savable, Xml.Loader
{
    private String name;        // Name of person or organization.
    private Email email;        // Email address.
    private Link link;          // Link to Web site or other external
                                // information about person.

	public Person ()
    {
        name = null;
        email = null;
        link = null;
    }

    public Xml.Loader startChild (String tag)
    {
        if (tag.equalsIgnoreCase ("email"))
        {
            email = new Email ();
            return email;
        }
        else if (tag.equalsIgnoreCase ("link"))
        {
            link = new Link ();
            return link;
        }
        if (tag.equalsIgnoreCase ("name"))
        {
            return new Xml.StringLoader (new Xml.Receiver<String> ()
            {
                public void receive (String value)
                {
                    name = value;
                }
            });
        }
        return null;
    }

    public void attribute (String attr, String value)
    {
    }

    public void end (String value)
    {
        if (!value.equals (""))
            name = value;
    }

    public void cleanup ()
    {
    }

    public void save (Xml.Saver saver)
        throws IOException
    {
        if (name != null)
            saver.saveValue ("name", name);
        if (email != null)
            saver.saveValue ("email", email);
        if (link != null)
            saver.saveValue ("link", link);
    }
}

