2
* Copyright Terracotta, Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
16
package net.sf.ehcache.transaction.manager.selector;
18
import net.sf.ehcache.util.ClassLoaderUtil;
20
import org.slf4j.Logger;
21
import org.slf4j.LoggerFactory;
23
import java.lang.reflect.InvocationTargetException;
24
import java.lang.reflect.Method;
26
import javax.transaction.TransactionManager;
29
* Abstract selector for calling a factory method
31
* @author Ludovic Orban
33
public abstract class FactorySelector extends Selector {
34
private static final Logger LOG = LoggerFactory.getLogger(FactorySelector.class);
36
private final String factoryClassName;
37
private final String factoryMethodName;
42
* @param vendor the transaction manager vendor name
43
* @param factoryClassName the class used to lookup the transaction manager
44
* @param factoryMethodName the method to be called on the class used to lookup the transaction manager
46
public FactorySelector(String vendor, String factoryClassName, String factoryMethodName) {
48
this.factoryClassName = factoryClassName;
49
this.factoryMethodName = factoryMethodName;
56
protected TransactionManager doLookup() {
57
TransactionManager transactionManager = null;
60
Class factoryClass = ClassLoaderUtil.loadClass(factoryClassName);
61
Class[] signature = null;
63
Method method = factoryClass.getMethod(factoryMethodName, signature);
64
transactionManager = (TransactionManager) method.invoke(null, args);
65
} catch (ClassNotFoundException e) {
66
LOG.debug("FactorySelector failed lookup", e);
67
} catch (NoSuchMethodException e) {
68
LOG.debug("FactorySelector failed lookup", e);
69
} catch (InvocationTargetException e) {
70
LOG.debug("FactorySelector failed lookup", e);
71
} catch (IllegalAccessException e) {
72
LOG.debug("FactorySelector failed lookup", e);
74
return transactionManager;
b'\\ No newline at end of file'