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 java.util.Collection;
21
22 import javax.resource.spi.BootstrapContext;
23 import javax.resource.spi.work.WorkManager;
24 import javax.transaction.xa.XAException;
25
26 import org.apache.geronimo.connector.BootstrapContextImpl;
27 import org.apache.geronimo.connector.work.GeronimoWorkManager;
28 import org.apache.geronimo.transaction.ExtendedTransactionManager;
29 import org.apache.geronimo.transaction.context.TransactionContextManager;
30 import org.apache.geronimo.transaction.manager.TransactionLog;
31 import org.apache.geronimo.transaction.manager.XidImporter;
32 import org.springframework.beans.factory.FactoryBean;
33 import org.springframework.beans.factory.InitializingBean;
34 import org.springframework.context.ApplicationContext;
35 import org.springframework.context.ApplicationContextAware;
36
37 /***
38 * A Spring {@link FactoryBean} for creating a {@link BootstrapContext} for the JCA container
39 * with the {@link WorkManager} and {@link ExtendedTransactionManager}.
40 *
41 * @version $Revision: 1.6 $
42 */
43 public class BootstrapContextFactoryBean implements FactoryBean, InitializingBean, ApplicationContextAware {
44
45 private ApplicationContext applicationContext;
46 private BootstrapContext bootstrapContext;
47 private GeronimoWorkManager workManager;
48 private WorkManagerFactoryBean workManagerFactory = new WorkManagerFactoryBean();
49
50 public Object getObject() throws Exception {
51 if (bootstrapContext == null) {
52 bootstrapContext = new BootstrapContextImpl(getWorkManager());
53 }
54 return bootstrapContext;
55 }
56
57 public Class getObjectType() {
58 return BootstrapContext.class;
59 }
60
61 public boolean isSingleton() {
62 return true;
63 }
64
65 public void afterPropertiesSet() throws Exception {
66 }
67
68 public void setApplicationContext(ApplicationContext applicationContext) {
69 this.applicationContext = applicationContext;
70 }
71
72
73
74
75 public GeronimoWorkManager getWorkManager() throws Exception {
76 if (workManager == null) {
77 workManagerFactory.setApplicationContext(applicationContext);
78 workManager = workManagerFactory.getWorkManager();
79 }
80 return workManager;
81 }
82
83 public void setWorkManager(GeronimoWorkManager workManager) {
84 this.workManager = workManager;
85 }
86
87 public TransactionContextManager getTransactionContextManager() throws XAException {
88 return workManagerFactory.getTransactionContextManager();
89 }
90
91 public void setTransactionContextManager(TransactionContextManager transactionContextManager) {
92 workManagerFactory.setTransactionContextManager(transactionContextManager);
93 }
94
95 public int getThreadPoolSize() {
96 return workManagerFactory.getThreadPoolSize();
97 }
98
99 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 }