[Ubermq-commits] jms/src/com/ubermq/jms/server/routing/impl SimpleSelector.java,1.3,1.4
Brought to you by:
jimmyp
From: <ji...@us...> - 2002-12-12 18:01:53
|
Update of /cvsroot/ubermq/jms/src/com/ubermq/jms/server/routing/impl In directory sc8-pr-cvs1:/tmp/cvs-serv797/src/com/ubermq/jms/server/routing/impl Modified Files: SimpleSelector.java Log Message: JMS 1.1 support (full backwards compatibility) queue support (incomplete - functional, but w/o administrative capabilities) Index: SimpleSelector.java =================================================================== RCS file: /cvsroot/ubermq/jms/src/com/ubermq/jms/server/routing/impl/SimpleSelector.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SimpleSelector.java 12 Sep 2002 22:23:10 -0000 1.3 --- SimpleSelector.java 12 Dec 2002 18:01:51 -0000 1.4 *************** *** 13,90 **** */ public class SimpleSelector ! implements Selector { ! private String property, scalar; ! private int operator; ! private boolean valid; ! ! private static final int EQUALS = 0, GREATER = 1, LESS = 2, NOTEQUAL = 3; ! private static final String WHERE_REGEX = "where\\s*(\\w*)\\s*(=|>|<|!=|<>)\\s*(\\w*)"; ! ! public SimpleSelector(String sz) ! { ! // parse the string. ! Pattern p = Pattern.compile(WHERE_REGEX, Pattern.CASE_INSENSITIVE); ! Matcher m = p.matcher(sz); ! ! if (m.matches()) { ! property = m.group(1); ! scalar = m.group(3); ! ! String op = m.group(2); ! if (op.equals("=")) operator = EQUALS; ! else if (op.equals("<>") || op.equals("!=")) operator = NOTEQUAL; ! else if (op.equals(">")) operator = GREATER; ! else if (op.equals("<")) operator = LESS; ! else operator = EQUALS; ! ! if (scalar.equalsIgnoreCase("NULL")) ! scalar = null; ! ! valid = true; ! } ! else valid = false; ! } ! ! public boolean accept(IMessageDatagram msg) ! { ! Object value = null; ! ! // if we are not valid, return false for everything. ! if (!valid) return false; ! ! if (property.equals("JMSDeliveryMode")) { ! value = msg.getStandardProperty(IMessageDatagram.STDPROP_DELIVERYMODE); ! } else if (property.equals("JMSPriority")) { ! value = msg.getStandardProperty(IMessageDatagram.STDPROP_PRIORITY); ! } else if (property.equals("JMSMessageID")) { ! value = msg.getMessageId(); ! } else if (property.equals("JMSTimestamp")) { ! value = msg.getStandardProperty(IMessageDatagram.STDPROP_TIMESTAMP); ! } else if (property.equals("JMSCorrelationID")) { ! value = msg.getStandardProperty(IMessageDatagram.STDPROP_CORRELATIONID); ! } else { ! value = msg.getCustomProperty(property); ! } ! ! com.ubermq.Utility.getLogger().fine("selector comparing " + property + " containing " + value + " with " + scalar); ! ! if (value == null || scalar == null) { ! return (value == null && scalar == null && operator == EQUALS); ! } else { ! switch(operator) { ! case EQUALS: ! return (value.toString().equals(scalar)); ! case NOTEQUAL: ! return !(value.toString().equals(scalar)); ! default: ! return false; ! } ! } ! } ! ! public String toString() ! { ! return "Property: " + property + " operator: " + operator + " scalar: " + scalar; ! } } --- 13,90 ---- */ public class SimpleSelector ! implements Selector { ! private String property, scalar; ! private int operator; ! private boolean valid; ! ! private static final int EQUALS = 0, GREATER = 1, LESS = 2, NOTEQUAL = 3; ! public static final String WHERE_REGEX = "where\\s*(\\S*)\\s*(=|>|<|!=|<>)\\s*'??([^']*)'??"; ! ! public SimpleSelector(String sz) ! { ! // parse the string. ! Pattern p = Pattern.compile(WHERE_REGEX, Pattern.CASE_INSENSITIVE); ! Matcher m = p.matcher(sz); ! ! if (m.matches()) { ! property = m.group(1); ! scalar = m.group(3); ! ! String op = m.group(2); ! if (op.equals("=")) operator = EQUALS; ! else if (op.equals("<>") || op.equals("!=")) operator = NOTEQUAL; ! else if (op.equals(">")) operator = GREATER; ! else if (op.equals("<")) operator = LESS; ! else operator = EQUALS; ! ! if (scalar.equalsIgnoreCase("NULL")) ! scalar = null; ! ! valid = true; ! } ! else valid = false; ! } ! ! public boolean accept(IMessageDatagram msg) ! { ! Object value = null; ! ! // if we are not valid, return false for everything. ! if (!valid) return false; ! ! if (property.equals("JMSDeliveryMode")) { ! value = msg.getStandardProperty(IMessageDatagram.STDPROP_DELIVERYMODE); ! } else if (property.equals("JMSPriority")) { ! value = msg.getStandardProperty(IMessageDatagram.STDPROP_PRIORITY); ! } else if (property.equals("JMSMessageID")) { ! value = msg.getMessageId(); ! } else if (property.equals("JMSTimestamp")) { ! value = msg.getStandardProperty(IMessageDatagram.STDPROP_TIMESTAMP); ! } else if (property.equals("JMSCorrelationID")) { ! value = msg.getStandardProperty(IMessageDatagram.STDPROP_CORRELATIONID); ! } else { ! value = msg.getCustomProperty(property); ! } ! ! com.ubermq.Utility.getLogger().fine("selector comparing " + property + " containing " + value + " with " + scalar); ! ! if (value == null || scalar == null) { ! return (value == null && scalar == null && operator == EQUALS); ! } else { ! switch(operator) { ! case EQUALS: ! return (value.toString().equals(scalar)); ! case NOTEQUAL: ! return !(value.toString().equals(scalar)); ! default: ! return false; ! } ! } ! } ! ! public String toString() ! { ! return "Property: " + property + " operator: " + operator + " scalar: " + scalar; ! } } |