KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > GenericFieldManager


1 /*
2  * Copyright 2004 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: GenericFieldManager.java,v 1.1 2004/01/18 03:01:05 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo;
12
13 import com.triactive.jdo.FieldManager;
14
15
16 /**
17  * An abstract base class for a field manager that deals with all fields as
18  * generic Objects.
19  * All the type-specific field manager methods (for primitives and Strings) are
20  * funneled to fetchObjectField() and storeObjectField() and primitive values
21  * are boxed/unboxed as needed.
22  *
23  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
24  * @version $Revision: 1.1 $
25  */

26
27 public abstract class GenericFieldManager implements FieldManager
28 {
29     public void storeBooleanField(int field, boolean value)
30     {
31         storeObjectField(field, new Boolean JavaDoc(value));
32     }
33
34     public boolean fetchBooleanField(int field)
35     {
36         Boolean JavaDoc value = (Boolean JavaDoc)fetchObjectField(field);
37         return value == null ? false : value.booleanValue();
38     }
39
40     public void storeCharField(int field, char value)
41     {
42         storeObjectField(field, new Character JavaDoc(value));
43     }
44
45     public char fetchCharField(int field)
46     {
47         Character JavaDoc value = (Character JavaDoc)fetchObjectField(field);
48         return value == null ? '\000' : value.charValue();
49     }
50
51     public void storeByteField(int field, byte value)
52     {
53         storeObjectField(field, new Byte JavaDoc(value));
54     }
55
56     public byte fetchByteField(int field)
57     {
58         Number JavaDoc value = (Number JavaDoc)fetchObjectField(field);
59         return value == null ? 0 : value.byteValue();
60     }
61
62     public void storeShortField(int field, short value)
63     {
64         storeObjectField(field, new Short JavaDoc(value));
65     }
66
67     public short fetchShortField(int field)
68     {
69         Number JavaDoc value = (Number JavaDoc)fetchObjectField(field);
70         return value == null ? 0 : value.shortValue();
71     }
72
73     public void storeIntField(int field, int value)
74     {
75         storeObjectField(field, new Integer JavaDoc(value));
76     }
77
78     public int fetchIntField(int field)
79     {
80         Number JavaDoc value = (Number JavaDoc)fetchObjectField(field);
81         return value == null ? 0 : value.intValue();
82     }
83
84     public void storeLongField(int field, long value)
85     {
86         storeObjectField(field, new Long JavaDoc(value));
87     }
88
89     public long fetchLongField(int field)
90     {
91         Number JavaDoc value = (Number JavaDoc)fetchObjectField(field);
92         return value == null ? 0 : value.longValue();
93     }
94
95     public void storeFloatField(int field, float value)
96     {
97         storeObjectField(field, new Float JavaDoc(value));
98     }
99
100     public float fetchFloatField(int field)
101     {
102         Number JavaDoc value = (Number JavaDoc)fetchObjectField(field);
103         return value == null ? 0 : value.floatValue();
104     }
105
106     public void storeDoubleField(int field, double value)
107     {
108         storeObjectField(field, new Double JavaDoc(value));
109     }
110
111     public double fetchDoubleField(int field)
112     {
113         Number JavaDoc value = (Number JavaDoc)fetchObjectField(field);
114         return value == null ? 0 : value.doubleValue();
115     }
116
117     public void storeStringField(int field, String JavaDoc value)
118     {
119         storeObjectField(field, value);
120     }
121
122     public String JavaDoc fetchStringField(int field)
123     {
124         return (String JavaDoc)fetchObjectField(field);
125     }
126
127     public abstract void storeObjectField(int field, Object JavaDoc value);
128
129     public abstract Object JavaDoc fetchObjectField(int field);
130 }
131
Popular Tags