Coverage Report - org.mule.config.spring.SpringXmlConfigurationBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
SpringXmlConfigurationBuilder
0%
0/33
0%
0/2
1.3
 
 1  
 /*
 2  
  * $Id: SpringXmlConfigurationBuilder.java 10761 2008-02-10 21:43:57Z rossmason $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.config.spring;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.config.ConfigurationException;
 15  
 import org.mule.api.registry.Registry;
 16  
 import org.mule.config.ConfigResource;
 17  
 import org.mule.config.builders.AbstractResourceConfigurationBuilder;
 18  
 
 19  
 import org.springframework.beans.BeansException;
 20  
 import org.springframework.context.ApplicationContext;
 21  
 
 22  
 /**
 23  
  * <code>SpringXmlConfigurationBuilder</code> enables Mule to be configured from a
 24  
  * Spring XML Configuration file used with Mule name-spaces. Multiple configuration
 25  
  * files can be loaded from this builder (specified as a comma-separated list).
 26  
  */
 27  
 public class SpringXmlConfigurationBuilder extends AbstractResourceConfigurationBuilder
 28  
 {
 29  0
     protected String defaultConfigResourceName = "default-mule-config.xml";
 30  
 
 31  
     protected ApplicationContext parentContext;
 32  
 
 33  
     public SpringXmlConfigurationBuilder(String configResources, ApplicationContext parentContext) throws ConfigurationException
 34  
     {
 35  0
         super(configResources);
 36  0
         this.parentContext = parentContext;
 37  0
     }
 38  
 
 39  
     public SpringXmlConfigurationBuilder(String[] configResources, ApplicationContext parentContext) throws ConfigurationException
 40  
     {
 41  0
         super(configResources);
 42  0
         this.parentContext = parentContext;
 43  0
     }
 44  
 
 45  
     public SpringXmlConfigurationBuilder(String[] configResources) throws ConfigurationException
 46  
     {
 47  0
         this(configResources, null);
 48  0
     }
 49  
 
 50  
     public SpringXmlConfigurationBuilder(String configResources) throws ConfigurationException
 51  
     {
 52  0
         this(configResources, null);
 53  0
     }
 54  
 
 55  
     public SpringXmlConfigurationBuilder(ConfigResource[] configResources, ApplicationContext parentContext)
 56  
     {
 57  0
         super(configResources);
 58  0
         this.parentContext = parentContext;
 59  0
     }
 60  
 
 61  
     public SpringXmlConfigurationBuilder(ConfigResource[] configResources)
 62  
     {
 63  0
         this(configResources, null);
 64  0
     }
 65  
 
 66  
     protected void doConfigure(MuleContext muleContext) throws Exception
 67  
     {
 68  0
         ConfigResource[] all = new ConfigResource[configResources.length + 1];
 69  0
         all[0] = new ConfigResource(defaultConfigResourceName);
 70  0
         System.arraycopy(configResources, 0, all, 1, configResources.length);
 71  0
         createSpringParentRegistry(muleContext, muleContext.getRegistry(), all);
 72  0
     }
 73  
 
 74  
     /**
 75  
      * Creates a Spring ApplicationContext from the configuration resources provided
 76  
      * and sets it as the parent Registry. This releationshio is setup with the
 77  
      * MuleApplicationContext constructor to ensure that the Registry can be used
 78  
      * during the initialization phase of Spring.
 79  
      * 
 80  
      * @param muleContext
 81  
      * @param registry
 82  
      * @param all
 83  
      * @see MuleApplicationContext#setupParentSpringRegistry(Registry registry
 84  
      */
 85  
     protected void createSpringParentRegistry(MuleContext muleContext, Registry registry, ConfigResource[] all)
 86  
     {
 87  
         try
 88  
         {
 89  0
             if (parentContext != null)
 90  
             {
 91  0
                 new MuleApplicationContext(muleContext, registry, all, parentContext);
 92  
             }
 93  
             else
 94  
             {
 95  0
                 new MuleApplicationContext(muleContext, registry, all);
 96  
             }
 97  
         }
 98  0
         catch (BeansException e)
 99  
         {
 100  
             // If creation of MuleApplicationContext fails, remove
 101  
             // TransientRegistry->SpringRegistry parent relationship
 102  0
             registry.setParent(null);
 103  0
             throw e;
 104  0
         }
 105  0
     }
 106  
 
 107  
     public void setDefaultConfigResourceName(String defaultConfigResourceName)
 108  
     {
 109  0
         this.defaultConfigResourceName = defaultConfigResourceName;
 110  0
     }
 111  
 
 112  
     public void setParentContext(ApplicationContext parentContext)
 113  
     {
 114  0
         this.parentContext = parentContext;
 115  0
     }
 116  
 
 117  
 }