1 17 package org.apache.servicemix.expression; 18 19 import javax.jbi.messaging.MessageExchange; 20 import javax.jbi.messaging.NormalizedMessage; 21 import javax.xml.namespace.QName ; 22 import javax.xml.xpath.XPathVariableResolver ; 23 24 30 public class MessageVariableResolver implements XPathVariableResolver { 31 public static final String SYSTEM_PROPERTIES_NAMESPACE = "http://servicemix.org/xml/variables/system-properties"; 32 public static final String ENVIRONMENT_VARIABLES = "http://servicemix.org/xml/variables/environment-variables"; 33 34 private MessageExchange exchange; 35 private NormalizedMessage message; 36 37 public MessageExchange getExchange() { 38 return exchange; 39 } 40 41 public void setExchange(MessageExchange exchange) { 42 this.exchange = exchange; 43 } 44 45 public NormalizedMessage getMessage() { 46 return message; 47 } 48 49 public void setMessage(NormalizedMessage message) { 50 this.message = message; 51 } 52 53 public Object resolveVariable(QName name) { 54 String uri = name.getNamespaceURI(); 56 String localPart = name.getLocalPart(); 57 58 Object answer = null; 59 60 if (uri == null || uri.length() == 0) { 61 answer = message.getProperty(localPart); 62 if (answer == null) { 63 answer = exchange.getProperty(localPart); 64 } 65 } 66 else if (uri.equals(SYSTEM_PROPERTIES_NAMESPACE)) { 67 answer = System.getProperty(localPart); 68 } 69 else if (uri.equals(ENVIRONMENT_VARIABLES)) { 70 answer = System.getProperty(System.getProperty(localPart)); 71 } 72 return answer; 73 } 74 } 75 | Popular Tags |