Coverage Report - org.mule.api.registry.AbstractServiceDescriptor
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractServiceDescriptor
0%
0/13
0%
0/4
0
AbstractServiceDescriptor$Key
0%
0/16
0%
0/16
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.api.registry;
 8  
 
 9  
 import org.mule.util.ClassUtils;
 10  
 import org.mule.util.StringUtils;
 11  
 
 12  
 import java.util.Map;
 13  
 import java.util.Properties;
 14  
 
 15  
 import org.apache.commons.logging.Log;
 16  
 import org.apache.commons.logging.LogFactory;
 17  
 
 18  
 public abstract class AbstractServiceDescriptor implements ServiceDescriptor
 19  
 {
 20  
 
 21  
     /**
 22  
      * logger used by this class
 23  
      */
 24  0
     protected final Log logger = LogFactory.getLog(getClass());
 25  
 
 26  
     protected String service;
 27  
 
 28  
     public AbstractServiceDescriptor(String service)
 29  0
     {
 30  0
         this.service = service;
 31  0
     }
 32  
 
 33  
     public String getService()
 34  
     {
 35  0
         return service;
 36  
     }
 37  
 
 38  
     protected String removeProperty(String name, Properties properties)
 39  
     {
 40  0
         String temp = (String)properties.remove(name);
 41  0
         if (StringUtils.isEmpty(StringUtils.trim(temp)))
 42  
         {
 43  0
             return null;
 44  
         }
 45  
         else
 46  
         {
 47  0
             return temp;
 48  
         }
 49  
     }
 50  
 
 51  
     protected Class<?> removeClassProperty(String name, Properties properties) throws ClassNotFoundException
 52  
     {
 53  0
         String clazz = removeProperty(name, properties);
 54  0
         if (clazz == null)
 55  
         {
 56  0
             return null;
 57  
         }
 58  
         else
 59  
         {
 60  0
             return ClassUtils.loadClass(clazz, getClass());
 61  
         }
 62  
     }
 63  
 
 64  
 
 65  
 
 66  
     /**
 67  
      * Unique key used to cache the service descriptors.  This uses the service and the
 68  
      * overrides, but since it is generated externally by the factory that instantiates
 69  
      * the service descriptor we do not need to keep overrides or properties anywhere else.
 70  
      */
 71  
     public static class Key
 72  
     {
 73  
         
 74  
         private final Map<?, ?> overrides;
 75  
         private final String service;
 76  
 
 77  
         public Key(String service, Map<?, ?> overrides)
 78  0
         {
 79  0
             this.overrides = overrides;
 80  0
             this.service = service;
 81  0
         }
 82  
 
 83  
         @Override
 84  
         public boolean equals(Object o)
 85  
         {
 86  0
             if (this == o)
 87  
             {
 88  0
                 return true;
 89  
             }
 90  0
             if (!(o instanceof Key))
 91  
             {
 92  0
                 return false;
 93  
             }
 94  
 
 95  0
             final Key key = (Key)o;
 96  
 
 97  0
             if (overrides != null ? !overrides.equals(key.overrides) : key.overrides != null)
 98  
             {
 99  0
                 return false;
 100  
             }
 101  0
             if (!service.equals(key.service))
 102  
             {
 103  0
                 return false;
 104  
             }
 105  
 
 106  0
             return true;
 107  
         }
 108  
 
 109  
         @Override
 110  
         public int hashCode()
 111  
         {
 112  0
             return 29 * (overrides != null ? overrides.hashCode() : 0) + (service != null ? service.hashCode(): 0);
 113  
         }
 114  
 
 115  
         public String getKey()
 116  
         {
 117  0
             return service + ":" + Integer.toString(hashCode()); 
 118  
         }
 119  
 
 120  
     }
 121  
 
 122  
 }
 123  
 
 124