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 java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.apache.jsieve.exception.SieveException;
27 import org.apache.jsieve.mail.*;
28
29 /***
30 * <p>
31 * A parsed representation of an RFC3028 testlist argument...
32 * </p>
33 *
34 * <code>test-list = "(" test *("," test) ")"</code>
35 */
36 public class TestList implements Executable {
37 /***
38 * List of Tests
39 */
40 private List fieldTests;
41
42 /***
43 * Constructor for TestList.
44 */
45 private TestList() {
46 super();
47 }
48
49 /***
50 * Constructor for TestList.
51 *
52 * @param children -
53 * A List of Tests
54 */
55 public TestList(List children) {
56 this();
57 setTests(children);
58 }
59
60 /***
61 * Constructor for TestList.
62 *
63 * @param child -
64 * A Test
65 */
66 public TestList(Test child) {
67 this();
68 List children = new ArrayList();
69 children.add(child);
70 setTests(children);
71 }
72
73 /***
74 * @see org.apache.jsieve.Executable#execute(MailAdapter)
75 */
76 public Object execute(MailAdapter mail) throws SieveException {
77 boolean result = true;
78
79 Iterator testsIter = getTests().iterator();
80 while (result && testsIter.hasNext()) {
81 result = ((Boolean) ((Test) testsIter.next()).execute(mail))
82 .booleanValue();
83 }
84 return new Boolean(result);
85 }
86
87 /***
88 * Returns the children.
89 *
90 * @return List
91 */
92 public List getTests() {
93 return fieldTests;
94 }
95
96 /***
97 * Sets the children.
98 *
99 * @param children
100 * The children to set
101 */
102 protected void setTests(List children) {
103 fieldTests = children;
104 }
105
106 public String toString() {
107 return "TEST LIST: " + fieldTests;
108 }
109
110 }