01: /**********************************************************************
02: Copyright (c) 2007 Andy Jefferson 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: ...
17: **********************************************************************/package org.jpox.jta;
18:
19: import javax.transaction.TransactionManager;
20:
21: import org.jpox.ClassLoaderResolver;
22: import org.jpox.util.Localiser;
23:
24: /**
25: * TransactionManager locator using a factory class.
26: * All extending classes must provide the method <i>getFactoryClass()</i> returning the class of a factory
27: * that has a method "getTransactionManager" returning the manager object.
28: *
29: * @version $Revision: 1.1 $
30: */
31: public abstract class FactoryBasedTransactionManagerLocator implements
32: TransactionManagerLocator {
33: /** Localisation utility for output messages */
34: protected static final Localiser LOCALISER = Localiser
35: .getInstance("org.jpox.Localisation");
36:
37: /**
38: * Accessor for the factory class to use for this locator.
39: * @param clr ClassLoader resolver
40: * @return The class
41: */
42: protected abstract Class getFactoryClass(ClassLoaderResolver clr);
43:
44: /**
45: * Method to return the TransactionManager.
46: * @return The TransactionManager
47: */
48: public TransactionManager getTransactionManager(
49: ClassLoaderResolver clr) {
50: Class factoryClass = getFactoryClass(clr);
51: if (factoryClass == null) {
52: return null;
53: }
54:
55: try {
56: return (TransactionManager) factoryClass.getMethod(
57: "getTransactionManager", null).invoke(null, null);
58: } catch (Exception e) {
59: e.printStackTrace();
60: }
61: return null;
62: }
63: }
|