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: ****************************************************************/package org.apache.james.jspf.core;
019:
020: import java.util.ArrayList;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: /**
025: * The Class represent the SPF1 Record and provide methods to get all directives
026: * and modifiers.
027: *
028: */
029: public class SPF1Record {
030:
031: private String record;
032: private List directives = new ArrayList();
033: private List modifiers = new ArrayList();
034:
035: public SPF1Record() {
036: this .record = null;
037: }
038:
039: public SPF1Record(String record) {
040: this .record = record;
041: }
042:
043: /**
044: * Return the directives as Collection
045: *
046: * @return directives Collection of all qualifier+mechanism which should be
047: * used
048: */
049: public List getDirectives() {
050: return directives;
051: }
052:
053: /**
054: * Return the modifiers as Collection
055: *
056: * @return modifiers Collection of all modifiers which should be used
057: */
058: public List getModifiers() {
059: return modifiers;
060: }
061:
062: /**
063: * @return the record in its string source format
064: */
065: public String getRecord() {
066: return record;
067: }
068:
069: /**
070: * Return a single iterator over Directives and Modifiers
071: *
072: * @return a chained iterator of the terms
073: */
074: public Iterator iterator() {
075: return new Iterator() {
076: boolean first = true;
077: Iterator current = getDirectives().iterator();
078:
079: /**
080: * @see java.util.Iterator#hasNext()
081: */
082: public boolean hasNext() {
083: if (current.hasNext()) {
084: return true;
085: } else if (first) {
086: current = getModifiers().iterator();
087: first = false;
088: return current.hasNext();
089: } else
090: return false;
091: }
092:
093: /**
094: * @see java.util.Iterator#next()
095: */
096: public Object next() {
097: return current.next();
098: }
099:
100: /**
101: * @see java.util.Iterator#remove()
102: */
103: public void remove() {
104: throw new UnsupportedOperationException(
105: "Readonly iterator");
106: }
107:
108: };
109: }
110:
111: }
|