| 1 2 package org.mr.core.util.patterns.flow; 3 4 import org.mr.api.jms.MantaMessage; 5 import org.mr.core.protocol.MantaBusMessage; 6 import org.mr.core.protocol.RecipientAddress; 7 import org.mr.core.util.exceptions.CreationException; 8 import org.mr.core.util.patterns.flow.AbstractCondition; 9 import org.mr.kernel.dmf.DMFObject; 10 import org.w3c.dom.Element ; 11 12 import javax.jms.JMSException ; 13 import java.lang.reflect.InvocationTargetException ; 14 import java.lang.reflect.Method ; 15 16 61 public class MessageCondition extends AbstractCondition{ 62 63 protected final static String HEADER = "header"; 64 protected final static String PROPERTY = "property"; 65 protected final static String JMS_HEADER = "jms-header"; 66 protected final static String RECIPIENT = "recipient"; 67 68 Method m_method = null; 69 70 public void configure(Element i_object) throws CreationException { 71 super.configure(i_object); 72 try { 73 if(getCondition().equals(JMS_HEADER)) 74 m_method = MantaMessage.class.getMethod("get"+getParam(),null); 75 } catch (NoSuchMethodException e) { 76 e.printStackTrace(); 77 throw new CreationException("JMS MESSAGE has no header called: " +getParam(), e); 78 } 79 } 80 81 public boolean metCondition(Object i_object) { 82 MantaBusMessage mantaBusMessage = null; 83 if(i_object instanceof DMFObject) 84 mantaBusMessage = ((DMFObject)i_object).getMantaBusMessage(); 85 else 86 mantaBusMessage = (MantaBusMessage)i_object; 87 88 String value = getValue(mantaBusMessage); 89 90 return getRequiresValue().equals(value); 91 } 92 93 protected String getValue(MantaBusMessage mantaBusMessage){ 94 MantaMessage mantaMessage = (MantaMessage)mantaBusMessage.getPayload(); 95 String condition = getCondition().intern(); 97 String value = null; 98 if(JMS_HEADER == condition){ 99 try { 101 value = String.valueOf(m_method.invoke(mantaMessage,null)); 102 } catch (IllegalAccessException e) { 103 } catch (InvocationTargetException e) { 104 } catch (Exception e) { 105 } 106 }else if(PROPERTY == condition){ 107 try { 108 value = mantaMessage.getStringProperty(getParam()); 109 } catch (JMSException e) { 110 e.printStackTrace(); 111 } 112 }else if(HEADER == condition){ 113 value = mantaBusMessage.getHeader(getParam()); 114 }else if(RECIPIENT == condition){ 115 RecipientAddress address = mantaBusMessage.getRecipient(); 116 value = address.getId(); 117 } 118 return value; 119 } 120 } | Popular Tags |