View Javadoc

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