View Javadoc
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.MuleException;
10  import org.mule.api.MuleMessage;
11  
12  import com.envoisolutions.sxc.xpath.XPathEvent;
13  import com.envoisolutions.sxc.xpath.XPathEventHandler;
14  
15  import javax.xml.stream.XMLStreamException;
16  
17  public class FilterEventHandler extends XPathEventHandler
18  {
19      SxcFilteringOutboundRouter router;
20      SxcFilter filter;
21      
22      public FilterEventHandler(SxcFilteringOutboundRouter router, SxcFilter filter)
23      {
24          super();
25          this.router = router;
26          this.filter = filter;
27      }
28      
29      @Override
30      public void onMatch(XPathEvent event) throws XMLStreamException
31      {
32          try 
33          {
34              MuleMessage msg = SxcFilteringOutboundRouter.getCurrentMessage();
35              msg.setInvocationProperty(filter.toString(), true);
36              
37              if (router.testMatch(msg))
38              {
39                  throw new StopProcessingException();
40              }
41          }
42          catch (UndefinedMatchException e) 
43          {
44              // ignore
45          }
46          catch (MuleException e)
47          {
48              // This shouldn't happen
49              throw new RuntimeException(e);
50          }
51      }
52  
53  }
54  
55