Coverage Report - org.mule.module.scripting.filter.ScriptFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
ScriptFilter
0%
0/13
N/A
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.scripting.filter;
 8  
 
 9  
 import org.mule.api.MuleEvent;
 10  
 import org.mule.api.MuleMessage;
 11  
 import org.mule.api.routing.filter.Filter;
 12  
 import org.mule.module.scripting.component.Scriptable;
 13  
 import org.mule.processor.AbstractFilteringMessageProcessor;
 14  
 
 15  
 import javax.script.Bindings;
 16  
 
 17  0
 public class ScriptFilter extends AbstractFilteringMessageProcessor implements Filter
 18  
 {
 19  
 
 20  
     private Scriptable script;
 21  
     
 22  
     private String name;
 23  
     
 24  
     @Override
 25  
     protected boolean accept(MuleEvent event)
 26  
     {
 27  0
         return this.accept(event.getMessage());
 28  
     }
 29  
     
 30  
     public boolean accept(MuleMessage message)
 31  
     {
 32  0
         Bindings bindings = script.getScriptEngine().createBindings();
 33  0
         script.populateBindings(bindings, message);
 34  
         try
 35  
         {
 36  0
             return (Boolean) script.runScript(bindings);
 37  
         }
 38  0
         catch (Throwable e)
 39  
         {
 40  0
             return false;
 41  
         }
 42  
     }
 43  
 
 44  
     public Scriptable getScript()
 45  
     {
 46  0
         return script;
 47  
     }
 48  
 
 49  
     public void setScript(Scriptable script)
 50  
     {
 51  0
         this.script = script;
 52  0
     }
 53  
 
 54  
     public String getName()
 55  
     {
 56  0
         return name;
 57  
     }
 58  
 
 59  
     public void setName(String name)
 60  
     {
 61  0
         this.name = name;
 62  0
     }
 63  
 }
 64  
 
 65