KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > inside > marshall > MarshallerFamily


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.inside.marshall;
22
23 import com.db4o.inside.convert.conversions.*;
24
25 /**
26  * @exclude
27  */

28 public class MarshallerFamily {
29     
30     
31     public static class FamilyVersion{
32         
33         public static final int PRE_MARSHALLER = 0;
34         
35         public static final int MARSHALLER = 1;
36         
37         public static final int BTREE_FIELD_INDEXES = 2;
38         
39     }
40     
41     private static int FAMILY_VERSION = FamilyVersion.BTREE_FIELD_INDEXES;
42     
43     public final ArrayMarshaller _array;
44     
45     public final ClassMarshaller _class;
46     
47     public final FieldMarshaller _field;
48     
49     public final ObjectMarshaller _object;
50
51     public final PrimitiveMarshaller _primitive;
52
53     public final StringMarshaller _string;
54     
55     public final UntypedMarshaller _untyped;
56
57     private final int _converterVersion;
58
59
60     private final static MarshallerFamily[] allVersions = new MarshallerFamily[] {
61         
62         // LEGACY => before 5.4
63

64         new MarshallerFamily(
65             0,
66             new ArrayMarshaller0(),
67             new ClassMarshaller0(),
68             new FieldMarshaller0(),
69             new ObjectMarshaller0(),
70             new PrimitiveMarshaller0(),
71             new StringMarshaller0(),
72             new UntypedMarshaller0()),
73         
74         new MarshallerFamily(
75             ClassIndexesToBTrees_5_5.VERSION,
76             new ArrayMarshaller1(),
77             new ClassMarshaller1(),
78             new FieldMarshaller0(),
79             new ObjectMarshaller1(),
80             new PrimitiveMarshaller1(),
81             new StringMarshaller1(),
82             new UntypedMarshaller1()),
83     
84         new MarshallerFamily(
85             FieldIndexesToBTrees_5_7.VERSION,
86             new ArrayMarshaller1(),
87             new ClassMarshaller2(),
88             new FieldMarshaller1(),
89             new ObjectMarshaller1(),
90             new PrimitiveMarshaller1(),
91             new StringMarshaller1(),
92             new UntypedMarshaller1())};
93
94     private MarshallerFamily(
95             int converterVersion,
96             ArrayMarshaller arrayMarshaller,
97             ClassMarshaller classMarshaller,
98             FieldMarshaller fieldMarshaller,
99             ObjectMarshaller objectMarshaller,
100             PrimitiveMarshaller primitiveMarshaller,
101             StringMarshaller stringMarshaller,
102             UntypedMarshaller untypedMarshaller) {
103         _converterVersion = converterVersion;
104         _array = arrayMarshaller;
105         _array._family = this;
106         _class = classMarshaller;
107         _class._family = this;
108         _field = fieldMarshaller;
109         _object = objectMarshaller;
110         _object._family = this;
111         _primitive = primitiveMarshaller;
112         _primitive._family = this;
113         _string = stringMarshaller;
114         _untyped = untypedMarshaller;
115         _untyped._family = this;
116     }
117
118     public static MarshallerFamily version(int n) {
119         return allVersions[n];
120     }
121
122     public static MarshallerFamily current() {
123         if(FAMILY_VERSION < FamilyVersion.BTREE_FIELD_INDEXES){
124             throw new IllegalStateException JavaDoc("Using old marshaller versions to write database files is not supported, source code has been removed.");
125         }
126         return version(FAMILY_VERSION);
127     }
128     
129     public static MarshallerFamily forConverterVersion(int n){
130         MarshallerFamily result = allVersions[0];
131         for (int i = 1; i < allVersions.length; i++) {
132             if(allVersions[i]._converterVersion > n){
133                 return result;
134             }
135             result = allVersions[i];
136         }
137         return result;
138     }
139
140 }
141
Popular Tags