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