KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
31
32 public class DVD implements Serializable JavaDoc {
33     private DVD() {
34     }
35
36     private DVD(String JavaDoc title, int price, String JavaDoc author) {
37         this.title = title;
38         this.price = price;
39         this.director = author;
40     }
41
42     public String JavaDoc getDirector() {
43         return director;
44     }
45
46     public void setDirector(String JavaDoc director) {
47         this.director = director;
48     }
49
50     public int getPrice() {
51         return price;
52     }
53
54     public void setPrice(int price) {
55         this.price = price;
56     }
57
58     public String JavaDoc getTitle() {
59         return title;
60     }
61
62     public void setTitle(String JavaDoc title) {
63         this.title = title;
64     }
65
66     public static DVD newDVD() {
67         counter++;
68         return new DVD(getNewTitle(counter),
69                        getNewPrice(counter),
70                        getNewDirector(counter));
71     }
72
73     public Object JavaDoc[] toArray() {
74         Object JavaDoc[] result = new Object JavaDoc[3];
75         result[0] = title;
76         result[1] = new Integer JavaDoc(price);
77         result[2] = director;
78         return result;
79     }
80
81     public String JavaDoc toString() {
82         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
83         sb.append("'").append(title);
84         sb.append("from ").append(director).append(", ");
85         sb.append(price).append(" E");
86         sb.append("'");
87         return sb.toString();
88     }
89
90     public static DVD toDVD(Object JavaDoc[] array) {
91         DVD dvd = new DVD();
92         dvd.setTitle((String JavaDoc) array[0]);
93         dvd.setPrice(((Integer JavaDoc) array[1]).intValue());
94         dvd.setDirector((String JavaDoc) array[2]);
95         return dvd;
96     }
97
98     public static ClassDescription getMetaDescription() {
99         ClassDescription meta = JalistoFactory.createClassDescription(DVD.class.getName());
100         meta.addField(JalistoFactory.createFieldDescription("title", MetaTypeFactory.StringType));
101         meta.addField(JalistoFactory.createFieldDescription("price", MetaTypeFactory.IntegerType));
102         meta.addField(JalistoFactory.createFieldDescription("director", MetaTypeFactory.StringType));
103         meta.setLeafPageSize(0, (short) 3);
104         meta.setNodePageSize(0, (short) 2);
105         meta.setNodeSize(0, (short) 4);
106         return meta;
107     }
108
109     private static String JavaDoc getNewTitle(int c) {
110         return titles[c % titles.length];
111     }
112
113     private static String JavaDoc getNewDirector(int c) {
114         return directors[c % directors.length];
115     }
116
117     private static int getNewPrice(int c) {
118         return prices[c % prices.length];
119     }
120
121     private String JavaDoc title;
122     private int price;
123     private String JavaDoc director;
124
125     public static int counter = -1;
126     public static final String JavaDoc[] titles = {"The Pianist",
127                                            "The Right Stuff",
128                                            "Dr. Quinn Medicine Woman",
129                                            "Throne of Blood",
130                                            "About Schmidt",
131                                            "A Guy Thing",
132                                            "Sex and the City",
133                                            "Miller's Crossing",
134                                            "The Animatrix",
135                                            "Dark Blue"};
136     public static final int[] prices = {5,
137                                         10,
138                                         15,
139                                         20,
140                                         25,
141                                         30};
142     public static final String JavaDoc[] directors = {"Roman Polanski",
143                                               "Toshiro Mifune",
144                                               "Luc Besson",
145                                               "Kevin Costner"};
146
147     static final long serialVersionUID = -7589377099514765159L;
148 }
149
Popular Tags