KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > customer > Address


1 /*
2  * Created on Nov 19, 2004
3  */

4 package com.openedit.store.customer;
5
6 import com.openedit.users.PropertyContainer;
7
8 /**
9  * @author dbrown
10  *
11  */

12 public class Address
13 {
14     protected PropertyContainer fieldPropertyContainer;
15     protected String JavaDoc fieldPrefix;
16     public static final String JavaDoc ADDRESS1 = "Address1";
17     public static final String JavaDoc ADDRESS2 = "Address2";
18     public static final String JavaDoc CITY = "City";
19     public static final String JavaDoc STATE = "State";
20     public static final String JavaDoc COUNTRY = "Country";
21     public static final String JavaDoc ZIP = "ZipCode";
22
23     public Address()
24     {
25     }
26
27     public Address(PropertyContainer inPropertyContainer)
28     {
29         setPropertyContainer(inPropertyContainer);
30     }
31
32     protected String JavaDoc getProperty(String JavaDoc inPropertyName)
33     {
34         return (String JavaDoc)getPropertyContainer().get(getPrefix() + inPropertyName);
35     }
36
37     protected void putProperty(String JavaDoc inPropertyName, String JavaDoc inValue)
38     {
39         getPropertyContainer().safePut(getPrefix() + inPropertyName, inValue);
40     }
41
42     public String JavaDoc getPrefix()
43     {
44         if ( fieldPrefix == null )
45         {
46             fieldPrefix = "";
47         }
48         return fieldPrefix;
49     }
50     public void setPrefix(String JavaDoc inPrefix)
51     {
52         fieldPrefix = inPrefix;
53     }
54
55     public String JavaDoc getAddress1()
56     {
57         return getProperty(ADDRESS1);
58     }
59     public void setAddress1(String JavaDoc inAddress1)
60     {
61         putProperty(ADDRESS1, inAddress1);
62     }
63     public String JavaDoc getAddress2()
64     {
65         return getProperty(ADDRESS2);
66     }
67     public void setAddress2(String JavaDoc inAddress2)
68     {
69         putProperty(ADDRESS2, inAddress2);
70     }
71     public String JavaDoc getCity()
72     {
73         return getProperty(CITY);
74     }
75     public void setCity(String JavaDoc inCity)
76     {
77         putProperty(CITY, inCity);
78     }
79     public String JavaDoc getCountry()
80     {
81         return getProperty(COUNTRY);
82     }
83     public void setCountry(String JavaDoc inCountry)
84     {
85         putProperty(COUNTRY, inCountry);
86     }
87     public String JavaDoc getState()
88     {
89         return getProperty(STATE);
90     }
91     public void setState(String JavaDoc inState)
92     {
93         putProperty(STATE, inState);
94     }
95     public String JavaDoc getZipCode()
96     {
97         return getProperty(ZIP);
98     }
99     public String JavaDoc get5DigitZipCode()
100     {
101         String JavaDoc zip = getProperty(ZIP);
102         if (getCountry().equals("USA") && zip.length() > 5)
103         {
104             zip = zip.substring(0,5);
105         }
106         return zip;
107     }
108
109     public void setZipCode(String JavaDoc inZipCode)
110     {
111         putProperty(ZIP, inZipCode);
112     }
113
114     public PropertyContainer getPropertyContainer()
115     {
116         return fieldPropertyContainer;
117     }
118     public void setPropertyContainer(PropertyContainer inPropertyContainer)
119     {
120         fieldPropertyContainer = inPropertyContainer;
121     }
122
123     public void setCityState( String JavaDoc inCityState )
124     {
125         if ( inCityState != null && inCityState.indexOf(",") > -1)
126         {
127             String JavaDoc[] both = inCityState.split(",");
128             setCity(both[0]);
129             setState(both[1]);
130         }
131     }
132     public String JavaDoc getCityState()
133     {
134         return getCity() + ", " + getState();
135     }
136 }
137
Popular Tags