01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.transaction;
18:
19: import org.apache.commons.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21: import org.compass.core.Compass;
22: import org.compass.core.config.CompassEnvironment;
23: import org.compass.core.config.CompassSettings;
24: import org.compass.core.config.ConfigurationException;
25: import org.compass.core.util.ClassUtils;
26:
27: /**
28: * @author kimchy
29: */
30: public class TransactionFactoryFactory {
31:
32: private static final Log log = LogFactory
33: .getLog(TransactionFactoryFactory.class);
34:
35: public static TransactionFactory createTransactionFactory(
36: Compass compass, CompassSettings settings) {
37: String factoryClassName = settings.getSetting(
38: CompassEnvironment.Transaction.FACTORY,
39: LocalTransactionFactory.class.getName());
40: return createTransactionFactory(compass, factoryClassName,
41: settings);
42: }
43:
44: public static LocalTransactionFactory createLocalTransactionFactory(
45: Compass compass, CompassSettings settings) {
46: return (LocalTransactionFactory) createTransactionFactory(
47: compass, LocalTransactionFactory.class.getName(),
48: settings);
49: }
50:
51: public static TransactionFactory createTransactionFactory(
52: Compass compass, String factoryClassName,
53: CompassSettings settings) {
54:
55: if (log.isDebugEnabled()) {
56: log.debug("Using transaction factory [" + factoryClassName
57: + "]");
58: }
59:
60: try {
61: TransactionFactory factory = (TransactionFactory) ClassUtils
62: .forName(factoryClassName,
63: settings.getClassLoader()).newInstance();
64: factory.configure(compass, settings);
65: return factory;
66: } catch (Exception e) {
67: throw new ConfigurationException(
68: "Failed to create transaction factory class ["
69: + factoryClassName + "]", e);
70: }
71: }
72: }
|