/Users/lyon/j4p/src/xml/adbk/SimpleAddressBook.java

1    package xml.adbk; 
2     
3    import java.beans.XMLEncoder; 
4    import java.io.ByteArrayOutputStream; 
5    import java.io.Serializable; 
6    import java.util.Vector; 
7     
8    /** 
9     * DocJava, Inc. 
10    * http://www.docjava.com 
11    * Programmer: dlyon 
12    * Date: Nov 3, 2004 
13    * Time: 6:24:02 PM 
14    */ 
15   public class SimpleAddressBook implements Serializable { 
16       private Vector v = new Vector(); 
17    
18       public void add(SimpleAddress sa) { 
19           v.addElement(v); 
20       } 
21    
22       public static void main(String[] args) { 
23           SimpleAddress a = new SimpleAddress(); 
24           a.setName("Herman Munster"); 
25           a.setAddress("1212 Mocking bird Lane"); 
26           a.setFaxPhone("203-555 faxME"); 
27           a.setHomePhone("203-555 callMe"); 
28           a.setBusinessPhone("203-555 bus"); 
29           SimpleAddressBook sab = new SimpleAddressBook(); 
30           sab.add(a); 
31           System.out.println(sab); 
32       } 
33    
34       public String toString() { 
35           return this.toXml(); 
36       } 
37    
38       public String toXml() { 
39           ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
40           XMLEncoder e = new XMLEncoder(baos); 
41           e.writeObject(this); 
42           e.flush(); 
43           return baos.toString(); 
44       } 
45   } 
46