001 /****************************************************************
002 * Licensed to the Apache Software Foundation (ASF) under one *
003 * or more contributor license agreements. See the NOTICE file *
004 * distributed with this work for additional information *
005 * regarding copyright ownership. The ASF licenses this file *
006 * to you under the Apache License, Version 2.0 (the *
007 * "License"); you may not use this file except in compliance *
008 * with the License. You may obtain a copy of the License at *
009 * *
010 * http://www.apache.org/licenses/LICENSE-2.0 *
011 * *
012 * Unless required by applicable law or agreed to in writing, *
013 * software distributed under the License is distributed on an *
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015 * KIND, either express or implied. See the License for the *
016 * specific language governing permissions and limitations *
017 * under the License. *
018 ****************************************************************/
019
020
021 package org.apache.james.jspf.core;
022
023 import java.util.ArrayList;
024 import java.util.Iterator;
025 import java.util.List;
026
027 import org.apache.james.jspf.terms.Directive;
028 import org.apache.james.jspf.terms.Modifier;
029
030 /**
031 * The Class represent the SPF1 Record and provide methods to get all directives
032 * and modifiers.
033 *
034 */
035 public class SPF1Record {
036
037 private String record;
038 private List<Directive> directives = new ArrayList<Directive>();
039 private List<Modifier> modifiers = new ArrayList<Modifier>();
040
041 public SPF1Record() {
042 this.record = null;
043 }
044
045 public SPF1Record(String record) {
046 this.record = record;
047 }
048
049 /**
050 * Return the directives as Collection
051 *
052 * @return directives Collection of all qualifier+mechanism which should be
053 * used
054 */
055 public List<Directive> getDirectives() {
056 return directives;
057 }
058
059 /**
060 * Return the modifiers as Collection
061 *
062 * @return modifiers Collection of all modifiers which should be used
063 */
064 public List<Modifier> getModifiers() {
065 return modifiers;
066 }
067
068 /**
069 * @return the record in its string source format
070 */
071 public String getRecord() {
072 return record;
073 }
074
075 /**
076 * Return a single iterator over Directives and Modifiers
077 *
078 * @return a chained iterator of the terms
079 */
080 @SuppressWarnings("unchecked")
081 public Iterator<SPFChecker> iterator() {
082 return new Iterator() {
083 boolean first = true;
084 Iterator current = getDirectives().iterator();
085
086 /**
087 * @see java.util.Iterator#hasNext()
088 */
089 public boolean hasNext() {
090 if (current.hasNext()) {
091 return true;
092 } else if (first) {
093 current = getModifiers().iterator();
094 first = false;
095 return current.hasNext();
096 } else return false;
097 }
098
099 /**
100 * @see java.util.Iterator#next()
101 */
102 public Object next() {
103 return current.next();
104 }
105
106 /**
107 * @see java.util.Iterator#remove()
108 */
109 public void remove() {
110 throw new UnsupportedOperationException("Readonly iterator");
111 }
112
113 };
114 }
115
116 }