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  package org.apache.jsieve;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  /**
26   * Class StringListArgument is a parsed representation of the RFC3028 BNF...
27   * </p>
28   * 
29   * <code>string-list = "[" string *("," string) "]" / string</code>
30   */
31  public class StringListArgument implements Argument {
32      private List<String> fieldList;
33  
34      /**
35       * Constructor for StringListArgument.
36       */
37      private StringListArgument() {
38          super();
39      }
40  
41      /**
42       * Constructor for StringListArgument.
43       */
44      public StringListArgument(List<String> stringList) {
45          this();
46          setList(stringList);
47      }
48  
49      /**
50       * Returns the list, lazy initialised if required.
51       * 
52       * @return List
53       */
54      public List<String> getList() {
55          List<String> list = null;
56          if (null == (list = getListBasic())) {
57              updateList();
58              return getList();
59          }
60          return list;
61      }
62  
63      /**
64       * Returns the list.
65       * 
66       * @return List
67       */
68      private List<String> getListBasic() {
69          return fieldList;
70      }
71  
72      /**
73       * Returns a new list.
74       * 
75       * @return List
76       */
77      protected List<String> computeList() {
78          return new ArrayList<String>();
79      }
80  
81      /**
82       * Sets the list.
83       * 
84       * @param list
85       *            The list to set
86       */
87      protected void setList(List<String> list) {
88          fieldList = list;
89      }
90  
91      /**
92       * Updates the list.
93       */
94      protected void updateList() {
95          setList(computeList());
96      }
97  
98      /**
99       * @see org.apache.jsieve.Argument#getValue()
100      */
101     public Object getValue() {
102         return getList();
103     }
104 
105     /**
106      * @see java.lang.Object#toString()
107      */
108     public String toString() {
109         return (getValue() == null) ? "null" : getValue().toString();
110     }
111 
112 }