Coverage Report - org.kuali.rice.core.jta.UserTransactionFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
UserTransactionFactoryBean
0%
0/23
0%
0/10
2.5
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.core.jta;
 17  
 
 18  
 import javax.naming.NamingException;
 19  
 import javax.transaction.UserTransaction;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.kuali.rice.core.config.Config;
 23  
 import org.kuali.rice.core.config.ConfigContext;
 24  
 import org.kuali.rice.core.config.ConfigurationException;
 25  
 import org.kuali.rice.core.util.RiceConstants;
 26  
 import org.springframework.beans.factory.FactoryBean;
 27  
 import org.springframework.jndi.JndiTemplate;
 28  
 
 29  
 
 30  
 /**
 31  
  * Factory bean that supplies a UserTransaction object from the the current context
 32  
  * (i.e. plugin, embedding webapp) Config object map if defined therein (under the Config.USER_TRANSACTION key),
 33  
  * from JNDI if {@link Config#USER_TRANSACTION_JNDI} is defined,
 34  
  * or from a default declaratively assigned in containing bean factory.
 35  
  * 
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  */
 38  0
 public class UserTransactionFactoryBean implements FactoryBean {
 39  
 
 40  
         private UserTransaction defaultUserTransaction;
 41  
         private JndiTemplate jndiTemplate;
 42  
         
 43  
         public Object getObject() throws Exception {
 44  
                 
 45  0
                 if (ConfigContext.getCurrentContextConfig().getObject(RiceConstants.SPRING_TRANSACTION_MANAGER) != null) {
 46  0
                         return null;
 47  
                 }
 48  
                 
 49  0
                 UserTransaction userTransaction = (UserTransaction)ConfigContext.getCurrentContextConfig().getObject(RiceConstants.USER_TRANSACTION_OBJ);
 50  0
                 if (userTransaction == null) {
 51  0
                         String userTransactionJndiName = ConfigContext.getCurrentContextConfig().getProperty(RiceConstants.USER_TRANSACTION_JNDI);
 52  0
                         if (!StringUtils.isEmpty(userTransactionJndiName)) {
 53  0
                                 if (this.jndiTemplate == null) {
 54  0
                                     this.jndiTemplate = new JndiTemplate();
 55  
                                 }
 56  
                                 try {
 57  0
                                         userTransaction = (UserTransaction)this.jndiTemplate.lookup(userTransactionJndiName, UserTransaction.class);
 58  0
                                 } catch (NamingException e) {
 59  0
                                         throw new ConfigurationException("Could not locate the UserTransaction at the given JNDI location: '" + userTransactionJndiName + "'", e);
 60  0
                                 }
 61  
                         }
 62  
                         
 63  
                 }
 64  0
                 if (userTransaction != null) {
 65  0
                         return userTransaction;
 66  
                 }
 67  0
                 return this.defaultUserTransaction;
 68  
         }
 69  
 
 70  
         public Class getObjectType() {
 71  0
                 return UserTransaction.class;
 72  
         }
 73  
 
 74  
         public boolean isSingleton() {
 75  0
                 return true;
 76  
         }
 77  
         
 78  
         public void setDefaultUserTransaction(UserTransaction userTransaction) {
 79  0
             this.defaultUserTransaction = userTransaction;
 80  0
         }
 81  
 
 82  
         public JndiTemplate getJndiTemplate() {
 83  0
                 return this.jndiTemplate;
 84  
         }
 85  
 
 86  
         public void setJndiTemplate(JndiTemplate jndiTemplate) {
 87  0
                 this.jndiTemplate = jndiTemplate;
 88  0
         }
 89  
         
 90  
         
 91  
 
 92  
 }