KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > impl > server > page > Page


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.impl.server.page;
25
26 import org.objectweb.jalisto.se.api.internal.JalistoObject;
27 import org.objectweb.jalisto.se.impl.InFileAddress;
28
29 public abstract class Page implements JalistoObject {
30
31     public Page(int size) {
32         storedDatas = new Object JavaDoc[size];
33     }
34
35     public boolean isEmpty() {
36         for (short i = 0; i < storedDatas.length; i++) {
37             if (storedDatas[i] != null) {
38                 return false;
39             }
40         }
41         return true;
42     }
43
44     public Object JavaDoc[] getAllDatas() {
45         return storedDatas;
46     }
47
48     public void setData(Object JavaDoc data) {
49     }
50
51     public Object JavaDoc getData() {
52         return storedDatas;
53     }
54
55     public void setDataAt(InFileAddress dataIfa, Object JavaDoc dataToInsert) {
56         storedDatas[dataIfa.getIndex()] = dataToInsert;
57     }
58
59     public void setDataAt(int index, Object JavaDoc dataToInsert) {
60         storedDatas[index] = dataToInsert;
61     }
62
63     public Object JavaDoc getDataAt(InFileAddress dataIfa) {
64         return storedDatas[dataIfa.getIndex()];
65     }
66
67     public Object JavaDoc getDataAt(int index) {
68         return storedDatas[index];
69     }
70
71     public void setIfa(InFileAddress ifa) {
72         this.ifa = ifa.getClone();
73     }
74
75     public InFileAddress getIfa() {
76         return ifa;
77     }
78
79     public int getSize() {
80         return storedDatas.length;
81     }
82
83     public JalistoObject internalClone(Page clone) {
84         clone.setIfa(ifa.getClone());
85         System.arraycopy(storedDatas, 0, clone.storedDatas, 0, storedDatas.length);
86         return clone;
87     }
88
89     public String JavaDoc toString() {
90         if (ifa != null) {
91             return pageName() + "@" + String.valueOf(ifa) + ":" + dataToString();
92         } else {
93             return pageName() + ":" + dataToString();
94         }
95     }
96
97     private String JavaDoc dataToString() {
98         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
99         sb.append("[");
100         for (int i = 0; i < storedDatas.length; i++) {
101             if (storedDatas[i] == null) {
102                 sb.append("null");
103             } else {
104                 sb.append(storedDatas[i]);
105             }
106             if (i != (storedDatas.length - 1)) {
107                 sb.append(";");
108             }
109         }
110         sb.append("]");
111         return sb.toString();
112     }
113
114     protected String JavaDoc pageName() {
115         return "P";
116     }
117
118
119     protected Object JavaDoc[] storedDatas;
120     protected transient InFileAddress ifa;
121
122
123     static final long serialVersionUID = -7589377099514761459L;
124
125
126     public static final short CLASSPAGE_TYPE = 0;
127     public static final short INSTANCEPAGE_TYPE = 1;
128     public static final short OIDPAGE_TYPE = 2;
129     public static final short SYSTEMPAGE_TYPE = 3;
130     public static final short NODEPAGE_TYPE = 4;
131     public static final short LEAFPAGE_TYPE = 5;
132 }
133
Popular Tags