1 package org.mr.core.util.patterns.flow; 2 3 import org.mr.core.util.exceptions.CreationException; 4 import org.w3c.dom.Element ; 5 import org.w3c.dom.NodeList ; 6 7 import java.util.HashMap ; 8 import java.util.Map ; 9 10 55 56 64 public abstract class AbstractCondition implements Condition{ 65 66 String m_condition; 67 String m_param; 68 String m_requiresValue; 69 String m_operator; 70 Message m_message; 71 72 public void configure(Element i_object) throws CreationException { 73 m_condition = i_object.getAttribute("name"); 74 m_operator = i_object.getAttribute("operator"); 75 NodeList list = i_object.getElementsByTagName("param"); 76 if(list.getLength() < 1) 77 throw new CreationException("Missing condition parameters"); 78 Element param = (Element )list.item(0); 79 m_param = param.getAttribute("name"); 80 m_requiresValue = param.getAttribute("value"); 81 82 NodeList elements = i_object.getElementsByTagName("message"); 83 if(elements != null && elements.getLength() > 0){ 84 m_message = new Message(); 85 m_message.configure((Element )elements.item(0)); 86 } 87 } 88 89 public String getCondition() { 90 return m_condition; 91 } 92 93 public String getParam() { 94 return m_param; 95 } 96 97 public String getRequiresValue() { 98 return m_requiresValue; 99 } 100 101 public String getOperator() { 102 return m_operator; 103 } 104 105 public Message getMessage() { 106 return m_message; 107 } 108 109 protected class Message{ 110 111 String m_type = null; 112 Map m_map = null; 113 114 public void configure(Element i_element){ 115 m_map = new HashMap (); 116 m_type = i_element.getAttribute("type"); 117 NodeList list = i_element.getElementsByTagName("param"); 118 for(int i = 0 ; i <list.getLength() ; i++){ 119 Element node = (Element )list.item(i); 120 m_map.put(node.getAttribute("name"), node.getAttribute("value")); 121 } 122 } 123 124 public String getType() { 125 return m_type; 126 } 127 128 public Map getMap() { 129 return m_map; 130 } 131 132 } 133 } 134 | Popular Tags |