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.MailAdapter;
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, SieveContext)
75 */
76 public Object execute(MailAdapter mail, SieveContext context)
77 throws SieveException {
78 boolean result = true;
79
80 Iterator testsIter = getTests().iterator();
81 while (result && testsIter.hasNext()) {
82 result = ((Boolean) ((Test) testsIter.next())
83 .execute(mail, context)).booleanValue();
84 }
85 return new Boolean(result);
86 }
87
88 /**
89 * Returns the children.
90 *
91 * @return List
92 */
93 public List getTests() {
94 return fieldTests;
95 }
96
97 /**
98 * Sets the children.
99 *
100 * @param children
101 * The children to set
102 */
103 protected void setTests(List children) {
104 fieldTests = children;
105 }
106
107 public String toString() {
108 return "TEST LIST: " + fieldTests;
109 }
110
111 }