KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.ArrayList JavaDoc;
31
32 public class Library {
33
34     private Library(String JavaDoc address, ArrayList JavaDoc clients, ArrayList JavaDoc books) {
35         this.address = address;
36         this.clients = clients;
37         this.books = books;
38     }
39
40     public String JavaDoc getAddress() {
41         return address;
42     }
43
44     public void setAddress(String JavaDoc address) {
45         this.address = address;
46     }
47
48     public ArrayList JavaDoc getBooks() {
49         return books;
50     }
51
52     public void setBooks(ArrayList JavaDoc books) {
53         this.books = books;
54     }
55
56     public ArrayList JavaDoc getClients() {
57         return clients;
58     }
59
60     public void setClients(ArrayList JavaDoc clients) {
61         this.clients = clients;
62     }
63
64     public Object JavaDoc getAuthorMostWanted() {
65         return authorMostWanted;
66     }
67
68     public void setAuthorMostWanted(Object JavaDoc authorMostWantedOid) {
69         this.authorMostWanted = authorMostWantedOid;
70     }
71
72
73     public Object JavaDoc[] toArray() {
74         Object JavaDoc[] result = new Object JavaDoc[4];
75         result[0] = address;
76         result[1] = clients;
77         result[2] = books;
78         result[3] = authorMostWanted;
79         return result;
80     }
81
82     public static Library toLibrary(Object JavaDoc[] array) {
83         Library library = new Library(
84                 (String JavaDoc) array[0],
85                 (ArrayList JavaDoc) array[1],
86                 (ArrayList JavaDoc) array[2]);
87         library.setAuthorMostWanted(array[3]);
88         return library;
89     }
90
91
92     private String JavaDoc address;
93     private ArrayList JavaDoc clients;
94     private ArrayList JavaDoc books;
95     private Object JavaDoc authorMostWanted;
96
97
98     public static Library newLibrary() {
99         counter++;
100         return new Library(getNewAddress(counter),
101                            new ArrayList JavaDoc(),
102                            new ArrayList JavaDoc());
103     }
104
105     private static String JavaDoc getNewAddress(int c) {
106         return addresses[c % addresses.length];
107     }
108
109     public static ClassDescription getMetaDescription() {
110         ClassDescription meta = JalistoFactory.createClassDescription(Library.class.getName());
111         meta.addField(JalistoFactory.createFieldDescription("address", MetaTypeFactory.StringType));
112         meta.addField(JalistoFactory.createFieldDescription("clients", MetaTypeFactory.CollectionType));
113         meta.addField(JalistoFactory.createFieldDescription("books", MetaTypeFactory.CollectionType));
114         meta.addField(JalistoFactory.createFieldDescription("authorMostWanted", MetaTypeFactory.LinkType));
115         return meta;
116     }
117
118     public static int counter = -1;
119     public static final String JavaDoc[] addresses = {"36 rue de picpus",
120                                               "107 rue de reuilly",
121                                               "20 rue de dante",
122                                               "15 impasse de l'enfer"};
123
124     static final long serialVersionUID = -7589377092222761459L;
125 }
126
Popular Tags