KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > test > data > Client


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.test.data;
25
26 import org.objectweb.jalisto.se.api.ClassDescription;
27 import org.objectweb.jalisto.se.JalistoFactory;
28 import org.objectweb.jalisto.se.impl.meta.type.MetaTypeFactory;
29
30 public class Client {
31
32     private Client() {
33     }
34
35     private Client(String JavaDoc firstName, String JavaDoc lastName) {
36         this.firstName = firstName;
37         this.lastName = lastName;
38     }
39
40     public String JavaDoc getFirstName() {
41         return firstName;
42     }
43
44     public void setFirstName(String JavaDoc firstName) {
45         this.firstName = firstName;
46     }
47
48     public String JavaDoc getLastName() {
49         return lastName;
50     }
51
52     public void setLastName(String JavaDoc lastName) {
53         this.lastName = lastName;
54     }
55
56     public boolean equals(Object JavaDoc o) {
57         try {
58             Client candidate = (Client) o;
59             return (candidate.firstName.equals(firstName) &&
60                     candidate.lastName.equals(lastName));
61         } catch (Exception JavaDoc e) {
62         }
63         return false;
64     }
65
66     public Object JavaDoc[] toArray() {
67         Object JavaDoc[] result = new Object JavaDoc[2];
68         result[0] = firstName;
69         result[1] = lastName;
70         return result;
71     }
72
73     public static Client toClient(Object JavaDoc[] array) {
74         Client client = new Client();
75         client.setFirstName((String JavaDoc) array[0]);
76         client.setLastName((String JavaDoc) array[1]);
77         return client;
78     }
79
80     public static ClassDescription getMetaDescription() {
81         ClassDescription meta = JalistoFactory.createClassDescription(Client.class.getName());
82         meta.addField(JalistoFactory.createFieldDescription("firstName", MetaTypeFactory.StringType));
83         meta.addField(JalistoFactory.createFieldDescription("lastName", MetaTypeFactory.StringType));
84         return meta;
85     }
86
87     public static Client newClient() {
88         counter++;
89         return new Client(getNewFirstName(counter), getNewLastName(counter));
90     }
91
92     private static String JavaDoc getNewFirstName(int c) {
93         return firstNames[c % firstNames.length];
94     }
95
96     private static String JavaDoc getNewLastName(int c) {
97         return lastNames[c % lastNames.length];
98     }
99
100     private String JavaDoc firstName;
101     private String JavaDoc lastName;
102
103     public static int counter = -1;
104
105     public static final String JavaDoc[] firstNames = {"Katharina",
106                                                "Sigourney",
107                                                "Winona",
108                                                "Jody",
109                                                "Famke"};
110
111     public static final String JavaDoc[] lastNames = {"Hepburn",
112                                               "Weaver",
113                                               "Rider",
114                                               "Foster",
115                                               "Janssen",
116                                               "Seymour",
117                                               "Scott Thommas",
118                                               "Harlow",
119                                               "Kruegger",
120                                               "Sastre",
121                                               "Pfeiffer",
122                                               "Jovovitch",
123                                               "Valetta"};
124 }
125
Popular Tags