Coverage Report - org.mule.module.sxc.SxcFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
SxcFilter
0%
0/22
0%
0/12
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.module.sxc;
 8  
 
 9  
 import org.mule.api.MuleMessage;
 10  
 import org.mule.api.routing.filter.Filter;
 11  
 
 12  
 import com.envoisolutions.sxc.xpath.XPathBuilder;
 13  
 
 14  
 import org.apache.commons.logging.Log;
 15  
 import org.apache.commons.logging.LogFactory;
 16  
 
 17  
 import static org.mule.util.ClassUtils.equal;
 18  
 import static org.mule.util.ClassUtils.hash;
 19  
 
 20  
 public class SxcFilter implements Filter
 21  
 {
 22  0
     protected transient Log logger = LogFactory.getLog(getClass());
 23  
 
 24  
     private String pattern;
 25  
     
 26  
     public SxcFilter()
 27  
     {
 28  0
         super();
 29  0
     }
 30  
 
 31  
     public SxcFilter(String pattern)
 32  0
     {
 33  0
         this.pattern = pattern;
 34  0
     }
 35  
 
 36  
     public boolean accept(MuleMessage msg)
 37  
     {
 38  0
         Object accept = msg.getInvocationProperty(toString());
 39  
          
 40  0
          if (accept == null && SxcFilteringOutboundRouter.getCurrentMessage() == null) 
 41  
          {
 42  0
              return false;
 43  
          }
 44  0
          else if (accept == null)
 45  
          {
 46  0
              throw new UndefinedMatchException();
 47  
          }
 48  
          
 49  0
          return (Boolean) accept;
 50  
     }
 51  
 
 52  
     /** @return XPath expression */
 53  
     public String getPattern()
 54  
     {
 55  0
         return pattern;
 56  
     }
 57  
 
 58  
     /** @param pattern The XPath expression */
 59  
     public void setPattern(String pattern)
 60  
     {
 61  0
         this.pattern = pattern;
 62  0
     }
 63  
 
 64  
     public void addEventHandler(SxcFilteringOutboundRouter router, XPathBuilder builder)
 65  
     {    
 66  0
         builder.listen(pattern, new FilterEventHandler(router, this));
 67  0
     }
 68  
     
 69  
     public boolean equals(Object obj)
 70  
     {
 71  0
         if (this == obj) return true;
 72  0
         if (obj == null || getClass() != obj.getClass()) return false;
 73  
 
 74  0
         final SxcFilter other = (SxcFilter) obj;
 75  0
         return equal(pattern, other.pattern);
 76  
     }
 77  
 
 78  
     public int hashCode()
 79  
     {
 80  0
         return hash(new Object[]{this.getClass(), pattern});
 81  
     }
 82  
 }
 83  
 
 84