KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on Mar 4, 2004
3  *
4  */

5 package com.openedit.store.customer;
6
7 import org.openedit.money.Fraction;
8
9 import com.openedit.store.PaymentMethod;
10 import com.openedit.users.User;
11 import com.openedit.users.filesystem.FileSystemUser;
12
13 /**
14  * A customer with nice getters and setters on top of the standard user object.
15  *
16  * @author dbrown
17  */

18 public class Customer
19 {
20     public static final String JavaDoc PHONE1 = "Phone1";
21     public static final String JavaDoc FAX = "Fax";
22     public static final String JavaDoc TITLE = "Title";
23     public static final String JavaDoc ALLOW_EMAIL = "AllowEmail";
24     public static final String JavaDoc REFERENCE = "ReferenceNumber";
25     public static final String JavaDoc TAX_RATE = "TaxRate";
26     public static final String JavaDoc TAX_EXEMPT_ID = "TaxExemptId";
27     public static final String JavaDoc COMPANY = "Company";
28     public static final String JavaDoc USERFIELD1 = "userfield1";
29     public static final String JavaDoc USERFIELD2 = "userfield2";
30
31     protected User fieldUser; //used to store information in Open Edit
32
protected PaymentMethod fieldPaymentMethod;
33     protected Address fieldBillingAddress;
34     protected Address fieldShippingAddress;
35     protected String JavaDoc fieldUserName;
36     
37     /**
38      * Creates a customer that uses the given user to store its information.
39      * @param inUser
40      */

41     public Customer(User inUser)
42     {
43         fieldUser = inUser;
44     }
45     
46     public Customer()
47     {
48          FileSystemUser user = new FileSystemUser();
49          fieldUser = user;
50     }
51     public User getUser()
52     {
53         return fieldUser;
54     }
55     
56     public String JavaDoc getUserName()
57     {
58         return getUser().getUserName();
59     }
60     
61     public String JavaDoc getFirstName()
62     {
63         return getUser().getFirstName();
64     }
65     
66     public void setFirstName( String JavaDoc inFirstName )
67     {
68         getUser().setFirstName( inFirstName );
69     }
70     
71     public String JavaDoc getLastName()
72     {
73         return getUser().getLastName();
74     }
75     
76     public void setLastName( String JavaDoc inLastName )
77     {
78         getUser().setLastName( inLastName );
79     }
80     
81     public String JavaDoc getEmail()
82     {
83         return getUser().getEmail();
84     }
85     
86     public void setEmail( String JavaDoc inEmail )
87     {
88         getUser().setEmail( inEmail );
89     }
90     
91     public String JavaDoc getPassword()
92     {
93         return getUser().getPassword();
94     }
95     
96     public boolean isAllowEmail()
97     {
98         return getUser().getBoolean(ALLOW_EMAIL);
99     }
100
101     public void setAllowEmail(boolean inValue)
102     {
103         getUser().safePut(ALLOW_EMAIL,String.valueOf(inValue));
104     }
105     
106     public String JavaDoc getTaxExemptId()
107     {
108         return getUser().getString(TAX_EXEMPT_ID);
109     }
110
111     public void setTaxExemptId(String JavaDoc inString)
112     {
113         getUser().safePut(TAX_EXEMPT_ID, inString);
114     }
115
116     public String JavaDoc getName()
117     {
118         return getFirstName() + " " + getLastName();
119     }
120     
121     public PaymentMethod getPaymentMethod()
122     {
123         return fieldPaymentMethod;
124     }
125     
126     public void setPaymentMethod(PaymentMethod inPaymentMethod)
127     {
128         fieldPaymentMethod = inPaymentMethod;
129     }
130     
131     public String JavaDoc getPhone1()
132     {
133         return getUser().getString(PHONE1);
134     }
135     
136     public void setPhone1(String JavaDoc inPhone1)
137     {
138         getUser().safePut(PHONE1, inPhone1);
139     }
140
141     public String JavaDoc getCompany()
142     {
143         return getUser().getString( COMPANY );
144     }
145     
146     public void setCompany( String JavaDoc inCompany )
147     {
148         getUser().safePut( COMPANY, inCompany );
149     }
150
151     public Fraction getTaxRate()
152     {
153         String JavaDoc taxRateString = getUser().getString(TAX_RATE);
154         if (taxRateString == null)
155         {
156             taxRateString = Fraction.ZERO.toString();
157             getUser().safePut(TAX_RATE, taxRateString);
158         }
159         return new Fraction(taxRateString);
160     }
161
162     public void setTaxRate(Fraction inTaxRate)
163     {
164         if (inTaxRate == null)
165         {
166             inTaxRate = Fraction.ZERO;
167         }
168         getUser().safePut(TAX_RATE, inTaxRate.toString());
169     }
170
171     public String JavaDoc getReferenceNumber()
172     {
173         return getUser().getString(REFERENCE);
174     }
175     public void setReferenceNumber(String JavaDoc inReferenceNumber)
176     {
177         getUser().safePut(REFERENCE,inReferenceNumber);
178     }
179     public String JavaDoc getTitle()
180     {
181         return getUser().getString(TITLE);
182     }
183     public void setTitle(String JavaDoc inTitle)
184     {
185         getUser().safePut(TITLE, inTitle);
186     }
187     //See UserManagerModule.clean
188
public String JavaDoc cleanPhoneNumber()
189     {
190         String JavaDoc phoneNumber = getPhone1();
191         if ( phoneNumber != null )
192         {
193             StringBuffer JavaDoc out = new StringBuffer JavaDoc();
194             for (int i = 0; i < phoneNumber.length(); i++)
195             {
196                 if ( Character.isDigit(phoneNumber.charAt(i)))
197                 {
198                     out.append(phoneNumber.charAt(i));
199                 }
200             }
201             phoneNumber = out.toString();
202         }
203         return phoneNumber;
204     }
205
206     public Address getBillingAddress()
207     {
208         if ( fieldBillingAddress == null )
209         {
210             fieldBillingAddress = new Address(getUser());
211             fieldBillingAddress.setPrefix("billing."); //only used to store the data
212
}
213         return fieldBillingAddress;
214     }
215
216     public void setBillingAddress(Address inAddress)
217     {
218         fieldBillingAddress = inAddress;
219     }
220     public Address getShippingAddress()
221     {
222         if ( fieldShippingAddress == null )
223         {
224             fieldShippingAddress = new Address(getUser());
225             fieldShippingAddress.setPrefix("");
226         }
227         return fieldShippingAddress;
228     }
229     public void setShippingAddress(Address inShippingAddress)
230     {
231         fieldShippingAddress = inShippingAddress;
232     }
233     public String JavaDoc getFax()
234     {
235         return getUser().getString(FAX);
236     }
237     public void setFax(String JavaDoc inFax)
238     {
239         getUser().safePut(FAX, inFax);
240     }
241     
242     public String JavaDoc getUserField1()
243     {
244         return getUser().getString( USERFIELD1 );
245     }
246     
247     public void setUserField1( String JavaDoc inUserField1 )
248     {
249         getUser().safePut( USERFIELD1, inUserField1 );
250     }
251     
252     public String JavaDoc getUserField2()
253     {
254         return getUser().getString( USERFIELD2 );
255     }
256     
257     public void setUserField2( String JavaDoc inUserField2 )
258     {
259         getUser().safePut( USERFIELD2, inUserField2 );
260     }
261     
262     public void setUserName(String JavaDoc inUserName)
263     {
264         getUser().setUserName(inUserName);
265     }
266
267     public void setPassword(String JavaDoc inPassword)
268     {
269         getUser().setPassword(inPassword);
270     }
271 }
272
Popular Tags