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.terms;
022    
023    import org.apache.james.jspf.core.DNSLookupContinuation;
024    import org.apache.james.jspf.core.LogEnabled;
025    import org.apache.james.jspf.core.Logger;
026    import org.apache.james.jspf.core.SPFSession;
027    import org.apache.james.jspf.core.exceptions.NeutralException;
028    import org.apache.james.jspf.core.exceptions.NoneException;
029    import org.apache.james.jspf.core.exceptions.PermErrorException;
030    import org.apache.james.jspf.core.exceptions.TempErrorException;
031    
032    /**
033     * This abstract class represent a gerneric modifier
034     * 
035     */
036    public abstract class GenericModifier implements Modifier, ConfigurationEnabled, LogEnabled {
037    
038        private String host;
039    
040        protected Logger log;
041    
042        /**
043         * @see org.apache.james.jspf.core.SPFChecker#checkSPF(org.apache.james.jspf.core.SPFSession)
044         */
045        public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
046                TempErrorException, NeutralException, NoneException {
047            log.debug("Processing modifier: " + this);
048            DNSLookupContinuation res = checkSPFLogged(spfData);
049            log.debug("Processed modifier: " + this + " resulted in "
050                    + res == null ? spfData.getCurrentResult() : " dns continuation...");
051            return res;
052        }
053        
054        protected abstract DNSLookupContinuation checkSPFLogged(SPFSession spfData) throws PermErrorException,
055            TempErrorException, NeutralException, NoneException;
056    
057    
058        /**
059         * @see org.apache.james.jspf.terms.Modifier#enforceSingleInstance()
060         */
061        public boolean enforceSingleInstance() {
062            return true;
063        }
064    
065        /**
066         * @see org.apache.james.jspf.terms.ConfigurationEnabled#config(Configuration)
067         */
068        public synchronized void config(Configuration params) throws PermErrorException {
069            if (params.groupCount() > 0) {
070                this.host = params.group(1);
071            }
072        }
073    
074        /**
075         * @return Returns the host.
076         */
077        protected synchronized String getHost() {
078            return host;
079        }
080        
081    
082        /**
083         * @see org.apache.james.jspf.core.LogEnabled#enableLogging(org.apache.james.jspf.core.Logger)
084         */
085        public void enableLogging(Logger logger) {
086            this.log = logger;
087        }
088    
089    
090    }