01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdo.sco.detached;
12:
13: import com.versant.core.jdo.sco.*;
14: import com.versant.core.metadata.FieldMetaData;
15: import com.versant.core.metadata.MDStaticUtils;
16: import com.versant.core.metadata.MDStatics;
17:
18: import com.versant.core.common.BindingSupportImpl;
19:
20: /**
21: * This registry map the SCO types to their factories.
22: */
23: public class DetachSCOFactoryRegistry {
24:
25: /**
26: * Get the factory for a simple SCO type.
27: */
28: public VersantSCOFactory getJdoGenieSCOFactory(FieldMetaData fmd) {
29: if (fmd.category == MDStatics.CATEGORY_SIMPLE
30: && fmd.typeCode == MDStatics.DATE) {
31: return new DetachSCODateFactory();
32: }
33: return null;
34: }
35:
36: /**
37: * Get the factory for a SCO collection.
38: */
39: public VersantSCOCollectionFactory getJDOGenieSCOCollectionFactory(
40: FieldMetaData fmd) {
41: if (fmd.category == MDStatics.CATEGORY_COLLECTION) {
42: switch (fmd.typeCode) {
43: case MDStatics.HASHSET:
44: case MDStatics.SET:
45: return new DetachSCOHashSetFactory();
46: case MDStatics.TREESET:
47: case MDStatics.SORTEDSET:
48: return new DetachSCOTreeSetFactory();
49: case MDStatics.COLLECTION:
50: case MDStatics.LIST:
51: case MDStatics.ARRAYLIST:
52: return new DetachSCOArrayListFactory();
53: case MDStatics.LINKEDLIST:
54: return new DetachSCOLinkedListFactory();
55:
56: case MDStatics.VECTOR:
57: return new DetachSCOVectorFactory();
58:
59: default:
60: throw BindingSupportImpl.getInstance().notImplemented(
61: "Creating a SCO instance for field "
62: + fmd.getName()
63: + " of type "
64: + MDStaticUtils
65: .toSimpleName(fmd.typeCode)
66: + " is not supported");
67: }
68: }
69: return null;
70: }
71:
72: /**
73: * Get the factory for a SCO map.
74: */
75: public VersantSCOMapFactory getJDOGenieSCOMapFactory(
76: FieldMetaData fmd) {
77: if (fmd.category == MDStatics.CATEGORY_MAP) {
78: switch (fmd.typeCode) {
79: case MDStatics.MAP:
80: case MDStatics.HASHMAP:
81: return new DetachSCOHashMapFactory();
82: case MDStatics.HASHTABLE:
83: return new DetachSCOHashtableFactory();
84: case MDStatics.TREEMAP:
85: case MDStatics.SORTEDMAP:
86: return new DetachSCOTreeMapFactory();
87: default:
88: throw BindingSupportImpl.getInstance().internal(
89: "Type code not supported as map. TypeCode = "
90: + MDStaticUtils
91: .toSimpleName(fmd.typeCode));
92: }
93: }
94: return null;
95: }
96: }
|