View Javadoc

1   /*
2    * $Id: FilterEventHandler.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.mule.api.MuleMessage;
14  import org.mule.api.routing.RoutingException;
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.setProperty(filter.toString(), true);
40              
41              if (router.testMatch(msg))
42              {
43                  throw new StopProcessingException();
44              }
45          }
46          catch (UndefinedMatchException e) 
47          {
48          }
49          catch (RoutingException e)
50          {
51              // This shouldn't happen
52              throw new RuntimeException(e);
53          }
54      }
55  
56  }
57  
58