org.apache.jsieve.Test Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apache-jsieve Show documentation
Show all versions of apache-jsieve Show documentation
Apache jSieve is a server side mail filtering system
implementing RFC3028. Apache jSieve is developed by the
JAMES project.
/****************************************************************
* Licensed to the Apache Software Foundation (ASF) under one *
* or more contributor license agreements. See the NOTICE file *
* distributed with this work for additional information *
* regarding copyright ownership. The ASF licenses this file *
* to you under the Apache License, Version 2.0 (the *
* "License"); you may not use this file except in compliance *
* with the License. You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, *
* software distributed under the License is distributed on an *
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
* KIND, either express or implied. See the License for the *
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
package org.apache.jsieve;
import org.apache.commons.logging.Log;
import org.apache.jsieve.exception.SieveException;
import org.apache.jsieve.mail.MailAdapter;
import org.apache.jsieve.tests.ExecutableTest;
/**
*
* A parsed representation of an RFC3028 test argument...
*
*
* test = identifier arguments
*/
public class Test implements Executable {
/** The name of this Test */
private String fieldName;
/** The arguments for this Test */
private Arguments fieldArguments;
/**
* @see org.apache.jsieve.Executable#execute(MailAdapter, SieveContext)
*/
public Object execute(MailAdapter mail, SieveContext context)
throws SieveException {
Log log = context.getLog();
if (log.isDebugEnabled()) {
log.debug(toString());
}
final String name = getName();
final ExecutableTest test = context.getTest(name);
final boolean result = test.execute(mail, getArguments(), context);
return new Boolean(result);
}
/**
* Constructor for Test.
*/
private Test() {
super();
}
/**
* Constructor for Test.
*
* @param name
* @param arguments
*/
public Test(String name, Arguments arguments) {
this();
setName(name);
setArguments(arguments);
}
/**
* Returns the arguments.
*
* @return Arguments
*/
public Arguments getArguments() {
return fieldArguments;
}
/**
* Returns the name.
*
* @return String
*/
public String getName() {
return fieldName;
}
/**
* Sets the arguments.
*
* @param arguments
* The arguments to set
*/
protected void setArguments(Arguments arguments) {
fieldArguments = arguments;
}
/**
* Sets the name.
*
* @param name
* The name to set
*/
protected void setName(String name) {
fieldName = name;
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
return "Test name: " + getName() + " "
+ (getArguments() == null ? "null" : getArguments().toString());
}
}