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