001    /*
002     * Copyright 2002-2005 the original author or authors.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.jencks.factory;
018    
019    import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
020    import org.apache.geronimo.transaction.context.TransactionContextManager;
021    import org.apache.geronimo.transaction.context.UserTransactionImpl;
022    import org.springframework.beans.factory.FactoryBean;
023    import org.springframework.beans.factory.InitializingBean;
024    
025    import javax.transaction.UserTransaction;
026    
027    /**
028     * This FactoryBean creates and configures the Geronimo implementation
029     * of the UserTransaction interface.
030     * <p/>
031     * This factory is based on the Geronimo Transaction Context Manager
032     * and Connection Tracking Coordinator.
033     *
034     * @author ttemplier
035     * @see UserTransactionImpl#setUp(TransactionContextManager, org.apache.geronimo.transaction.TrackedConnectionAssociator)
036     * @see UserTransactionImpl#setOnline(boolean)
037     */
038    public class UserTransactionFactoryBean implements FactoryBean, InitializingBean {
039    
040        private TransactionContextManager transactionContextManager;
041        private ConnectionTrackingCoordinator connectionTrackingCoordinator;
042    
043        private UserTransaction userTransaction;
044    
045        public Object getObject() throws Exception {
046            return userTransaction;
047        }
048    
049        public Class getObjectType() {
050            return UserTransaction.class;
051        }
052    
053        public boolean isSingleton() {
054            return true;
055        }
056    
057        /**
058         * Set the transaction context manager to configure the user transaction.
059         */
060        public void setTransactionContextManager(TransactionContextManager manager) {
061            transactionContextManager = manager;
062        }
063    
064        /**
065         * Set the connection tracking coordinator to configure the user transaction.
066         */
067        public void setConnectionTrackingCoordinator(ConnectionTrackingCoordinator coordinator) {
068            connectionTrackingCoordinator = coordinator;
069        }
070    
071        /**
072         * This method instanciates the Geronimo user transaction implementation
073         * and sets up it with the transaction context manager used and a connection
074         * tracking coordinator.
075         *
076         * It then sets the online property to true in order that the application
077         * can used it.
078         */
079        public void afterPropertiesSet() throws Exception {
080            this.userTransaction = new UserTransactionImpl();
081            ((UserTransactionImpl) this.userTransaction).setUp(transactionContextManager,
082                    connectionTrackingCoordinator);
083            ((UserTransactionImpl) this.userTransaction).setOnline(true);
084        }
085    
086    
087    }