Coverage Report - org.org.usurper.springframework.UsurperFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
UsurperFactoryBean
69 %
9/13
50 %
1/2
0
 
 1  
 /*
 2  
  ORG Usurper is a random value object generator library 
 3  
  Copyright (C) 2007  Pierre-Antoine GrĂ©goire
 4  
  
 5  
  This library is free software; you can redistribute it and/or
 6  
  modify it under the terms of the GNU Lesser General Public
 7  
  License as published by the Free Software Foundation; either
 8  
  version 2.1 of the License, or (at your option) any later version.
 9  
  
 10  
  This library 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 GNU
 13  
  Lesser General Public License for more details.
 14  
  
 15  
  You should have received a copy of the GNU Lesser General Public
 16  
  License along with this library; if not, write to the Free Software
 17  
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 18  
  */
 19  
 package org.org.usurper.springframework;
 20  
 
 21  
 import org.org.usurper.UsurperGenerator;
 22  
 import org.org.usurper.setup.UsurperGeneratorSetup;
 23  
 import org.springframework.beans.factory.FactoryBean;
 24  
 import org.springframework.beans.factory.InitializingBean;
 25  
 import org.springframework.beans.factory.annotation.Required;
 26  
 
 27  
 /**
 28  
  * The Class UsurperFactoryBean is a Spring compliant FactoryBean and InitializingBean.
 29  
  * As such, it can be used as any other Spring Factory Bean.
 30  
  * It generates an Usurped object.
 31  
  */
 32  2
 public class UsurperFactoryBean implements FactoryBean, InitializingBean {
 33  
 
 34  
     private UsurperGenerator<?> usurperGenerator;
 35  
     private String usurpedClassName;
 36  
     @SuppressWarnings("unchecked")
 37  
     private Class usurpedClass;
 38  
     private UsurperGeneratorSetup usurperGeneratorSetup;
 39  
     
 40  
     public void setUsurperGeneratorSetup(UsurperGeneratorSetup usurperGeneratorSetup) {
 41  0
         this.usurperGeneratorSetup = usurperGeneratorSetup;
 42  0
     }
 43  
     
 44  
     @Required
 45  
     public void setUsurpedClassName(String usurpedClassName) {
 46  2
         this.usurpedClassName = usurpedClassName;
 47  2
     }
 48  
 
 49  
     public Object getObject() throws Exception {
 50  3
         return usurperGenerator.generateUsurper();
 51  
     }
 52  
 
 53  
     @SuppressWarnings("unchecked")
 54  
     public Class getObjectType() {
 55  0
         return usurpedClass;
 56  
     }
 57  
 
 58  
     public boolean isSingleton() {
 59  2
         return false;
 60  
     }
 61  
 
 62  
     @SuppressWarnings("unchecked")
 63  
     public void afterPropertiesSet() throws Exception {
 64  2
         usurpedClass = Class.forName(usurpedClassName);
 65  2
         if (usurperGeneratorSetup == null) {
 66  2
             usurperGenerator = new UsurperGenerator(usurpedClass);
 67  
         } else {
 68  0
             usurperGenerator = new UsurperGenerator(usurpedClass, usurperGeneratorSetup);
 69  
         }
 70  2
     }
 71  
 
 72  
 }