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.james.jspf.core;
22  
23  import java.util.ArrayList;
24  import java.util.Iterator;
25  import java.util.List;
26  
27  /**
28   * The Class represent the SPF1 Record and provide methods to get all directives
29   * and modifiers.
30   * 
31   */
32  public class SPF1Record {
33      
34      private String record;
35      private List directives = new ArrayList();
36      private List modifiers = new ArrayList();
37  
38      public SPF1Record() {
39          this.record = null;
40      }
41      
42      public SPF1Record(String record) {
43          this.record = record;
44      }
45  
46      /**
47       * Return the directives as Collection
48       * 
49       * @return directives Collection of all qualifier+mechanism which should be
50       *         used
51       */
52      public List getDirectives() {
53          return directives;
54      }
55  
56      /**
57       * Return the modifiers as Collection
58       * 
59       * @return modifiers Collection of all modifiers which should be used
60       */
61      public List getModifiers() {
62          return modifiers;
63      }
64  
65      /**
66       * @return the record in its string source format
67       */
68      public String getRecord() {
69          return record;
70      }
71      
72      /**
73       * Return a single iterator over Directives and Modifiers
74       * 
75       * @return a chained iterator of the terms
76       */
77      public Iterator iterator() {
78          return new Iterator() {
79              boolean first = true;
80              Iterator current = getDirectives().iterator();
81  
82              /**
83               * @see java.util.Iterator#hasNext()
84               */
85              public boolean hasNext() {
86                  if (current.hasNext()) { 
87                      return true;
88                  } else if (first) {
89                      current = getModifiers().iterator();
90                      first = false;
91                      return current.hasNext();
92                  } else return false;
93              }
94  
95              /**
96               * @see java.util.Iterator#next()
97               */
98              public Object next() {
99                  return current.next();
100             }
101 
102             /**
103              * @see java.util.Iterator#remove()
104              */
105             public void remove() {
106                 throw new UnsupportedOperationException("Readonly iterator");
107             }
108             
109         };
110     }
111 
112 }