~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to src/main/java/net/sf/ehcache/transaction/manager/selector/FactorySelector.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-06 14:53:07 UTC
  • mfrom: (1.1.7) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130506145307-v5bhw5yu70re00l3
Tags: 2.6.7-1
* Team upload.
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *  Copyright Terracotta, Inc.
 
3
 *
 
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
 
7
 *
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
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
package net.sf.ehcache.transaction.manager.selector;
 
17
 
 
18
import net.sf.ehcache.util.ClassLoaderUtil;
 
19
 
 
20
import org.slf4j.Logger;
 
21
import org.slf4j.LoggerFactory;
 
22
 
 
23
import java.lang.reflect.InvocationTargetException;
 
24
import java.lang.reflect.Method;
 
25
 
 
26
import javax.transaction.TransactionManager;
 
27
 
 
28
/**
 
29
 * Abstract selector for calling a factory method
 
30
 *
 
31
 * @author Ludovic Orban
 
32
 */
 
33
public abstract class FactorySelector extends Selector {
 
34
    private static final Logger LOG = LoggerFactory.getLogger(FactorySelector.class);
 
35
 
 
36
    private final String factoryClassName;
 
37
    private final String factoryMethodName;
 
38
 
 
39
    /**
 
40
     * Constructor
 
41
     *
 
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
 
45
     */
 
46
    public FactorySelector(String vendor, String factoryClassName, String factoryMethodName) {
 
47
        super(vendor);
 
48
        this.factoryClassName = factoryClassName;
 
49
        this.factoryMethodName = factoryMethodName;
 
50
    }
 
51
 
 
52
    /**
 
53
     * {@inheritDoc}
 
54
     */
 
55
    @Override
 
56
    protected TransactionManager doLookup() {
 
57
        TransactionManager transactionManager = null;
 
58
 
 
59
        try {
 
60
            Class factoryClass = ClassLoaderUtil.loadClass(factoryClassName);
 
61
            Class[] signature = null;
 
62
            Object[] args = 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);
 
73
        }
 
74
        return transactionManager;
 
75
    }
 
76
}
 
 
b'\\ No newline at end of file'