User: user57
Date: 01/08/21 17:53:35
Modified: src/main/org/jboss/mq/selectors Selector.java
Log:
o added some commented logging (too verbose to leave it for now)
o changed exceptions to return a bit more detail
Revision Changes Path
1.3 +105 -62 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Selector.java 2001/08/17 03:04:06 1.2
+++ Selector.java 2001/08/22 00:53:35 1.3
@@ -8,10 +8,12 @@
import java.util.HashMap;
import java.util.Iterator;
-import javax.jms.InvalidSelectorException;
+import javax.jms.InvalidSelectorException;
import javax.jms.JMSException;
+import org.apache.log4j.Category;
+
import org.jboss.mq.SpyMessage;
/**
@@ -19,112 +21,153 @@
*
* @author Norbert Lataille ([EMAIL PROTECTED])
* @author Juha Lindfors ([EMAIL PROTECTED])
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @created August 16, 2001
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
-public class Selector {
- public HashMap identifiers;
- // HashMap of Identifiers
- public Object result;
+public class Selector
+{
+ public HashMap identifiers;
+ public Object result;
+ private Class resultType;
+
+ static Category cat = Category.getInstance(Selector.class);
- static org.apache.log4j.Category cat = org.apache.log4j.Category.getInstance(
Selector.class );
-
- public Selector( String sel )
- throws JMSException {
+ public Selector(String sel) throws JMSException {
parser bob = new parser();
identifiers = new HashMap();
try {
- result = bob.parse( sel, identifiers );
- } catch ( Exception e ) {
- InvalidSelectorException exception = new InvalidSelectorException( "The
selector is invalid." );
- exception.setLinkedException( e );
+ result = bob.parse(sel, identifiers);
+ resultType = result.getClass();
+ }
+ catch (Exception e) {
+ InvalidSelectorException exception =
+ new InvalidSelectorException("The selector is invalid.");
+ exception.setLinkedException(e);
throw exception;
}
- //Log.notice(result.toString());
+// if (cat.isDebugEnabled()) {
+// cat.debug("result: " + resultType + " = " + result);
+// }
}
-
- public boolean test( SpyMessage mes )
- throws JMSException {
+ public boolean test(SpyMessage mes) throws JMSException {
try {
-
- //Set the identifiers values
+ // Set the identifiers values
Iterator i = identifiers.values().iterator();
-
- while ( i.hasNext() ) {
- Identifier id = ( Identifier )i.next();
- Object find = mes.getObjectProperty( id.name );
+ while (i.hasNext()) {
+ Identifier id = (Identifier)i.next();
+ Object find = mes.getObjectProperty(id.name);
+// if (cat.isDebugEnabled()) {
+// cat.debug("Identifier: " + id);
+// cat.debug("Property: " + find);
+// if (find != null) {
+// cat.debug("Property type: " + find.getClass());
+// }
+// }
- if ( find == null ) {
- find = getHeaderFieldReferences( mes, id.name );
+ if (find == null) {
+ find = getHeaderFieldReferences(mes, id.name);
}
- if ( find == null ) {
- cat.debug( "Warning : missing property " + id.name );
+ if (find == null) {
+ if (cat.isDebugEnabled()) {
+ cat.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 ) ) {
+ 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))
+ {
id.value = find;
- } else {
- throw new Exception( "Bad property type !" );
+ }
+ else {
+ throw new Exception("Bad property type: " + type);
}
- //Log.notice("SEL:"+id.name+" =>"+id.value);
+
+// if (cat.isDebugEnabled()) {
+// cat.debug("SEL:" + id.name + " =>" + id.value);
+// }
}
}
- //Compute the result of this operator
+ // Compute the result of this operator
Object res;
- if ( result.getClass().equals( Identifier.class ) ) {
- res = ( ( Identifier )result ).value;
- } else if ( result.getClass().equals( Operator.class ) ) {
- res = ( ( Operator )result ).apply();
- } else {
+ if (resultType.equals(Identifier.class)) {
+ res = ((Identifier)result).value;
+ }
+ else if (resultType.equals(Operator.class)) {
+ res = ((Operator)result).apply();
+ }
+ else {
res = result;
}
- if ( res == null ) {
+// if (cat.isDebugEnabled()) {
+// cat.debug("res: " + res);
+// if (result != null) {
+// cat.debug("res type: " + res.getClass());
+// }
+// }
+
+ if (res == null) {
return false;
}
- if ( !( res.getClass().equals( Boolean.class ) ) ) {
- throw new Exception( "Bad object type" );
+
+ if (!(res.getClass().equals(Boolean.class))) {
+ throw new Exception("Bad object type: " + res);
}
- //Log.notice("Selectors =>"+res);
+// if (cat.isDebugEnabled()) {
+// cat.debug("Selectors =>" + res);
+// }
- return ( ( Boolean )res ).booleanValue();
- } catch ( Exception e ) {
- throw new JMSException( "SELECTOR: " + e.getMessage() );
+ return ((Boolean )res).booleanValue();
}
+ catch (Exception e) {
+ throw new JMSException("SELECTOR: " + e.getMessage());
+ }
}
// [JPL]
- private Object getHeaderFieldReferences( SpyMessage msg, String idName )
- throws JMSException {
-
+ private Object getHeaderFieldReferences(SpyMessage msg, String idName)
+ 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" ) ) {
- return new Integer( msg.getJMSDeliveryMode() );
- } else if ( idName.equals( "JMSPriority" ) ) {
- return new Integer( msg.getJMSPriority() );
- } else if ( idName.equals( "JMSMessageID" ) ) {
+ //
+ if (idName.equals("JMSDeliveryMode")) {
+ return new Integer(msg.getJMSDeliveryMode());
+ }
+ else if (idName.equals("JMSPriority")) {
+ return new Integer(msg.getJMSPriority());
+ }
+ else if (idName.equals("JMSMessageID")) {
return msg.getJMSMessageID();
- } else if ( idName.equals( "JMSTimestamp" ) ) {
- return new Long( msg.getJMSTimestamp() );
- } else if ( idName.equals( "JMSCorrelationID" ) ) {
+ }
+ else if (idName.equals("JMSTimestamp")) {
+ return new Long(msg.getJMSTimestamp());
+ }
+ 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]
http://lists.sourceforge.net/lists/listinfo/jboss-development