Coverage Report - org.mule.config.spring.processors.PropertyPlaceholderProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyPlaceholderProcessor
0%
0/24
0%
0/8
0
PropertyPlaceholderProcessor$1
N/A
N/A
0
PropertyPlaceholderProcessor$RegistryProperties
0%
0/6
0%
0/8
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.config.spring.processors;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.config.PropertyFactory;
 11  
 import org.mule.api.context.MuleContextAware;
 12  
 import org.mule.config.i18n.CoreMessages;
 13  
 
 14  
 import java.io.IOException;
 15  
 import java.util.HashMap;
 16  
 import java.util.Iterator;
 17  
 import java.util.Map;
 18  
 import java.util.Properties;
 19  
 
 20  
 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
 21  
 
 22  
 /**
 23  
  * TODO
 24  
  */
 25  0
 public class PropertyPlaceholderProcessor extends PropertyPlaceholderConfigurer implements MuleContextAware
 26  
 {
 27  
     private MuleContext muleContext;
 28  0
     private Map factories = new HashMap();
 29  
     
 30  
 
 31  
     @Override
 32  
     protected Properties mergeProperties() throws IOException
 33  
     {
 34  0
         RegistryProperties props = new RegistryProperties();
 35  0
         props.putAll(super.mergeProperties());
 36  
 
 37  
         // MuleContext/MuleConfiguration properties
 38  0
         props.put("mule.working.dir", muleContext.getConfiguration().getWorkingDirectory());
 39  
         
 40  0
         if (factories != null)
 41  
         {
 42  0
             for (Iterator iterator = factories.entrySet().iterator(); iterator.hasNext();)
 43  
             {
 44  0
                 Map.Entry entry = (Map.Entry) iterator.next();
 45  0
                 if (entry.getKey() == null)
 46  
                 {
 47  0
                     throw new NullPointerException(CoreMessages.objectIsNull("Factories.Key").getMessage());
 48  
                 }
 49  0
                 if (entry.getValue() == null)
 50  
                 {
 51  0
                     throw new NullPointerException(CoreMessages.objectIsNull("Factories.Value").getMessage());
 52  
                 }
 53  
                 try
 54  
                 {
 55  0
                     props.put(entry.getKey(), ((PropertyFactory) entry.getValue()).create(props));
 56  
                 }
 57  0
                 catch (Exception e)
 58  
                 {
 59  0
                     throw new IOException("Failed to invoke PropertyFactory: " + entry.getValue() + ". Error is: " + e.toString());
 60  0
                 }
 61  0
             }
 62  
         }
 63  0
         return props;
 64  
     }
 65  
 
 66  
     public Map getFactories()
 67  
     {
 68  0
         return factories;
 69  
     }
 70  
 
 71  
     public void setFactories(Map factories)
 72  
     {
 73  0
         this.factories = factories;
 74  0
     }
 75  
 
 76  0
     private class RegistryProperties extends Properties
 77  
     {
 78  
         public String getProperty(String key)
 79  
         {
 80  0
             Object oval = super.get(key);
 81  0
             if (oval == null)
 82  
             {
 83  0
                 oval = muleContext.getRegistry().lookupObject(key);
 84  
             }
 85  0
             String sval = (oval instanceof String) ? (String)oval : null;
 86  0
             return ((sval == null) && (defaults != null)) ? defaults.getProperty(key) : sval;
 87  
         }
 88  
     }
 89  
 
 90  
     public void setMuleContext(MuleContext muleContext)
 91  
     {
 92  0
         this.muleContext = muleContext;
 93  
         
 94  0
     }
 95  
 
 96  
 }