KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > examples > beans > Customers


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.standard.examples.beans;
18
19 import java.util.*;
20 import java.text.*;
21
22 /**
23  * Customers Datastore.
24  *
25  * @author Pierre Delisle
26  * @version $Revision: 1.3 $ $Date: 2004/02/28 01:01:41 $
27  */

28
29 public class Customers {
30     
31     //*********************************************************************
32
// Instance variables
33

34     private static Vector customers = new Vector();
35     private static int nextSeqNo = 0;
36     
37     //*********************************************************************
38
// Datastore operations
39

40     public static void create(
41     String JavaDoc lastName,
42     String JavaDoc firstName,
43     String JavaDoc birthDate,
44     String JavaDoc line1,
45     String JavaDoc line2,
46     String JavaDoc city,
47     String JavaDoc state,
48     String JavaDoc zip,
49     String JavaDoc country) {
50         create(lastName, firstName, birthDate, line1, line2, city, state, zip,
51         country, null, null);
52     }
53     
54     /**
55      * Create new customer
56      */

57     public static void create(
58     String JavaDoc lastName,
59     String JavaDoc firstName,
60     String JavaDoc birthDate,
61     String JavaDoc line1,
62     String JavaDoc line2,
63     String JavaDoc city,
64     String JavaDoc state,
65     String JavaDoc zip,
66     String JavaDoc country,
67     String JavaDoc phoneHome,
68     String JavaDoc phoneCell) {
69         Customer customer =
70         new Customer(++nextSeqNo, lastName, firstName,
71         genDate(birthDate), genAddress(line1, line2, city, state, zip, country),
72         phoneHome, phoneCell);
73         customers.add(customer);
74     }
75     
76     /**
77      * Find all customers
78      */

79     public static Collection findAll() {
80         return customers;
81     }
82     
83     //*********************************************************************
84
// Utility methods
85

86     private static Date genDate(String JavaDoc dateString) {
87         DateFormat df = new SimpleDateFormat("M/d/y");
88         Date date;
89         try {
90             date = df.parse(dateString);
91         } catch (Exception JavaDoc ex) {
92             date = null;
93         }
94         return date;
95     }
96     
97     private static Address genAddress(String JavaDoc line1, String JavaDoc line2, String JavaDoc city,
98     String JavaDoc state, String JavaDoc zip, String JavaDoc country) {
99         return new Address(line1, line2, city, state, zip, country);
100     }
101 }
102
Popular Tags