Coverage Report - org.mule.routing.filters.PayloadTypeFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
PayloadTypeFilter
0%
0/16
0%
0/8
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.routing.filters;
 8  
 
 9  
 import static org.mule.util.ClassUtils.equal;
 10  
 import static org.mule.util.ClassUtils.hash;
 11  
 
 12  
 import org.mule.api.MuleMessage;
 13  
 import org.mule.api.routing.filter.Filter;
 14  
 import org.mule.util.ClassUtils;
 15  
 
 16  
 /**
 17  
  * <code>PayloadTypeFilter</code> filters based on the type of the object received.
 18  
  */
 19  
 
 20  
 public class PayloadTypeFilter implements Filter
 21  
 {
 22  
     private Class expectedType;
 23  
 
 24  
     public PayloadTypeFilter()
 25  
     {
 26  0
         super();
 27  0
     }
 28  
 
 29  
     public PayloadTypeFilter(String expectedType) throws ClassNotFoundException
 30  
     {
 31  0
         this(ClassUtils.loadClass(expectedType, PayloadTypeFilter.class));
 32  0
     }
 33  
 
 34  
     public PayloadTypeFilter(Class expectedType)
 35  0
     {
 36  0
         this.expectedType = expectedType;
 37  0
     }
 38  
 
 39  
     public boolean accept(MuleMessage message)
 40  
     {
 41  0
         return (expectedType != null ? expectedType.isAssignableFrom(message.getPayload().getClass()) : false);
 42  
     }
 43  
 
 44  
     public Class getExpectedType()
 45  
     {
 46  0
         return expectedType;
 47  
     }
 48  
 
 49  
     public void setExpectedType(Class expectedType)
 50  
     {
 51  0
         this.expectedType = expectedType;
 52  0
     }
 53  
     
 54  
     public boolean equals(Object obj)
 55  
     {
 56  0
         if (this == obj) return true;
 57  0
         if (obj == null || getClass() != obj.getClass()) return false;
 58  
 
 59  0
         final PayloadTypeFilter other = (PayloadTypeFilter) obj;
 60  0
         return equal(expectedType, other.expectedType);
 61  
     }
 62  
 
 63  
     public int hashCode()
 64  
     {
 65  0
         return hash(new Object[]{this.getClass(), expectedType});
 66  
     }
 67  
 }