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

1    package xml.adbk; 
2     
3    import java.beans.XMLEncoder; 
4    import java.io.ByteArrayOutputStream; 
5    import java.io.Serializable; 
6     
7     
8    public class SimpleAddress implements Comparable, 
9            Serializable { 
10       private String name = null; 
11       private String address = null; 
12       private String info = null; 
13       private String homePhone = null; 
14       private String businessPhone = null; 
15       private String faxPhone = null; 
16    
17       public SimpleAddress() { 
18       } 
19    
20       public int compareTo(Object o1) { 
21           SimpleAddress a = (SimpleAddress) o1; 
22           String hisLastName = a.name.toLowerCase(); 
23           String lastNameMine = getName().toLowerCase(); 
24           return lastNameMine.compareTo(hisLastName); 
25       } 
26    
27       public static void main(String args[]) { 
28           SimpleAddress a = new SimpleAddress(); 
29           //3Com; 
30           // Palm Computing, Inc.  5400 Bayfront Plaza     Box 58007       Santa Clara, CA 95052-8007 
31           // ;                                       ;;;; 
32           a.setName("3Com"); 
33           a.setAddress("Palm Computing, Inc.  5400 Bayfront Plaza " + 
34                   "    Box 58007       Santa Clara, CA 95052-8007"); 
35           System.out.println("a=" + a); 
36       } 
37    
38       public String toString() { 
39           return this.toXml(); 
40       } 
41    
42       public void setInfo(String s) { 
43           info = s; 
44       } 
45    
46       public void setHomePhone(String s) { 
47           homePhone = s; 
48       } 
49    
50       public void setBusinessPhone(String s) { 
51           businessPhone = s; 
52       } 
53    
54       public void setFaxPhone(String s) { 
55           faxPhone = s; 
56       } 
57    
58       public void setAddress(String s) { 
59           address = s; 
60       } 
61    
62       public void setName(String s) { 
63           name = s; 
64       } 
65    
66       public String toXml() { 
67           ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
68           XMLEncoder e = new XMLEncoder(baos); 
69           e.writeObject(this); 
70           e.flush(); 
71           return baos.toString(); 
72       } 
73    
74       public String getName() { 
75           return name; 
76       } 
77    
78       public String getAddress() { 
79           return address; 
80       } 
81    
82       public String getInfo() { 
83           return info; 
84       } 
85    
86       public String getHomePhone() { 
87           return homePhone; 
88       } 
89    
90       public String getBusinessPhone() { 
91           return businessPhone; 
92       } 
93    
94       public String getFaxPhone() { 
95           return faxPhone; 
96       } 
97   }