KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > runtime > colocated > GenClass_C


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23 package org.objectweb.jorm.runtime.colocated;
24
25 import org.objectweb.jorm.api.PIndexedElem;
26 import org.objectweb.jorm.api.PException;
27 import org.objectweb.jorm.api.PGenClassAccessor;
28 import org.objectweb.jorm.api.PAccessor;
29 import org.objectweb.jorm.naming.api.PName;
30
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.Date JavaDoc;
35 import java.io.Serializable JavaDoc;
36 import java.math.BigDecimal JavaDoc;
37 import java.math.BigInteger JavaDoc;
38
39 import junit.framework.Assert;
40
41 /**
42  *
43  * @author S.Chassande-Barrioz
44  */

45 public class GenClass_C implements PGenClassAccessor {
46
47     public List JavaDoc elements;
48     public int expectedSize;
49
50     public GenClass_C(List JavaDoc pnames) {
51         elements = new ArrayList JavaDoc(pnames.size());
52         for(int i=0; i<pnames.size(); i++) {
53             elements.add(new RefElement((PName) pnames.get(i)));
54         }
55         expectedSize = elements.size();
56     }
57
58     public GenClass_C(int expectedsize) {
59         expectedSize = expectedsize;
60         elements = new ArrayList JavaDoc();
61     }
62
63     public boolean equals(Object JavaDoc obj) {
64         Assert.assertNotNull("null object", obj);
65         Assert.assertEquals("Bad class", obj.getClass(), getClass());
66         GenClass_C o = (GenClass_C) obj;
67         Assert.assertEquals("Bad size", elements.size(), o.elements.size());
68         for(int i=0; i<elements.size(); i++) {
69             Assert.assertTrue("Expected element <"
70                 + ((RefElement) elements.get(i)).element
71                 + "> is not present: in " + o.elements,
72                 o.elements.contains(elements.get(i)));
73         }
74         for(int i=0; i<o.elements.size(); i++) {
75             Assert.assertTrue("Unexpected element <"
76                 + ((RefElement) o.elements.get(i)).element
77                 + "> is present",
78                 elements.contains(o.elements.get(i)));
79         }
80         return true;
81     }
82
83     // IMPLEMENTATION OF THE PGenClassAccessor INTERFACE //
84
//---------------------------------------------------//
85

86     public void paAdd(PIndexedElem elem, Object JavaDoc conn) throws PException {
87         elements.add(elem);
88     }
89
90     public boolean paDeltaSupported() {
91         return true;
92     }
93
94     public int paGetNbElem() {
95         return elements.size();
96     }
97
98     public Iterator JavaDoc paIterator() {
99         return elements.iterator();
100     }
101
102     public void paSetNbElem(int nbelem) {
103         if (nbelem != -1) {
104             Assert.assertEquals("Bad expected size", expectedSize, nbelem);
105         }
106         elements.clear();
107     }
108
109     public PIndexedElem createPIndexedElem() throws PException {
110         return new RefElement();
111     }
112
113
114     // IMPLEMENTATION OF THE PGenClassAccessor INTERFACE //
115
//---------------------------------------------------//
116

117     public Object JavaDoc getMemoryInstance() {
118         return this;
119     }
120
121
122     // INNER CLASS IMPLEMENTING THE PIndexedElem INTERFACE //
123
//-----------------------------------------------------//
124

125     public class RefElement implements PIndexedElem {
126         public byte status;
127         public PName element;
128
129         public RefElement() {
130             status = PIndexedElem.ELEM_UNMODIFIED;
131         }
132
133         public RefElement(PName element) {
134             this.status = PIndexedElem.ELEM_CREATED;
135             this.element = element;
136         }
137
138         public RefElement(byte status, PName element) {
139             this.status = status;
140             this.element = element;
141         }
142
143         public boolean equals(Object JavaDoc obj) {
144             return element.equals(((RefElement) obj).element);
145         }
146
147         public String JavaDoc toString() {
148             return "RefElemen(" + element.toString() + ")";
149         }
150
151         public byte getElemStatus() {
152             return status;
153         }
154
155         public void pieSetRefElem(PName value) throws PException {
156             element = value;
157         }
158
159         public PName pieGetRefElem() throws PException {
160             return element;
161         }
162
163         public boolean pieGetBooleanElem() throws PException {
164             Assert.fail("The element is a reference");
165             return false;
166         }
167
168         public Boolean JavaDoc pieGetObooleanElem() throws PException {
169             Assert.fail("The element is a reference");
170             return null;
171         }
172
173         public byte pieGetByteElem() throws PException {
174             Assert.fail("The element is a reference");
175             return 0;
176         }
177
178         public Byte JavaDoc pieGetObyteElem() throws PException {
179             Assert.fail("The element is a reference");
180             return null;
181         }
182
183         public byte pieGetByteIndexField(String JavaDoc fn) throws PException {
184             Assert.fail("There is no index");
185             return 0;
186         }
187
188         public Byte JavaDoc pieGetObyteIndexField(String JavaDoc fn) throws PException {
189             Assert.fail("There is no index");
190             return null;
191         }
192
193         public char pieGetCharElem() throws PException {
194             Assert.fail("The element is a reference");
195             return 0;
196         }
197
198         public Character JavaDoc pieGetOcharElem() throws PException {
199             Assert.fail("The element is a reference");
200             return null;
201         }
202
203         public char pieGetCharIndexField(String JavaDoc fn) throws PException {
204             Assert.fail("There is no index");
205             return 0;
206         }
207
208         public Character JavaDoc pieGetOcharIndexField(String JavaDoc fn) throws PException {
209             Assert.fail("There is no index");
210             return null;
211         }
212
213         public short pieGetShortElem() throws PException {
214             Assert.fail("The element is a reference");
215             return 0;
216         }
217
218         public Short JavaDoc pieGetOshortElem() throws PException {
219             Assert.fail("The element is a reference");
220             return null;
221         }
222
223         public short pieGetShortIndexField(String JavaDoc fn) throws PException {
224             Assert.fail("There is no index");
225             return 0;
226         }
227
228         public Short JavaDoc pieGetOshortIndexField(String JavaDoc fn) throws PException {
229             Assert.fail("There is no index");
230             return null;
231         }
232
233         public int pieGetIntElem() throws PException {
234             Assert.fail("The element is a reference");
235             return 0;
236         }
237
238         public Integer JavaDoc pieGetOintElem() throws PException {
239             Assert.fail("The element is a reference");
240             return null;
241         }
242
243         public int pieGetIntIndexField(String JavaDoc fn) throws PException {
244             Assert.fail("There is no index");
245             return 0;
246         }
247
248         public Integer JavaDoc pieGetOintIndexField(String JavaDoc fn) throws PException {
249             Assert.fail("There is no index");
250             return null;
251         }
252
253         public long pieGetLongElem() throws PException {
254             Assert.fail("The element is a reference");
255             return 0;
256         }
257
258         public Long JavaDoc pieGetOlongElem() throws PException {
259             Assert.fail("The element is a reference");
260             return null;
261         }
262
263         public long pieGetLongIndexField(String JavaDoc fn) throws PException {
264             Assert.fail("There is no index");
265             return 0;
266         }
267
268         public Long JavaDoc pieGetOlongIndexField(String JavaDoc fn) throws PException {
269             Assert.fail("There is no index");
270             return null;
271         }
272
273         public float pieGetFloatElem() throws PException {
274             Assert.fail("The element is a reference");
275             return 0;
276         }
277
278         public Float JavaDoc pieGetOfloatElem() throws PException {
279             Assert.fail("The element is a reference");
280             return null;
281         }
282
283         public double pieGetDoubleElem() throws PException {
284             Assert.fail("The element is a reference");
285             return 0;
286         }
287
288         public Double JavaDoc pieGetOdoubleElem() throws PException {
289             Assert.fail("The element is a reference");
290             return null;
291         }
292
293         public String JavaDoc pieGetStringElem() throws PException {
294             Assert.fail("The element is a reference");
295             return null;
296         }
297
298         public String JavaDoc pieGetStringIndexField(String JavaDoc fn) throws PException {
299             Assert.fail("There is no index");
300             return null;
301         }
302
303         public Date JavaDoc pieGetDateElem() throws PException {
304             Assert.fail("The element is a reference");
305             return null;
306         }
307
308         public Date JavaDoc pieGetDateIndexField(String JavaDoc fn) throws PException {
309             Assert.fail("There is no index");
310             return null;
311         }
312
313         public char[] pieGetCharArrayElem() throws PException {
314             Assert.fail("The element is a reference");
315             return new char[0];
316         }
317
318         public byte[] pieGetByteArrayElem() throws PException {
319             Assert.fail("The element is a reference");
320             return new byte[0];
321         }
322
323         public Serializable JavaDoc pieGetSerializedElem() throws PException {
324             Assert.fail("The element is a reference");
325             return null;
326         }
327
328         public BigDecimal JavaDoc pieGetBigDecimalElem() throws PException {
329             Assert.fail("The element is a reference");
330             return null;
331         }
332
333         public BigInteger JavaDoc pieGetBigIntegerElem() throws PException {
334             Assert.fail("The element is a reference");
335             return null;
336         }
337
338         public void pieSetBooleanElem(boolean value) throws PException {
339             Assert.fail("The element is a reference");
340         }
341
342         public void pieSetObooleanElem(Boolean JavaDoc value) throws PException {
343             Assert.fail("The element is a reference");
344         }
345
346         public void pieSetByteElem(byte value) throws PException {
347             Assert.fail("The element is a reference");
348         }
349
350         public void pieSetObyteElem(Byte JavaDoc value) throws PException {
351             Assert.fail("The element is a reference");
352         }
353
354         public void pieSetByteIndexField(String JavaDoc fn, byte value) throws PException {
355             Assert.fail("There is no index");
356         }
357
358         public void pieSetObyteIndexField(String JavaDoc fn, Byte JavaDoc value) throws PException {
359             Assert.fail("There is no index");
360         }
361
362         public void pieSetCharElem(char value) throws PException {
363             Assert.fail("The element is a reference");
364         }
365
366         public void pieSetOcharElem(Character JavaDoc value) throws PException {
367             Assert.fail("The element is a reference");
368         }
369
370         public void pieSetCharIndexField(String JavaDoc fn, char value) throws PException {
371             Assert.fail("There is no index");
372         }
373
374         public void pieSetOcharIndexField(String JavaDoc fn, Character JavaDoc value) throws PException {
375             Assert.fail("There is no index");
376         }
377
378         public void pieSetShortElem(short value) throws PException {
379             Assert.fail("The element is a reference");
380         }
381
382         public void pieSetOshortElem(Short JavaDoc value) throws PException {
383             Assert.fail("The element is a reference");
384         }
385
386         public void pieSetShortIndexField(String JavaDoc fn, short value) throws PException {
387             Assert.fail("There is no index");
388         }
389
390         public void pieSetOshortIndexField(String JavaDoc fn, Short JavaDoc value) throws PException {
391             Assert.fail("There is no index");
392         }
393
394         public void pieSetIntElem(int value) throws PException {
395             Assert.fail("The element is a reference");
396         }
397
398         public void pieSetOintElem(Integer JavaDoc value) throws PException {
399             Assert.fail("The element is a reference");
400         }
401
402         public void pieSetIntIndexField(String JavaDoc fn, int value) throws PException {
403             Assert.fail("There is no index");
404         }
405
406         public void pieSetOintIndexField(String JavaDoc fn, Integer JavaDoc value) throws PException {
407             Assert.fail("There is no index");
408         }
409
410         public void pieSetLongElem(long value) throws PException {
411             Assert.fail("The element is a reference");
412         }
413
414         public void pieSetOlongElem(Long JavaDoc value) throws PException {
415             Assert.fail("The element is a reference");
416         }
417
418         public void pieSetLongIndexField(String JavaDoc fn, long value) throws PException {
419             Assert.fail("There is no index");
420         }
421
422         public void pieSetOlongIndexField(String JavaDoc fn, Long JavaDoc value) throws PException {
423             Assert.fail("There is no index");
424         }
425
426         public void pieSetFloatElem(float value) throws PException {
427             Assert.fail("The element is a reference");
428         }
429
430         public void pieSetOfloatElem(Float JavaDoc value) throws PException {
431             Assert.fail("The element is a reference");
432         }
433
434         public void pieSetDoubleElem(double value) throws PException {
435             Assert.fail("The element is a reference");
436         }
437
438         public void pieSetOdoubleElem(Double JavaDoc value) throws PException {
439             Assert.fail("The element is a reference");
440         }
441
442         public void pieSetStringElem(String JavaDoc value) throws PException {
443             Assert.fail("The element is a reference");
444         }
445
446         public void pieSetStringIndexField(String JavaDoc fn, String JavaDoc value) throws PException {
447             Assert.fail("There is no index");
448         }
449
450         public void pieSetDateElem(Date JavaDoc value) throws PException {
451             Assert.fail("The element is a reference");
452         }
453
454         public void pieSetDateIndexField(String JavaDoc fn, Date JavaDoc value) throws PException {
455             Assert.fail("There is no index");
456         }
457
458         public void pieSetCharArrayElem(char[] value) throws PException {
459             Assert.fail("The element is a reference");
460         }
461
462         public void pieSetByteArrayElem(byte[] value) throws PException {
463             Assert.fail("The element is a reference");
464         }
465
466         public void pieSetSerializedElem(Serializable JavaDoc value) throws PException {
467             Assert.fail("The element is a reference");
468         }
469
470         public void pieSetBigDecimalElem(BigDecimal JavaDoc value) throws PException {
471             Assert.fail("The element is a reference");
472         }
473
474         public void pieSetBigIntegerElem(BigInteger JavaDoc value) throws PException {
475             Assert.fail("The element is a reference");
476         }
477     }
478 }
479
Popular Tags