KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > state > SCOWrapper


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: SCOWrapper.java,v 1.1 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.state;
12
13 import com.triactive.jdo.FieldManager;
14
15
16 /**
17  * A field manager that wraps SCO field values in appropriate SCO objects.
18  * <p>
19  * All calls are delegated to an underlying field manager.
20  * Calls to {@link #fetchObjectField} are handled specially; if the field is
21  * an SCO field the value obtained from the underlying field manager is, if
22  * necessary, wrapped in an appropriate SCO wrapper class.
23  *
24  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
25  * @version $Revision: 1.1 $
26  */

27
28 class SCOWrapper implements FieldManager
29 {
30     private final FieldManager fm;
31     private final StateManagerImpl sm;
32     private final boolean[] isSCO;
33
34
35     /**
36      * Constructs an SCO wrapper.
37      *
38      * @param fm
39      * The underlying field manager to which calls are delegated.
40      * @param sm
41      * The state manager for the managed object.
42      * @param isSCO
43      * An array of booleans, one for each field, indicating whether or not
44      * the field is an SCO field.
45      */

46
47     public SCOWrapper(FieldManager fm, StateManagerImpl sm, boolean[] isSCO)
48     {
49         this.fm = fm;
50         this.sm = sm;
51         this.isSCO = isSCO;
52     }
53
54     public void storeBooleanField(int field, boolean value)
55     {
56         fm.storeBooleanField(field, value);
57     }
58
59     public boolean fetchBooleanField(int field)
60     {
61         return fm.fetchBooleanField(field);
62     }
63
64     public void storeCharField(int field, char value)
65     {
66         fm.storeCharField(field, value);
67     }
68
69     public char fetchCharField(int field)
70     {
71         return fm.fetchCharField(field);
72     }
73
74     public void storeByteField(int field, byte value)
75     {
76         fm.storeByteField(field, value);
77     }
78
79     public byte fetchByteField(int field)
80     {
81         return fm.fetchByteField(field);
82     }
83
84     public void storeShortField(int field, short value)
85     {
86         fm.storeShortField(field, value);
87     }
88
89     public short fetchShortField(int field)
90     {
91         return fm.fetchShortField(field);
92     }
93
94     public void storeIntField(int field, int value)
95     {
96         fm.storeIntField(field, value);
97     }
98
99     public int fetchIntField(int field)
100     {
101         return fm.fetchIntField(field);
102     }
103
104     public void storeLongField(int field, long value)
105     {
106         fm.storeLongField(field, value);
107     }
108
109     public long fetchLongField(int field)
110     {
111         return fm.fetchLongField(field);
112     }
113
114     public void storeFloatField(int field, float value)
115     {
116         fm.storeFloatField(field, value);
117     }
118
119     public float fetchFloatField(int field)
120     {
121         return fm.fetchFloatField(field);
122     }
123
124     public void storeDoubleField(int field, double value)
125     {
126         fm.storeDoubleField(field, value);
127     }
128
129     public double fetchDoubleField(int field)
130     {
131         return fm.fetchDoubleField(field);
132     }
133
134     public void storeStringField(int field, String JavaDoc value)
135     {
136         fm.storeStringField(field, value);
137     }
138
139     public String JavaDoc fetchStringField(int field)
140     {
141         return fm.fetchStringField(field);
142     }
143
144     public void storeObjectField(int field, Object JavaDoc value)
145     {
146         fm.storeObjectField(field, value);
147     }
148
149     public Object JavaDoc fetchObjectField(int field)
150     {
151         Object JavaDoc value = fm.fetchObjectField(field);
152
153         if (isSCO[field])
154             return sm.wrapSCOInstance(field, value);
155         else
156             return value;
157     }
158 }
159
Popular Tags