KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > odmg > collections > DCollectionFactory


1 package org.apache.ojb.odmg.collections;
2
3 import org.odmg.DList;
4 import org.odmg.DBag;
5 import org.odmg.DSet;
6 import org.odmg.DArray;
7 import org.odmg.DMap;
8 import org.apache.ojb.broker.util.factory.ConfigurableFactory;
9 import org.apache.ojb.broker.PBKey;
10
11 /* Copyright 2003-2004 The Apache Software Foundation
12  *
13  * Licensed under the Apache License, Version 2.0 (the "License");
14  * you may not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  * http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  */

25 public class DCollectionFactory
26 {
27     private static final DCollectionFactory singleton = new DCollectionFactory();
28
29     private DCollectionFactory()
30     {
31     }
32
33     public static DCollectionFactory getInstance()
34     {
35         return singleton;
36     }
37
38     public DList createDList()
39     {
40         return (DList) DListFactory.singleton.createCollectionOrMap();
41     }
42
43     public DList createDList(PBKey key)
44     {
45         return (DList) DListFactory.singleton.createCollectionOrMap(key);
46     }
47
48     public DBag createDBag()
49     {
50         return (DBag) DBagFactory.singleton.createCollectionOrMap();
51     }
52
53     public DBag createDBag(PBKey key)
54     {
55         return (DBag) DBagFactory.singleton.createCollectionOrMap(key);
56     }
57
58     public DSet createDSet()
59     {
60         return (DSet) DSetFactory.singleton.createCollectionOrMap();
61     }
62
63     public DSet createDSet(PBKey key)
64     {
65         return (DSet) DSetFactory.singleton.createCollectionOrMap(key);
66     }
67
68     public DArray createDArray()
69     {
70         return (DArray) DArrayFactory.singleton.createCollectionOrMap();
71     }
72
73     public DArray createDArray(PBKey key)
74     {
75         return (DArray) DArrayFactory.singleton.createCollectionOrMap(key);
76     }
77
78     public DMap createDMap()
79     {
80         return (DMap) DMapFactory.singleton.createCollectionOrMap();
81     }
82
83     public DMap createDMap(PBKey key)
84     {
85         return (DMap) DMapFactory.singleton.createCollectionOrMap(key);
86     }
87
88     //*****************************************************
89
// inner classes
90
//*****************************************************
91

92     abstract static class BaseFactory extends ConfigurableFactory
93     {
94         Object JavaDoc createCollectionOrMap()
95         {
96             return this.createNewInstance();
97         }
98
99         Object JavaDoc createCollectionOrMap(PBKey key)
100         {
101             return createNewInstance(PBKey.class, key);
102         }
103     }
104
105     static final class DListFactory extends BaseFactory
106     {
107         static final BaseFactory singleton = new DListFactory();
108         protected String JavaDoc getConfigurationKey()
109         {
110             return "DListClass";
111         }
112     }
113
114     static final class DArrayFactory extends BaseFactory
115     {
116         static final BaseFactory singleton = new DArrayFactory();
117         protected String JavaDoc getConfigurationKey()
118         {
119             return "DArrayClass";
120         }
121     }
122
123     static final class DBagFactory extends BaseFactory
124     {
125         static final BaseFactory singleton = new DBagFactory();
126         protected String JavaDoc getConfigurationKey()
127         {
128             return "DBagClass";
129         }
130     }
131
132     static final class DSetFactory extends BaseFactory
133     {
134         static final BaseFactory singleton = new DSetFactory();
135         protected String JavaDoc getConfigurationKey()
136         {
137             return "DSetClass";
138         }
139     }
140
141     static final class DMapFactory extends BaseFactory
142     {
143         static final BaseFactory singleton = new DMapFactory();
144         protected String JavaDoc getConfigurationKey()
145         {
146             return "DMapClass";
147         }
148     }
149 }
150
Popular Tags