| Home >> All >> org >> activemq >> [ filter Javadoc ] |
Source code: org/activemq/filter/XMLBeansXPathEvaluator.java
1 package org.activemq.filter; 2 3 import java.io.ByteArrayInputStream; 4 5 import javax.jms.BytesMessage; 6 import javax.jms.JMSException; 7 import javax.jms.Message; 8 import javax.jms.TextMessage; 9 10 import org.apache.xmlbeans.XmlObject; 11 12 public class XMLBeansXPathEvaluator implements XPathExpression.XPathEvaluator { 13 14 private final String xpath; 15 16 public XMLBeansXPathEvaluator(String xpath) { 17 this.xpath = xpath; 18 } 19 20 public boolean evaluate(Message message) throws JMSException { 21 if( message instanceof TextMessage ) { 22 String text = ((TextMessage)message).getText(); 23 try { 24 XmlObject object = XmlObject.Factory.parse(text); 25 XmlObject[] objects = object.selectPath(xpath); 26 return object!=null && objects.length>0; 27 } catch (Throwable e) { 28 return false; 29 } 30 31 } else if ( message instanceof BytesMessage ) { 32 BytesMessage bm = (BytesMessage) message; 33 byte data[] = new byte[(int) bm.getBodyLength()]; 34 bm.readBytes(data); 35 try { 36 XmlObject object = XmlObject.Factory.parse(new ByteArrayInputStream(data)); 37 XmlObject[] objects = object.selectPath(xpath); 38 return object!=null && objects.length>0; 39 } catch (Throwable e) { 40 return false; 41 } 42 } 43 return false; 44 } 45 }