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