001: /*
002: * Copyright 2004 (C) TJDO.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the TJDO License version 1.0.
006: * See the terms of the TJDO License in the documentation provided with this software.
007: *
008: * $Id: SCOWrapper.java,v 1.1 2004/01/18 03:01:06 jackknifebarber Exp $
009: */
010:
011: package com.triactive.jdo.state;
012:
013: import com.triactive.jdo.FieldManager;
014:
015: /**
016: * A field manager that wraps SCO field values in appropriate SCO objects.
017: * <p>
018: * All calls are delegated to an underlying field manager.
019: * Calls to {@link #fetchObjectField} are handled specially; if the field is
020: * an SCO field the value obtained from the underlying field manager is, if
021: * necessary, wrapped in an appropriate SCO wrapper class.
022: *
023: * @author <a href="mailto:mmartin5@austin.rr.com">Mike Martin</a>
024: * @version $Revision: 1.1 $
025: */
026:
027: class SCOWrapper implements FieldManager {
028: private final FieldManager fm;
029: private final StateManagerImpl sm;
030: private final boolean[] isSCO;
031:
032: /**
033: * Constructs an SCO wrapper.
034: *
035: * @param fm
036: * The underlying field manager to which calls are delegated.
037: * @param sm
038: * The state manager for the managed object.
039: * @param isSCO
040: * An array of booleans, one for each field, indicating whether or not
041: * the field is an SCO field.
042: */
043:
044: public SCOWrapper(FieldManager fm, StateManagerImpl sm,
045: boolean[] isSCO) {
046: this .fm = fm;
047: this .sm = sm;
048: this .isSCO = isSCO;
049: }
050:
051: public void storeBooleanField(int field, boolean value) {
052: fm.storeBooleanField(field, value);
053: }
054:
055: public boolean fetchBooleanField(int field) {
056: return fm.fetchBooleanField(field);
057: }
058:
059: public void storeCharField(int field, char value) {
060: fm.storeCharField(field, value);
061: }
062:
063: public char fetchCharField(int field) {
064: return fm.fetchCharField(field);
065: }
066:
067: public void storeByteField(int field, byte value) {
068: fm.storeByteField(field, value);
069: }
070:
071: public byte fetchByteField(int field) {
072: return fm.fetchByteField(field);
073: }
074:
075: public void storeShortField(int field, short value) {
076: fm.storeShortField(field, value);
077: }
078:
079: public short fetchShortField(int field) {
080: return fm.fetchShortField(field);
081: }
082:
083: public void storeIntField(int field, int value) {
084: fm.storeIntField(field, value);
085: }
086:
087: public int fetchIntField(int field) {
088: return fm.fetchIntField(field);
089: }
090:
091: public void storeLongField(int field, long value) {
092: fm.storeLongField(field, value);
093: }
094:
095: public long fetchLongField(int field) {
096: return fm.fetchLongField(field);
097: }
098:
099: public void storeFloatField(int field, float value) {
100: fm.storeFloatField(field, value);
101: }
102:
103: public float fetchFloatField(int field) {
104: return fm.fetchFloatField(field);
105: }
106:
107: public void storeDoubleField(int field, double value) {
108: fm.storeDoubleField(field, value);
109: }
110:
111: public double fetchDoubleField(int field) {
112: return fm.fetchDoubleField(field);
113: }
114:
115: public void storeStringField(int field, String value) {
116: fm.storeStringField(field, value);
117: }
118:
119: public String fetchStringField(int field) {
120: return fm.fetchStringField(field);
121: }
122:
123: public void storeObjectField(int field, Object value) {
124: fm.storeObjectField(field, value);
125: }
126:
127: public Object fetchObjectField(int field) {
128: Object value = fm.fetchObjectField(field);
129:
130: if (isSCO[field])
131: return sm.wrapSCOInstance(field, value);
132: else
133: return value;
134: }
135: }
|