View Javadoc

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