01: package org.apache.ojb.broker.core;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.OJBRuntimeException;
19: import org.apache.ojb.broker.util.ClassHelper;
20: import org.apache.ojb.broker.util.configuration.Configuration;
21: import org.apache.ojb.broker.util.configuration.Configurator;
22: import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
23: import org.apache.ojb.broker.util.logging.Logger;
24: import org.apache.ojb.broker.util.logging.LoggerFactory;
25:
26: /**
27: *
28: * @author Thomas Mahler
29: * @version $Id: PersistenceBrokerFactoryFactory.java,v 1.4.2.1 2005/12/21 22:25:01 tomdz Exp $
30: */
31: public class PersistenceBrokerFactoryFactory {
32: private static Logger log = LoggerFactory.getBootLogger();
33:
34: private static final String PBF_KEY = "PersistenceBrokerFactoryClass";
35: private static PersistenceBrokerFactoryIF singleton = init();
36:
37: /**
38: * Returns an {@link PersistenceBrokerFactoryIF} instance.
39: */
40: public static PersistenceBrokerFactoryIF instance() {
41: return singleton;
42: }
43:
44: private static PersistenceBrokerFactoryIF init() {
45: if (log.isDebugEnabled())
46: log.debug("Instantiate PersistenceBrokerFactory");
47: Class pbfClass = null;
48: try {
49: Configurator configurator = OjbConfigurator.getInstance();
50: Configuration config = configurator
51: .getConfigurationFor(null);
52: pbfClass = config.getClass(PBF_KEY, null);
53: if (pbfClass == null) {
54: log
55: .error("Creation of PersistenceBrokerFactory (PBF) instance failed, can't get PBF class object");
56: throw new OJBRuntimeException("Property for key '"
57: + PBF_KEY
58: + "' can not be found in properties file");
59: }
60: PersistenceBrokerFactoryIF result = (PersistenceBrokerFactoryIF) ClassHelper
61: .newInstance(pbfClass);
62: configurator.configure(result);
63: log.info("PersistencebrokerFactory class instantiated: "
64: + result);
65: return result;
66: } catch (Exception e) {
67: if (e instanceof OJBRuntimeException) {
68: throw (OJBRuntimeException) e;
69: } else {
70: throw new OJBRuntimeException(
71: "Error while instantiation of PersistenceBrokerFactory class",
72: e);
73: }
74: }
75: }
76: }
|