1 10 11 package org.mule.routing.filters; 12 13 import ognl.Ognl; 14 import ognl.OgnlException; 15 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 18 import org.mule.umo.UMOFilter; 19 import org.mule.umo.UMOMessage; 20 21 public class OGNLFilter implements UMOFilter 22 { 23 private static final Log logger = LogFactory.getLog(OGNLFilter.class); 24 25 private String expression; 26 27 public String getExpression() 28 { 29 return expression; 30 } 31 32 public void setExpression(String expression) 33 { 34 this.expression = expression; 35 } 36 37 public boolean accept(UMOMessage message) 38 { 39 if (message == null) 40 { 41 return false; 42 } 43 44 Object candidate = message.getPayload(); 45 if (candidate == null) 46 { 47 return false; 48 } 49 50 if (expression == null) 51 { 52 logger.warn("Expression for OGNLFilter is not set"); 53 return false; 54 } 55 56 try 57 { 58 Object result = Ognl.getValue(expression, candidate); 59 if (result instanceof Boolean ) 60 { 61 return ((Boolean )result).booleanValue(); 62 } 63 } 64 65 catch (OgnlException ex) 66 { 67 logger.error("Error evaluating OGNL expression.", ex); 68 } 69 70 return false; 72 } 73 74 } 75 | Popular Tags |