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 import org.apache.commons.logging.Log; 23 import org.apache.jsieve.exception.SieveException; 24 import org.apache.jsieve.mail.MailAdapter; 25 import org.apache.jsieve.tests.ExecutableTest; 26 27 /** 28 * <p> 29 * A parsed representation of an RFC3028 test argument... 30 * </p> 31 * 32 * <code>test = identifier arguments</code> 33 */ 34 public class Test implements Executable { 35 36 /** The name of this Test */ 37 private String fieldName; 38 39 /** The arguments for this Test */ 40 private Arguments fieldArguments; 41 42 /** 43 * @see org.apache.jsieve.Executable#execute(MailAdapter, SieveContext) 44 */ 45 public Object execute(MailAdapter mail, SieveContext context) 46 throws SieveException { 47 Log log = context.getLog(); 48 if (log.isDebugEnabled()) { 49 log.debug(toString()); 50 } 51 final String name = getName(); 52 final ExecutableTest test = context.getTest(name); 53 final boolean result = test.execute(mail, getArguments(), context); 54 return new Boolean(result); 55 } 56 57 /** 58 * Constructor for Test. 59 */ 60 private Test() { 61 super(); 62 } 63 64 /** 65 * Constructor for Test. 66 * 67 * @param name 68 * @param arguments 69 */ 70 public Test(String name, Arguments arguments) { 71 this(); 72 setName(name); 73 setArguments(arguments); 74 } 75 76 /** 77 * Returns the arguments. 78 * 79 * @return Arguments 80 */ 81 public Arguments getArguments() { 82 return fieldArguments; 83 } 84 85 /** 86 * Returns the name. 87 * 88 * @return String 89 */ 90 public String getName() { 91 return fieldName; 92 } 93 94 /** 95 * Sets the arguments. 96 * 97 * @param arguments 98 * The arguments to set 99 */ 100 protected void setArguments(Arguments arguments) { 101 fieldArguments = arguments; 102 } 103 104 /** 105 * Sets the name. 106 * 107 * @param name 108 * The name to set 109 */ 110 protected void setName(String name) { 111 fieldName = name; 112 } 113 114 /** 115 * @see java.lang.Object#toString() 116 */ 117 public String toString() { 118 return "Test name: " + getName() + " " 119 + (getArguments() == null ? "null" : getArguments().toString()); 120 } 121 122 }