import java.io.*;
import org.w3c.dom.*;

/**
 * An encapsulation of a PhoneNumber.
 * 
 * This is an example of "naive" serialization.
 * 
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class PhoneNumber
{
    private String number, type;
    
    /**
     * Construct an empty PhoneNumber object.
     */
   private PhoneNumber()
    {
    }

   /**
    * Populate the attributes of this PhoneNumber object from
    * an XML representation.
    * 
    * @param source  The XML representation
    */
   public void fromXML(Element source)
   {
       number  = source.getAttribute("number");
       type    = source.getAttribute("type");
   }
   
   /**
    * Construct a PhoneNumber object from an XML representation.
    * 
    * @param source  The XML representation
    * @return        The Person object
    */
   public static PhoneNumber parsePhoneNumber(Element source)
   {
       PhoneNumber result = new PhoneNumber();
       result.fromXML(source);
       return result;
   }
    /**
     * Create an XML representation of this PhoneNumber.
     * 
     * @return The XML representation
     */
    public String toXML()
    {
        return String.format("<PhoneNumber type=\"%s\" number=\"%s\" />",
                type, number);
    }
}
