User: starksm Date: 01/11/27 22:15:32 Modified: src/main/org/jboss/mq/selectors Tag: Branch_2_4 Selector.java Log: Complete switch to org.jboss.logging.Logger and use trace to reduce default logging Add support for package version manifest headers Revision Changes Path No revision No revision 1.3.2.2 +84 -49 jbossmq/src/main/org/jboss/mq/selectors/Selector.java Index: Selector.java =================================================================== RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/selectors/Selector.java,v retrieving revision 1.3.2.1 retrieving revision 1.3.2.2 diff -u -r1.3.2.1 -r1.3.2.2 --- Selector.java 2001/08/23 03:57:12 1.3.2.1 +++ Selector.java 2001/11/28 06:15:32 1.3.2.2 @@ -12,6 +12,7 @@ import javax.jms.JMSException; +import org.jboss.logging.Logger; import org.jboss.mq.SpyMessage; /** @@ -20,111 +21,145 @@ * @author Norbert Lataille ([EMAIL PROTECTED]) * @author Juha Lindfors ([EMAIL PROTECTED]) * @created August 16, 2001 - * @version $Revision: 1.3.2.1 $ + * @version $Revision: 1.3.2.2 $ */ -public class Selector { +public class Selector +{ + static Logger log = Logger.getLogger( Selector.class ); + public HashMap identifiers; // HashMap of Identifiers public Object result; - - static org.apache.log4j.Category cat = org.apache.log4j.Category.getInstance( Selector.class ); - + public Selector( String sel ) - throws JMSException { + throws JMSException + { parser bob = new parser(); identifiers = new HashMap(); - - try { + + try + { result = bob.parse( sel, identifiers ); - } catch ( Exception e ) { + } catch ( Exception e ) + { InvalidSelectorException exception = new InvalidSelectorException( "The selector is invalid." ); exception.setLinkedException( e ); throw exception; } - + //Log.notice(result.toString()); } - + public boolean test( SpyMessage mes ) - throws JMSException { - - try { - + throws JMSException + { + + try + { + //Set the identifiers values Iterator i = identifiers.values().iterator(); - - while ( i.hasNext() ) { + + while ( i.hasNext() ) + { Identifier id = ( Identifier )i.next(); - + Object find = mes.getObjectProperty( id.name ); - - if ( find == null ) { + + if ( find == null ) + { find = getHeaderFieldReferences( mes, id.name ); } - - if ( find == null ) { - cat.debug( "Warning : missing property " + id.name ); + + if ( find == null ) + { + log.debug( "Warning : missing property " + id.name ); id.value = null; - } else { + } else + { Class type = find.getClass(); if ( type.equals( Boolean.class ) || type.equals( String.class ) - || type.equals( Double.class ) || type.equals( Float.class ) - || type.equals( Integer.class ) || type.equals( Long.class ) - || type.equals( Short.class ) || type.equals( Byte.class ) ) { + || type.equals( Double.class ) || type.equals( Float.class ) + || type.equals( Integer.class ) || type.equals( Long.class ) + || type.equals( Short.class ) || type.equals( Byte.class ) ) + { id.value = find; - } else { + } + else + { throw new Exception( "Bad property type !" ); } //Log.notice("SEL:"+id.name+" =>"+id.value); } } - + //Compute the result of this operator Object res; - - if ( result.getClass().equals( Identifier.class ) ) { + + if ( result.getClass().equals( Identifier.class ) ) + { res = ( ( Identifier )result ).value; - } else if ( result.getClass().equals( Operator.class ) ) { + } else if ( result.getClass().equals( Operator.class ) ) + { res = ( ( Operator )result ).apply(); - } else { + } else + { res = result; } - - if ( res == null ) { + + if ( res == null ) + { return false; } - if ( !( res.getClass().equals( Boolean.class ) ) ) { + if ( !( res.getClass().equals( Boolean.class ) ) ) + { throw new Exception( "Bad object type" ); } - + //Log.notice("Selectors =>"+res); - + return ( ( Boolean )res ).booleanValue(); - } catch ( Exception e ) { + } + catch ( Exception e ) + { throw new JMSException( "SELECTOR: " + e.getMessage() ); } } - + // [JPL] private Object getHeaderFieldReferences( SpyMessage msg, String idName ) - throws JMSException { - + throws JMSException + { + // JMS 3.8.1.1 -- Message header field references are restricted to: // JMSDeliveryMode, JMSPriority, JMSMessageID, // JMSTimeStamp, JMSCorrelationID and JMSType - if ( idName.equals( "JMSDeliveryMode" ) ) { + if ( idName.equals( "JMSDeliveryMode" ) ) + { return new Integer( msg.getJMSDeliveryMode() ); - } else if ( idName.equals( "JMSPriority" ) ) { + } + else if ( idName.equals( "JMSPriority" ) ) + { return new Integer( msg.getJMSPriority() ); - } else if ( idName.equals( "JMSMessageID" ) ) { + } + else if ( idName.equals( "JMSMessageID" ) ) + { return msg.getJMSMessageID(); - } else if ( idName.equals( "JMSTimestamp" ) ) { + } + else if ( idName.equals( "JMSTimestamp" ) ) + { return new Long( msg.getJMSTimestamp() ); - } else if ( idName.equals( "JMSCorrelationID" ) ) { + } + else if ( idName.equals( "JMSCorrelationID" ) ) + { return msg.getJMSCorrelationID(); - } else if ( idName.equals( "JMSType" ) ) { + } + else if ( idName.equals( "JMSType" ) ) + { return msg.getJMSType(); - } else { + } + else + { return null; } }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development