1 package org.mr.core.util.patterns.flow; 2 3 import org.mr.core.util.exceptions.CreationException; 4 import org.w3c.dom.Element ; 5 6 import java.util.ArrayList ; 7 import java.util.List ; 8 9 54 55 63 64 public class Conditional implements Condition{ 65 66 public final static String AND_OPERATOR = "AND"; 67 public final static String OR_OPERATOR = "OR"; 68 69 char m_operator; 70 List m_conditions = null; 71 72 public void configure(Element i_object) throws CreationException { 73 String operator = i_object.getAttribute("operator"); 74 if(AND_OPERATOR.equals(operator) || operator == null || operator.length() == 0) 75 m_operator = '+'; 76 else if(OR_OPERATOR.equals(operator)) 77 m_operator = '|'; 78 else 79 throw new CreationException("Unsupported operator="+operator); 80 m_conditions = new ArrayList (); 82 } 83 84 public void addCondition(Condition i_condition){ 85 m_conditions.add(i_condition); 86 } 87 88 public boolean metCondition(Object i_object) { 89 for(int i = 0 ; i < m_conditions.size() ; i++){ 90 Condition condition = (Condition)m_conditions.get(i); 91 boolean metCondition = false; 92 try { 93 metCondition = condition.metCondition(i_object); 94 } catch (Exception e) { 95 metCondition = false; 96 } 97 switch(m_operator){ 98 case '+': 99 if(!metCondition) 100 return false; 101 break; 102 case '|': 103 if(metCondition) 104 return true; 105 } 106 } 107 if('+' == m_operator) 108 return true; 109 return false; 110 } 111 } | Popular Tags |