Coverage Report - org.mule.module.ibeans.config.IBeanHolderConfigurationBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
IBeanHolderConfigurationBuilder
0%
0/20
0%
0/2
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.ibeans.config;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.config.ConfigurationException;
 11  
 import org.mule.util.scan.ClasspathScanner;
 12  
 
 13  
 import java.io.IOException;
 14  
 import java.util.HashSet;
 15  
 import java.util.Set;
 16  
 
 17  
 import org.ibeans.annotation.Call;
 18  
 import org.ibeans.annotation.IBeanGroup;
 19  
 import org.ibeans.annotation.Template;
 20  
 import org.ibeans.impl.IBeansNotationHelper;
 21  
 
 22  
 /**
 23  
  * A configuration builder that registers iBean objects on the classpath with the Mule registry.
 24  
  * <p/>
 25  
  * The registry can then be used to query available iBeans.
 26  
  */
 27  
 public class IBeanHolderConfigurationBuilder extends AbstractAnnotationConfigurationBuilder
 28  
 {
 29  
     public static final String IBEAN_HOLDER_PREFIX = "_ibeanHolder.";
 30  
 
 31  
     public IBeanHolderConfigurationBuilder()
 32  
     {
 33  0
         super();
 34  0
     }
 35  
 
 36  
     public IBeanHolderConfigurationBuilder(String... basepackages)
 37  
     {
 38  0
         super(basepackages);
 39  0
     }
 40  
 
 41  
     public IBeanHolderConfigurationBuilder(ClassLoader classLoader)
 42  
     {
 43  0
         super(classLoader);
 44  0
     }
 45  
 
 46  
     public IBeanHolderConfigurationBuilder(ClassLoader classLoader, String... basepackages)
 47  
     {
 48  0
         super(classLoader, basepackages);
 49  0
     }
 50  
 
 51  
     @Override
 52  
     protected String getScanPackagesProperty()
 53  
     {
 54  0
         return "ibeans.scan.packages";
 55  
     }
 56  
 
 57  
     @SuppressWarnings("rawtypes")
 58  
     @Override
 59  
     protected void doConfigure(MuleContext muleContext) throws Exception
 60  
     {
 61  0
         Set<Class> ibeanClasses = new HashSet<Class>();
 62  0
         ClasspathScanner scanner = createClasspathScanner();
 63  
 
 64  
         try
 65  
         {
 66  
             //There will be some overlap here but only
 67  0
             ibeanClasses.addAll(scanner.scanFor(Call.class, ClasspathScanner.INCLUDE_INTERFACE));
 68  0
             ibeanClasses.addAll(scanner.scanFor(Template.class, ClasspathScanner.INCLUDE_INTERFACE));
 69  
             //Some ibeans will extend other iBeans but have not methods of there own
 70  0
             ibeanClasses.addAll(scanner.scanFor(IBeanGroup.class, ClasspathScanner.INCLUDE_INTERFACE));
 71  
         }
 72  0
         catch (IOException e)
 73  
         {
 74  0
             throw new ConfigurationException(e);
 75  0
         }
 76  
 
 77  0
         for (Class<?> ibeanClass : ibeanClasses)
 78  
         {
 79  0
             muleContext.getRegistry().registerObject(IBeansNotationHelper.getIBeanShortID(ibeanClass), new IBeanHolder(ibeanClass));
 80  
         }
 81  0
     }
 82  
 }