1 /**************************************************************** 2 * Licensed to the Apache Software Foundation (ASF) under one * 3 * or more contributor license agreements. See the NOTICE file * 4 * distributed with this work for additional information * 5 * regarding copyright ownership. The ASF licenses this file * 6 * to you under the Apache License, Version 2.0 (the * 7 * "License"); you may not use this file except in compliance * 8 * with the License. You may obtain a copy of the License at * 9 * * 10 * http://www.apache.org/licenses/LICENSE-2.0 * 11 * * 12 * Unless required by applicable law or agreed to in writing, * 13 * software distributed under the License is distributed on an * 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15 * KIND, either express or implied. See the License for the * 16 * specific language governing permissions and limitations * 17 * under the License. * 18 ****************************************************************/ 19 20 package org.apache.jsieve; 21 22 /** 23 * Thread singleton class ConditionManager manages Conditional Commands during a 24 * Sieve evaluation. 25 */ 26 public class ConditionManager { 27 28 /** 29 * Is an Else Condition allowed 30 */ 31 private boolean fieldElseAllowed; 32 33 /** 34 * The result of the last Test 35 */ 36 private boolean fieldTestResult; 37 38 /** 39 * Constructor for ConditionManager. 40 */ 41 public ConditionManager() { 42 super(); 43 initialize(); 44 } 45 46 /** 47 * Initialize the receiver. 48 */ 49 protected void initialize() { 50 setElseAllowed(false); 51 setTestResult(true); 52 } 53 54 /** 55 * Method setIfTestResult enables a following Else Command and records the 56 * test result. 57 * 58 * @param result 59 */ 60 public void setIfTestResult(boolean result) { 61 setElseAllowed(true); 62 setTestResult(result); 63 } 64 65 /** 66 * Method setElsifTestResult enables a following Else Command and records 67 * the test result. 68 * 69 * @param result 70 */ 71 public void setElsifTestResult(boolean result) { 72 setElseAllowed(true); 73 setTestResult(result); 74 } 75 76 /** 77 * Method setElseTestResult disables a following Else Command and records 78 * the test result. 79 * 80 * @param result 81 */ 82 public void setElseTestResult(boolean result) { 83 setElseAllowed(false); 84 setTestResult(result); 85 } 86 87 /** 88 * Method isIfAllowed answers a boolean indicating if an If Command is 89 * allowed. 90 * 91 * @return boolean 92 */ 93 public boolean isIfAllowed() { 94 return true; 95 } 96 97 /** 98 * Method isElsifAllowed answers a boolean indicating if an Elsif Command is 99 * allowed. 100 * 101 * @return boolean 102 */ 103 public boolean isElsifAllowed() { 104 return isElseAllowed(); 105 } 106 107 /** 108 * Method isElseAllowed answers a boolean indicating if an Else Command is 109 * allowed. 110 * 111 * @return boolean 112 */ 113 public boolean isElseAllowed() { 114 return fieldElseAllowed; 115 } 116 117 /** 118 * Method isIfRunnable answers a boolean indicating if an If Command is 119 * runnable based upon the current evaluation state. 120 * 121 * @return boolean 122 */ 123 public boolean isIfRunnable() { 124 return true; 125 } 126 127 /** 128 * Method isElsifRunnable answers a boolean indicating if an Elsif Command 129 * is runnable based upon the current evaluation state. 130 * 131 * @return boolean 132 */ 133 public boolean isElsifRunnable() { 134 return isElseRunnable(); 135 } 136 137 /** 138 * Method isElseRunnable answers a boolean indicating if an Else Command is 139 * runnable based upon the current evaluation state. 140 * 141 * @return boolean 142 */ 143 public boolean isElseRunnable() { 144 return !isTestResult(); 145 } 146 147 /** 148 * Returns the testResult. 149 * 150 * @return boolean 151 */ 152 protected boolean isTestResult() { 153 return fieldTestResult; 154 } 155 156 /** 157 * Sets the elseAllowed. 158 * 159 * @param elseAllowed 160 * The elseAllowed to set 161 */ 162 protected void setElseAllowed(boolean elseAllowed) { 163 fieldElseAllowed = elseAllowed; 164 } 165 166 /** 167 * Sets the testResult. 168 * 169 * @param testResult 170 * The testResult to set 171 */ 172 protected void setTestResult(boolean testResult) { 173 fieldTestResult = testResult; 174 } 175 176 }