1 /***
2 *
3 * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package org.jencks.factory;
19
20 import org.apache.geronimo.connector.BootstrapContextImpl;
21 import org.apache.geronimo.connector.work.GeronimoWorkManager;
22 import org.apache.geronimo.gbean.ReferenceCollection;
23 import org.apache.geronimo.transaction.ExtendedTransactionManager;
24 import org.apache.geronimo.transaction.context.TransactionContextManager;
25 import org.apache.geronimo.transaction.log.UnrecoverableLog;
26 import org.apache.geronimo.transaction.manager.TransactionLog;
27 import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
28 import org.apache.geronimo.transaction.manager.XidImporter;
29 import org.springframework.beans.factory.FactoryBean;
30 import org.springframework.beans.factory.InitializingBean;
31
32 import javax.resource.spi.BootstrapContext;
33 import javax.resource.spi.work.WorkManager;
34 import javax.transaction.xa.XAException;
35
36 /***
37 * A Spring {@link FactoryBean} for creating a {@link BootstrapContext} for the JCA container
38 * with the {@link WorkManager} and {@link ExtendedTransactionManager}.
39 *
40 * @version $Revision: 1.3 $
41 */
42 public class BootstrapContextFactoryBean implements FactoryBean, InitializingBean {
43
44 private BootstrapContext bootstrapContext;
45 private GeronimoWorkManager workManager;
46 private WorkManagerFactoryBean workManagerFactory = new WorkManagerFactoryBean();
47
48 public Object getObject() throws Exception {
49 return bootstrapContext;
50 }
51
52 public Class getObjectType() {
53 return BootstrapContext.class;
54 }
55
56 public boolean isSingleton() {
57 return true;
58 }
59
60 public void afterPropertiesSet() throws Exception {
61 bootstrapContext = new BootstrapContextImpl(getWorkManager());
62 }
63
64
65
66
67 public GeronimoWorkManager getWorkManager() throws Exception {
68 if (workManager == null) {
69 workManager = workManagerFactory.getWorkManager();
70 }
71 return workManager;
72 }
73
74 public void setWorkManager(GeronimoWorkManager workManager) {
75 this.workManager = workManager;
76 }
77
78 public TransactionContextManager getTransactionContextManager() throws XAException {
79 return workManagerFactory.getTransactionContextManager();
80 }
81
82 public void setTransactionContextManager(TransactionContextManager transactionContextManager) {
83 workManagerFactory.setTransactionContextManager(transactionContextManager);
84 }
85
86 public int getThreadPoolSize() {
87 return workManagerFactory.getThreadPoolSize();
88 }
89
90 public void setThreadPoolSize(int threadPoolSize) {
91 workManagerFactory.setThreadPoolSize(threadPoolSize);
92 }
93
94 public ExtendedTransactionManager getTransactionManager() throws XAException {
95 return workManagerFactory.getTransactionManager();
96 }
97
98 public void setTransactionManager(ExtendedTransactionManager transactionManager) {
99 workManagerFactory.setTransactionManager(transactionManager);
100 }
101
102 public XidImporter getXidImporter() {
103 return workManagerFactory.getXidImporter();
104 }
105
106 public void setXidImporter(XidImporter xidImporter) {
107 workManagerFactory.setXidImporter(xidImporter);
108 }
109
110 public int getDefaultTransactionTimeoutSeconds() {
111 return workManagerFactory.getDefaultTransactionTimeoutSeconds();
112 }
113
114 public void setDefaultTransactionTimeoutSeconds(int defaultTransactionTimeoutSeconds) {
115 workManagerFactory.setDefaultTransactionTimeoutSeconds(defaultTransactionTimeoutSeconds);
116 }
117
118 public TransactionLog getTransactionLog() {
119 return workManagerFactory.getTransactionLog();
120 }
121
122 public void setTransactionLog(TransactionLog transactionLog) {
123 workManagerFactory.setTransactionLog(transactionLog);
124 }
125
126 public ReferenceCollection getResourceManagers() {
127 return workManagerFactory.getResourceManagers();
128 }
129
130 public void setResourceManagers(ReferenceCollection resourceManagers) {
131 workManagerFactory.setResourceManagers(resourceManagers);
132 }
133 }