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.List; 24 25 /** 26 * <p> 27 * A parsed representation of the RFC3028 BNF... 28 * </p> 29 * 30 * <code>arguments = *argument [test / test-list]</code> 31 * 32 * <p> 33 * Note that a test is represented as a test-list with a single element. 34 * </p> 35 * 36 */ 37 public class Arguments { 38 /** 39 * A List of the parsed Arguments 40 */ 41 private List fieldArgumentList; 42 43 /** 44 * The parsed tests 45 */ 46 private TestList fieldTestList; 47 48 /** 49 * Constructor for Arguments. 50 */ 51 private Arguments() { 52 super(); 53 } 54 55 /** 56 * Constructor for Arguments. 57 * 58 * @param arguments 59 * @param testList 60 */ 61 public Arguments(List arguments, TestList testList) { 62 this(); 63 setArgumentList(arguments); 64 setTestList(testList); 65 } 66 67 /** 68 * Returns the arguments. 69 * 70 * @return List 71 */ 72 public List getArgumentList() { 73 return fieldArgumentList; 74 } 75 76 /** 77 * Returns the testList, lazily initialised if required. 78 * 79 * @return TestList 80 */ 81 public TestList getTestList() { 82 TestList testList = null; 83 if (null == (testList = getTestListBasic())) { 84 updateTestList(); 85 return getTestList(); 86 } 87 return testList; 88 } 89 90 /** 91 * Returns true if there is a TestList and it has Tests. Saves triggering 92 * lazy initialisation. 93 * 94 * @return boolean 95 */ 96 public boolean hasTests() { 97 TestList testList = getTestListBasic(); 98 return null != testList && testList.getTests().size() == 0; 99 } 100 101 /** 102 * Returns the testList. 103 * 104 * @return TestList 105 */ 106 private TestList getTestListBasic() { 107 return fieldTestList; 108 } 109 110 /** 111 * Computes the testList. 112 * 113 * @return TestList 114 */ 115 protected TestList computeTestList() { 116 return new TestList(new ArrayList()); 117 } 118 119 /** 120 * Sets the arguments. 121 * 122 * @param arguments 123 * The arguments to set 124 */ 125 protected void setArgumentList(List arguments) { 126 fieldArgumentList = arguments; 127 } 128 129 /** 130 * Sets the testList. 131 * 132 * @param testList 133 * The testList to set 134 */ 135 protected void setTestList(TestList testList) { 136 fieldTestList = testList; 137 } 138 139 /** 140 * Updates the TestList 141 */ 142 protected void updateTestList() { 143 setTestList(computeTestList()); 144 } 145 146 /** 147 * @see java.lang.Object#toString() 148 */ 149 public String toString() { 150 return "Arguments: " + getArgumentList().toString() + " Tests: " 151 + (hasTests() ? getTestList().toString() : "null"); 152 } 153 154 }