1 17 package org.apache.servicemix.expression; 18 19 import org.jaxen.UnresolvableException; 20 import org.jaxen.VariableContext; 21 22 import javax.jbi.messaging.MessageExchange; 23 import javax.jbi.messaging.NormalizedMessage; 24 25 import java.util.HashMap ; 26 import java.util.Map ; 27 28 34 public class JaxenVariableContext implements VariableContext { 35 public static final String MESSAGE_NAMESPACE = "http://servicemix.org/xml/variables/message"; 36 public static final String EXCHANGE_NAMESPACE = "http://servicemix.org/xml/variables/exchange"; 37 public static final String SYSTEM_PROPERTIES_NAMESPACE = "http://servicemix.org/xml/variables/system-properties"; 38 public static final String ENVIRONMENT_VARIABLES_NAMESPACE = "http://servicemix.org/xml/variables/environment-variables"; 39 40 private MessageExchange exchange; 41 private NormalizedMessage message; 42 private Map variables; 43 44 public MessageExchange getExchange() { 45 return exchange; 46 } 47 48 public void setExchange(MessageExchange exchange) { 49 this.exchange = exchange; 50 } 51 52 public NormalizedMessage getMessage() { 53 return message; 54 } 55 56 public void setMessage(NormalizedMessage message) { 57 this.message = message; 58 } 59 60 public Map getVariables() { 61 return variables; 62 } 63 64 69 public void setVariables(Map variables) { 70 this.variables = variables; 71 } 72 73 public Object getVariableValue(String uri, String prefix, String localPart) throws UnresolvableException { 74 Object answer = null; 75 76 if (uri == null || uri.length() == 0) { 77 answer = message.getProperty(localPart); 78 if (answer == null) { 79 answer = exchange.getProperty(localPart); 80 } 81 } 82 else if (uri.equals(MESSAGE_NAMESPACE)) { 83 answer = message.getProperty(localPart); 84 } 85 else if (uri.equals(EXCHANGE_NAMESPACE)) { 86 answer = message.getProperty(localPart); 87 } 88 else if (uri.equals(SYSTEM_PROPERTIES_NAMESPACE)) { 89 answer = System.getProperty(localPart); 90 } 91 else if (uri.equals(ENVIRONMENT_VARIABLES_NAMESPACE)) { 92 answer = System.getProperty(System.getProperty(localPart)); 93 } 94 return answer; 95 } 96 97 103 public void setVariableValue(String localPart, Object value) { 104 if (variables == null) { 105 variables = new HashMap (); 106 } 107 variables.put(localPart, value); 108 } 109 110 } 111 | Popular Tags |