package examples; import java.util.Date; import java.beans.XMLEncoder; import java.io.*; /* * @author Kenneth J. Goldman * Created: Feb 9, 2006 */ public class Person { String name; Date birthday; int ssn; Person mom; String momName; public Person() { this("unnamed",null,0,null,"unavailable"); } public Person(String name, Date birthday, int ssn, Person mom, String momName) { this.birthday = birthday; this.mom = mom; this.name = name; this.ssn = ssn; this.momName = momName; } /** * @return Returns the name. */ public String getAName() { return name; } /** * @param name The name to set. */ public void setAName(String name) { this.name = name; } /** * @return Returns the birthday. */ public Date getBirthday() { return birthday; } /** * @param birthday The birthday to set. */ public void setBirthday(Date birthday) { this.birthday = birthday; } /** * @return Returns the mom. */ public Person getMom() { return mom; } /** * @param mom The mom to set. */ public void setMom(Person mom) { this.mom = mom; } /** * @return Returns the ssn. */ public int getSsn() { return ssn; } /** * @param ssn The ssn to set. */ public void setSsn(int ssn) { this.ssn = ssn; } /** * * @return momName */ public String getMomName() { return momName; } /** * * @param momName */ public void setMomName(String momName) { this.momName = momName; } public String toString() { return name; } public static void main(String[] args) throws FileNotFoundException { Person a = new Person("Eve", new Date(), 1, null, "null"); Person b = new Person("Abel", new Date(), 2, a, ""+a); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("Test.xml")); XMLEncoder e = new XMLEncoder(bos); e.flush(); (new PrintStream(bos)).println(""); e.writeObject(a); e.writeObject(b); e.close(); } }