001    /**
002     * 
003     * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
004     * 
005     * Licensed under the Apache License, Version 2.0 (the "License"); 
006     * you may not use this file except in compliance with the License. 
007     * You may obtain a copy of the License at 
008     * 
009     * http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS, 
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
014     * See the License for the specific language governing permissions and 
015     * limitations under the License. 
016     * 
017     **/
018    package org.jencks.factory;
019    
020    import java.util.Collection;
021    
022    import javax.resource.spi.BootstrapContext;
023    import javax.resource.spi.work.WorkManager;
024    import javax.transaction.xa.XAException;
025    
026    import org.apache.geronimo.connector.BootstrapContextImpl;
027    import org.apache.geronimo.connector.work.GeronimoWorkManager;
028    import org.apache.geronimo.transaction.ExtendedTransactionManager;
029    import org.apache.geronimo.transaction.context.TransactionContextManager;
030    import org.apache.geronimo.transaction.manager.TransactionLog;
031    import org.apache.geronimo.transaction.manager.XidImporter;
032    import org.springframework.beans.factory.FactoryBean;
033    import org.springframework.beans.factory.InitializingBean;
034    import org.springframework.context.ApplicationContext;
035    import org.springframework.context.ApplicationContextAware;
036    
037    /**
038     * A Spring {@link FactoryBean} for creating a {@link BootstrapContext} for the JCA container
039     * with the {@link WorkManager} and {@link ExtendedTransactionManager}.
040     *
041     * @version $Revision: 1.6 $
042     */
043    public class BootstrapContextFactoryBean implements FactoryBean, InitializingBean, ApplicationContextAware {
044    
045            private ApplicationContext applicationContext;
046        private BootstrapContext bootstrapContext;
047        private GeronimoWorkManager workManager;
048        private WorkManagerFactoryBean workManagerFactory = new WorkManagerFactoryBean();
049    
050        public Object getObject() throws Exception {
051            if (bootstrapContext == null) {
052                bootstrapContext = new BootstrapContextImpl(getWorkManager());
053            }
054            return bootstrapContext;
055        }
056    
057        public Class getObjectType() {
058            return BootstrapContext.class;
059        }
060    
061        public boolean isSingleton() {
062            return true;
063        }
064    
065        public void afterPropertiesSet() throws Exception {
066        }
067    
068        public void setApplicationContext(ApplicationContext applicationContext) {
069            this.applicationContext = applicationContext;
070        }
071    
072    
073        // Properties
074        //-------------------------------------------------------------------------
075        public GeronimoWorkManager getWorkManager() throws Exception {
076            if (workManager == null) {
077                    workManagerFactory.setApplicationContext(applicationContext);
078                workManager = workManagerFactory.getWorkManager();
079            }
080            return workManager;
081        }
082    
083        public void setWorkManager(GeronimoWorkManager workManager) {
084            this.workManager = workManager;
085        }
086    
087        public TransactionContextManager getTransactionContextManager() throws XAException {
088            return workManagerFactory.getTransactionContextManager();
089        }
090    
091        public void setTransactionContextManager(TransactionContextManager transactionContextManager) {
092            workManagerFactory.setTransactionContextManager(transactionContextManager);
093        }
094    
095        public int getThreadPoolSize() {
096            return workManagerFactory.getThreadPoolSize();
097        }
098    
099        public void setThreadPoolSize(int threadPoolSize) {
100            workManagerFactory.setThreadPoolSize(threadPoolSize);
101        }
102    
103        public ExtendedTransactionManager getTransactionManager() throws XAException {
104            return workManagerFactory.getTransactionManager();
105        }
106    
107        public void setTransactionManager(ExtendedTransactionManager transactionManager) {
108            workManagerFactory.setTransactionManager(transactionManager);
109        }
110    
111        public XidImporter getXidImporter() {
112            return workManagerFactory.getXidImporter();
113        }
114    
115        public void setXidImporter(XidImporter xidImporter) {
116            workManagerFactory.setXidImporter(xidImporter);
117        }
118    
119        public int getDefaultTransactionTimeoutSeconds() {
120            return workManagerFactory.getDefaultTransactionTimeoutSeconds();
121        }
122    
123        public void setDefaultTransactionTimeoutSeconds(int defaultTransactionTimeoutSeconds) {
124            workManagerFactory.setDefaultTransactionTimeoutSeconds(defaultTransactionTimeoutSeconds);
125        }
126    
127        public TransactionLog getTransactionLog() {
128            return workManagerFactory.getTransactionLog();
129        }
130    
131        public void setTransactionLog(TransactionLog transactionLog) {
132            workManagerFactory.setTransactionLog(transactionLog);
133        }
134    
135        public Collection getResourceManagers() {
136            return workManagerFactory.getResourceManagers();
137        }
138    
139        public void setResourceManagers(Collection resourceManagers) {
140            workManagerFactory.setResourceManagers(resourceManagers);
141        }
142    }