View Javadoc

1   /*
2    * $Id: SxcFilter.java 12263 2008-07-09 22:04:04Z dandiep $
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.module.sxc;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  import org.mule.api.MuleMessage;
16  import org.mule.api.routing.filter.Filter;
17  
18  import com.envoisolutions.sxc.xpath.XPathBuilder;
19  
20  public class SxcFilter implements Filter
21  {
22      protected transient Log logger = LogFactory.getLog(getClass());
23  
24      private String pattern;
25      
26      public SxcFilter()
27      {
28          super();
29      }
30  
31      public SxcFilter(String pattern)
32      {
33          this.pattern = pattern;
34      }
35  
36      public boolean accept(MuleMessage obj)
37      {
38           Object accept = obj.getProperty(toString());
39           
40           if (accept == null && SxcFilteringOutboundRouter.getCurrentMessage() == null) 
41           {
42               return false;
43           }
44           else if (accept == null)
45           {
46               throw new UndefinedMatchException();
47           }
48           
49           return ((Boolean) accept).booleanValue();
50      }
51  
52      /** @return XPath expression */
53      public String getPattern()
54      {
55          return pattern;
56      }
57  
58      /** @param pattern The XPath expression */
59      public void setPattern(String pattern)
60      {
61          this.pattern = pattern;
62      }
63  
64      public void addEventHandler(SxcFilteringOutboundRouter router, XPathBuilder builder)
65      {    
66      	builder.listen(pattern, new FilterEventHandler(router, this));
67      }
68  }
69  
70