View Javadoc

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.5 $
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          return bootstrapContext;
52      }
53  
54      public Class getObjectType() {
55          return BootstrapContext.class;
56      }
57  
58      public boolean isSingleton() {
59          return true;
60      }
61  
62      public void afterPropertiesSet() throws Exception {
63          bootstrapContext = new BootstrapContextImpl(getWorkManager());
64      }
65  
66      public void setApplicationContext(ApplicationContext applicationContext) {
67      	this.applicationContext = applicationContext;
68      }
69  
70  
71      // Properties
72      //-------------------------------------------------------------------------
73      public GeronimoWorkManager getWorkManager() throws Exception {
74          if (workManager == null) {
75          	workManagerFactory.setApplicationContext(applicationContext);
76              workManager = workManagerFactory.getWorkManager();
77          }
78          return workManager;
79      }
80  
81      public void setWorkManager(GeronimoWorkManager workManager) {
82          this.workManager = workManager;
83      }
84  
85      public TransactionContextManager getTransactionContextManager() throws XAException {
86          return workManagerFactory.getTransactionContextManager();
87      }
88  
89      public void setTransactionContextManager(TransactionContextManager transactionContextManager) {
90          workManagerFactory.setTransactionContextManager(transactionContextManager);
91      }
92  
93      public int getThreadPoolSize() {
94          return workManagerFactory.getThreadPoolSize();
95      }
96  
97      public void setThreadPoolSize(int threadPoolSize) {
98          workManagerFactory.setThreadPoolSize(threadPoolSize);
99      }
100 
101     public ExtendedTransactionManager getTransactionManager() throws XAException {
102         return workManagerFactory.getTransactionManager();
103     }
104 
105     public void setTransactionManager(ExtendedTransactionManager transactionManager) {
106         workManagerFactory.setTransactionManager(transactionManager);
107     }
108 
109     public XidImporter getXidImporter() {
110         return workManagerFactory.getXidImporter();
111     }
112 
113     public void setXidImporter(XidImporter xidImporter) {
114         workManagerFactory.setXidImporter(xidImporter);
115     }
116 
117     public int getDefaultTransactionTimeoutSeconds() {
118         return workManagerFactory.getDefaultTransactionTimeoutSeconds();
119     }
120 
121     public void setDefaultTransactionTimeoutSeconds(int defaultTransactionTimeoutSeconds) {
122         workManagerFactory.setDefaultTransactionTimeoutSeconds(defaultTransactionTimeoutSeconds);
123     }
124 
125     public TransactionLog getTransactionLog() {
126         return workManagerFactory.getTransactionLog();
127     }
128 
129     public void setTransactionLog(TransactionLog transactionLog) {
130         workManagerFactory.setTransactionLog(transactionLog);
131     }
132 
133     public Collection getResourceManagers() {
134         return workManagerFactory.getResourceManagers();
135     }
136 
137     public void setResourceManagers(Collection resourceManagers) {
138         workManagerFactory.setResourceManagers(resourceManagers);
139     }
140 }