
package personservice;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;


// By default JAXB uses getters/setters for marshaling/unmarshaling
// Using fields access allows us not to define getters/setters for 
// all mapped instance variables.
@XmlAccessorType(XmlAccessType.FIELD)
// We need to provide the namespace, otherwise it defaults to
// the package name
@XmlRootElement(namespace="http://person")
public class Person {

    // we only need annotations for variables that don't match 
    // element names
    private String ssn;
    private String firstName;
    private String lastName;
    
    @XmlElement(name = "address")
    protected List<Address> addresses;
    
    
    public String getSsn() {
        return ssn;
    }

    public void setSsn(String ssn) {
        this.ssn = ssn;
    }

    /**
     * Gets the value of the firstName property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Sets the value of the firstName property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    
    public void setFirstName(String value) {
        this.firstName = value;
    }

    /**
     * Gets the value of the lastName property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Sets the value of the lastName property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setLastName(String value) {
        this.lastName = value;
    }

    public String getFullName(){
        return firstName+" "+lastName;
    }
    
    
    public String toString(){
        
        StringBuilder buf = new StringBuilder();
        buf.append("\nSSN: "+ssn);
        buf.append("\nName: "+getFullName() );
        for( Address address:addresses){
            buf.append("\n"+address);
        }
        return buf.toString();
        
    }
    
}
