1 18 19 package org.apache.activemq.filter; 20 21 import java.io.IOException ; 22 23 import javax.jms.JMSException ; 24 25 import org.apache.activemq.command.ActiveMQDestination; 26 import org.apache.activemq.util.JMSExceptionSupport; 27 28 29 34 public abstract class DestinationFilter implements BooleanExpression { 35 36 public static final String ANY_DESCENDENT = ">"; 37 public static final String ANY_CHILD = "*"; 38 39 public Object evaluate(MessageEvaluationContext message) throws JMSException { 40 return matches(message) ? Boolean.TRUE : Boolean.FALSE; 41 } 42 43 public boolean matches(MessageEvaluationContext message) throws JMSException { 44 try { 45 if( message.isDropped() ) 46 return false; 47 return matches(message.getMessage().getDestination()); 48 } catch (IOException e) { 49 throw JMSExceptionSupport.create(e); 50 } 51 } 52 53 public abstract boolean matches(ActiveMQDestination destination); 54 55 public static DestinationFilter parseFilter(ActiveMQDestination destination) { 56 if (destination.isComposite()) { 57 return new CompositeDestinationFilter(destination); 58 } 59 String [] paths = DestinationPath.getDestinationPaths(destination); 60 int idx = paths.length - 1; 61 if (idx >= 0) { 62 String lastPath = paths[idx]; 63 if (lastPath.equals(ANY_DESCENDENT)) { 64 return new PrefixDestinationFilter(paths); 65 } 66 else { 67 while (idx >= 0) { 68 lastPath = paths[idx--]; 69 if (lastPath.equals(ANY_CHILD)) { 70 return new WildcardDestinationFilter(paths); 71 } 72 } 73 } 74 } 75 76 return new SimpleDestinationFilter(destination); 78 } 79 } 80 | Popular Tags |