KickJava   Java API By Example, From Geeks To Geeks.

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


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 Author {
31
32     private Author() {
33     }
34
35     private Author(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             Author candidate = (Author) 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 String JavaDoc toString() {
67         return "Author : " + firstName + " " + lastName;
68     }
69
70     public Object JavaDoc[] toArray() {
71         Object JavaDoc[] result = new Object JavaDoc[2];
72         result[0] = firstName;
73         result[1] = lastName;
74         return result;
75     }
76
77     public static Author toAuthor(Object JavaDoc[] array) {
78         Author author = new Author();
79         author.setFirstName((String JavaDoc) array[0]);
80         author.setLastName((String JavaDoc) array[1]);
81         return author;
82     }
83
84     public static ClassDescription getMetaDescription() {
85         ClassDescription meta = JalistoFactory.createClassDescription(Author.class.getName());
86         meta.addField(JalistoFactory.createFieldDescription("firstName", MetaTypeFactory.StringType));
87         meta.addField(JalistoFactory.createFieldDescription("lastName", MetaTypeFactory.StringType));
88         return meta;
89     }
90
91     public static Author newAuthor() {
92         counter++;
93         return new Author(getNewFirstName(counter), getNewLastName(counter));
94     }
95
96     private static String JavaDoc getNewFirstName(int c) {
97         return firstNames[c % firstNames.length];
98     }
99
100     private static String JavaDoc getNewLastName(int c) {
101         return lastNames[c % lastNames.length];
102     }
103
104     private String JavaDoc firstName;
105     private String JavaDoc lastName;
106
107     public static int counter = -1;
108
109     public static final String JavaDoc[] firstNames = {"James",
110                                                "John",
111                                                "Robert",
112                                                "Andy"};
113
114     public static final String JavaDoc[] lastNames = {"McManus",
115                                               "Sandford",
116                                               "Dallek",
117                                               "Andrews"};
118 }
119
Popular Tags