Coverage Report - org.mule.config.spring.parsers.assembly.MapEntryCombiner
 
Classes in this File Line Coverage Branch Coverage Complexity
MapEntryCombiner
0%
0/34
0%
0/4
1.167
 
 1  
 /*
 2  
  * $Id: MapEntryCombiner.java 10489 2008-01-23 17:53:38Z dfeist $
 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.parsers.assembly;
 12  
 
 13  
 import java.util.Collection;
 14  
 import java.util.HashMap;
 15  
 import java.util.Map;
 16  
 import java.util.Set;
 17  
 
 18  
 /**
 19  
  * This is used internally by {@link org.mule.config.spring.parsers.assembly.DefaultBeanAssembler}
 20  
  * along with {@link org.mule.config.spring.parsers.collection.ChildSingletonMapDefinitionParser}.
 21  
  * It creates a map with a single key/value pair.  This may seem odd, but the result is not
 22  
  * manipulated within the assembler - that means that, unlike
 23  
  * {@link org.mule.config.spring.parsers.collection.ChildMapEntryDefinitionParser}, this element
 24  
  * can contain nested values.  Note that most uses will set
 25  
  * {@link org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration#isCollection(String)}
 26  
  * so that several entries can be combined.
 27  
  */
 28  0
 public class MapEntryCombiner implements Map
 29  
 {
 30  
 
 31  
     public static final String KEY = "key";
 32  
     public static final String VALUE = "value";
 33  
 
 34  
     private Object key;
 35  
     private Object value;
 36  0
     private Map cachedMerge = new HashMap();
 37  0
     private boolean isMerged = false;
 38  
 
 39  
     private synchronized Map getCachedMerge()
 40  
     {
 41  0
         if (!isMerged)
 42  
         {
 43  0
             cachedMerge.put(key, value);
 44  0
             isMerged = true;
 45  
         }
 46  0
         return cachedMerge;
 47  
     }
 48  
 
 49  
     public Object getKey()
 50  
     {
 51  0
         assertNotMerged();
 52  0
         return key;
 53  
     }
 54  
 
 55  
     public void setKey(Object key)
 56  
     {
 57  0
         assertNotMerged();
 58  0
         this.key = key;
 59  0
     }
 60  
 
 61  
     public Object getValue()
 62  
     {
 63  0
         assertNotMerged();
 64  0
         return value;
 65  
     }
 66  
 
 67  
     public void setValue(Object value)
 68  
     {
 69  0
         assertNotMerged();
 70  0
         this.value = value;
 71  0
     }
 72  
 
 73  
     private synchronized void assertNotMerged()
 74  
     {
 75  0
         if (isMerged)
 76  
         {
 77  0
             throw new IllegalStateException("Maps have already been merged");
 78  
         }
 79  0
     }
 80  
 
 81  
     // map delegates (except hashCode and equals)
 82  
 
 83  
     public int size()
 84  
     {
 85  0
         return getCachedMerge().size();
 86  
     }
 87  
 
 88  
     public void clear()
 89  
     {
 90  0
         getCachedMerge().clear();
 91  0
     }
 92  
 
 93  
     public boolean isEmpty()
 94  
     {
 95  0
         return getCachedMerge().isEmpty();
 96  
     }
 97  
 
 98  
     public boolean containsKey(Object key)
 99  
     {
 100  0
         return getCachedMerge().containsKey(key);
 101  
     }
 102  
 
 103  
     public boolean containsValue(Object value)
 104  
     {
 105  0
         return getCachedMerge().containsValue(value);
 106  
     }
 107  
 
 108  
     public Collection values()
 109  
     {
 110  0
         return getCachedMerge().values();
 111  
     }
 112  
 
 113  
     public void putAll(Map t)
 114  
     {
 115  0
         getCachedMerge().putAll(t);
 116  0
     }
 117  
 
 118  
     public Set entrySet()
 119  
     {
 120  0
         return getCachedMerge().entrySet();
 121  
     }
 122  
 
 123  
     public Set keySet()
 124  
     {
 125  0
         return getCachedMerge().keySet();
 126  
     }
 127  
 
 128  
     public Object get(Object key)
 129  
     {
 130  0
         return getCachedMerge().get(key);
 131  
     }
 132  
 
 133  
     public Object remove(Object key)
 134  
     {
 135  0
         return getCachedMerge().remove(key);
 136  
     }
 137  
 
 138  
     public Object put(Object key, Object value)
 139  
     {
 140  0
         return getCachedMerge().put(key, value);
 141  
     }
 142  
 
 143  
 }