KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > sco > detached > DetachSCOFactoryRegistry


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.sco.detached;
13
14 import com.versant.core.jdo.sco.*;
15 import com.versant.core.metadata.FieldMetaData;
16 import com.versant.core.metadata.MDStaticUtils;
17 import com.versant.core.metadata.MDStatics;
18
19 import com.versant.core.common.BindingSupportImpl;
20
21 /**
22  * This registry map the SCO types to their factories.
23  */

24 public class DetachSCOFactoryRegistry {
25
26     /**
27      * Get the factory for a simple SCO type.
28      */

29     public VersantSCOFactory getJdoGenieSCOFactory(FieldMetaData fmd) {
30         if (fmd.category == MDStatics.CATEGORY_SIMPLE && 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
57                 case MDStatics.VECTOR:
58                     return new DetachSCOVectorFactory();
59
60                 default:
61                     throw BindingSupportImpl.getInstance().notImplemented("Creating a SCO instance for field " +
62                             fmd.getName() + " of type " + MDStaticUtils.toSimpleName(fmd.typeCode) +
63                             " is not supported");
64             }
65         }
66         return null;
67     }
68
69     /**
70      * Get the factory for a SCO map.
71      */

72     public VersantSCOMapFactory getJDOGenieSCOMapFactory(FieldMetaData fmd) {
73         if (fmd.category == MDStatics.CATEGORY_MAP) {
74             switch (fmd.typeCode) {
75                 case MDStatics.MAP:
76                 case MDStatics.HASHMAP:
77                     return new DetachSCOHashMapFactory();
78                 case MDStatics.HASHTABLE:
79                     return new DetachSCOHashtableFactory();
80                 case MDStatics.TREEMAP:
81                 case MDStatics.SORTEDMAP:
82                     return new DetachSCOTreeMapFactory();
83                 default:
84                     throw BindingSupportImpl.getInstance().internal("Type code not supported as map. TypeCode = " +
85                             MDStaticUtils.toSimpleName(fmd.typeCode));
86             }
87         }
88         return null;
89     }
90 }
91
Popular Tags