01: /**********************************************************************
02: Copyright (c) 2007 Erik Bengtson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15: Contributors:
16: 2007 Andy Jefferson - removed hardcoded dependency on db4o
17: ...
18: **********************************************************************/package org.jpox;
19:
20: import java.util.HashMap;
21:
22: /**
23: * Registry for connection factories for this ObjectManagerFactory.
24: * Will typically have entries for things like "jdbc/nontx", "jdbc/tx", etc
25: *
26: * @version $Revision: 1.9 $
27: */
28: public class ConnectionFactoryRegistry {
29: /** ObjectManagerFactory context. */
30: OMFContext ctx;
31:
32: /** The registry of factories. */
33: HashMap factories = new HashMap();
34:
35: /**
36: * Constructor.
37: * @param ctx OMFContext
38: */
39: public ConnectionFactoryRegistry(OMFContext ctx) {
40: this .ctx = ctx;
41: }
42:
43: /**
44: * Method to lookup a connection factory and create it if not yet existing.
45: * @param name The lookup name "e.g "jdbc/tx"
46: * @return The connection factory
47: */
48: public ConnectionFactory lookupConnectionFactory(String name) {
49: Object obj = factories.get(name);
50: if (obj != null) {
51: return (ConnectionFactory) obj;
52: }
53: return null;
54: }
55:
56: /**
57: * Method to register a connection factory
58: * @param name The lookup name "e.g "jdbc/tx"
59: * @param factory The connection factory
60: */
61: public void registerConnectionFactory(String name,
62: ConnectionFactory factory) {
63: factories.put(name, factory);
64: }
65: }
|