001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.internal.marshall;
022:
023: import com.db4o.internal.convert.conversions.*;
024:
025: /**
026: * @exclude
027: */
028: public class MarshallerFamily {
029:
030: public static class FamilyVersion {
031:
032: public static final int PRE_MARSHALLER = 0;
033:
034: public static final int MARSHALLER = 1;
035:
036: public static final int BTREE_FIELD_INDEXES = 2;
037:
038: }
039:
040: private static int FAMILY_VERSION = FamilyVersion.BTREE_FIELD_INDEXES;
041:
042: public final ArrayMarshaller _array;
043:
044: public final ClassMarshaller _class;
045:
046: public final FieldMarshaller _field;
047:
048: public final ObjectMarshaller _object;
049:
050: public final PrimitiveMarshaller _primitive;
051:
052: public final StringMarshaller _string;
053:
054: public final UntypedMarshaller _untyped;
055:
056: private final int _converterVersion;
057:
058: private final static MarshallerFamily[] allVersions = new MarshallerFamily[] {
059:
060: // LEGACY => before 5.4
061:
062: new MarshallerFamily(0, new ArrayMarshaller0(),
063: new ClassMarshaller0(), new FieldMarshaller0(),
064: new ObjectMarshaller0(),
065: new PrimitiveMarshaller0(),
066: new StringMarshaller0(), new UntypedMarshaller0()),
067:
068: new MarshallerFamily(ClassIndexesToBTrees_5_5.VERSION,
069: new ArrayMarshaller1(), new ClassMarshaller1(),
070: new FieldMarshaller0(), new ObjectMarshaller1(),
071: new PrimitiveMarshaller1(),
072: new StringMarshaller1(), new UntypedMarshaller1()),
073:
074: new MarshallerFamily(FieldIndexesToBTrees_5_7.VERSION,
075: new ArrayMarshaller1(), new ClassMarshaller2(),
076: new FieldMarshaller1(), new ObjectMarshaller1(),
077: new PrimitiveMarshaller1(),
078: new StringMarshaller1(), new UntypedMarshaller1()),
079:
080: };
081:
082: public MarshallerFamily(int converterVersion,
083: ArrayMarshaller arrayMarshaller,
084: ClassMarshaller classMarshaller,
085: FieldMarshaller fieldMarshaller,
086: ObjectMarshaller objectMarshaller,
087: PrimitiveMarshaller primitiveMarshaller,
088: StringMarshaller stringMarshaller,
089: UntypedMarshaller untypedMarshaller) {
090: _converterVersion = converterVersion;
091: _array = arrayMarshaller;
092: _array._family = this ;
093: _class = classMarshaller;
094: _class._family = this ;
095: _field = fieldMarshaller;
096: _object = objectMarshaller;
097: _object._family = this ;
098: _primitive = primitiveMarshaller;
099: _primitive._family = this ;
100: _string = stringMarshaller;
101: _untyped = untypedMarshaller;
102: _untyped._family = this ;
103: }
104:
105: public static MarshallerFamily version(int n) {
106: return allVersions[n];
107: }
108:
109: public static MarshallerFamily current() {
110: if (FAMILY_VERSION < FamilyVersion.BTREE_FIELD_INDEXES) {
111: throw new IllegalStateException(
112: "Using old marshaller versions to write database files is not supported, source code has been removed.");
113: }
114: return version(FAMILY_VERSION);
115: }
116:
117: public static MarshallerFamily forConverterVersion(int n) {
118: MarshallerFamily result = allVersions[0];
119: for (int i = 1; i < allVersions.length; i++) {
120: if (allVersions[i]._converterVersion > n) {
121: return result;
122: }
123: result = allVersions[i];
124: }
125: return result;
126: }
127:
128: }
|