Coverage Report - org.jtheque.core.managers.beans.ioc.SpringContainer
 
Classes in this File Line Coverage Branch Coverage Complexity
SpringContainer
0 %
0/17
0 %
0/2
1.143
 
 1  
 package org.jtheque.core.managers.beans.ioc;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 import org.springframework.context.ApplicationContext;
 21  
 import org.springframework.context.support.AbstractMessageSource;
 22  
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.Collection;
 26  
 
 27  
 /**
 28  
  * The spring context. This class is responsible for the Spring Application Context.
 29  
  *
 30  
  * @author Baptiste Wicht
 31  
  */
 32  
 public final class SpringContainer implements IocContainer {
 33  
     private ClassPathXmlApplicationContext applicationContext;
 34  
 
 35  0
     private final Collection<String> files = new ArrayList<String>(10);
 36  
 
 37  
     /**
 38  
      * Construct a new SpringContainer.
 39  
      */
 40  
     public SpringContainer() {
 41  0
         super();
 42  
 
 43  0
         files.add("org/jtheque/core/spring/core-beans.xml");
 44  0
     }
 45  
 
 46  
     @Override
 47  
     public AbstractMessageSource getResourceBundle() {
 48  0
         return (AbstractMessageSource) getApplicationContext().getBean("messageSource");
 49  
     }
 50  
 
 51  
     @Override
 52  
     public ApplicationContext getApplicationContext() {
 53  0
         return applicationContext;
 54  
     }
 55  
 
 56  
     @Override
 57  
     public void loadContext() {
 58  0
         LogFactory.getLog(SpringContainer.class).debug("Load Spring with XML files : " + files);
 59  
 
 60  0
         applicationContext = new ClassPathXmlApplicationContext(files.toArray(new String[files.size()]));
 61  0
         applicationContext.registerShutdownHook();
 62  0
     }
 63  
 
 64  
     @Override
 65  
     public void destroy() {
 66  0
         if (applicationContext != null) {
 67  0
             applicationContext.destroy();
 68  
         }
 69  0
     }
 70  
 
 71  
     @Override
 72  
     public void inject(Object bean) {
 73  0
         applicationContext.getAutowireCapableBeanFactory().autowireBean(bean);
 74  0
     }
 75  
 
 76  
     @Override
 77  
     public void addBeansFile(String file) {
 78  0
         files.add(file);
 79  0
     }
 80  
 }