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  
  * $Id: PayloadTypeFilter.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.routing.filters;
 12  
 
 13  
 import static org.mule.util.ClassUtils.equal;
 14  
 import static org.mule.util.ClassUtils.hash;
 15  
 
 16  
 import org.mule.api.MuleMessage;
 17  
 import org.mule.api.routing.filter.Filter;
 18  
 import org.mule.util.ClassUtils;
 19  
 
 20  
 /**
 21  
  * <code>PayloadTypeFilter</code> filters based on the type of the object received.
 22  
  */
 23  
 
 24  
 public class PayloadTypeFilter implements Filter
 25  
 {
 26  
     private Class expectedType;
 27  
 
 28  
     public PayloadTypeFilter()
 29  
     {
 30  0
         super();
 31  0
     }
 32  
 
 33  
     public PayloadTypeFilter(String expectedType) throws ClassNotFoundException
 34  
     {
 35  0
         this(ClassUtils.loadClass(expectedType, PayloadTypeFilter.class));
 36  0
     }
 37  
 
 38  
     public PayloadTypeFilter(Class expectedType)
 39  0
     {
 40  0
         this.expectedType = expectedType;
 41  0
     }
 42  
 
 43  
     public boolean accept(MuleMessage message)
 44  
     {
 45  0
         return (expectedType != null ? expectedType.isAssignableFrom(message.getPayload().getClass()) : false);
 46  
     }
 47  
 
 48  
     public Class getExpectedType()
 49  
     {
 50  0
         return expectedType;
 51  
     }
 52  
 
 53  
     public void setExpectedType(Class expectedType)
 54  
     {
 55  0
         this.expectedType = expectedType;
 56  0
     }
 57  
     
 58  
     public boolean equals(Object obj)
 59  
     {
 60  0
         if (this == obj) return true;
 61  0
         if (obj == null || getClass() != obj.getClass()) return false;
 62  
 
 63  0
         final PayloadTypeFilter other = (PayloadTypeFilter) obj;
 64  0
         return equal(expectedType, other.expectedType);
 65  
     }
 66  
 
 67  
     public int hashCode()
 68  
     {
 69  0
         return hash(new Object[]{this.getClass(), expectedType});
 70  
     }
 71  
 }