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    package org.apache.james.jspf.core;
021    
022    
023    import org.apache.james.jspf.core.exceptions.TimeoutException;
024    
025    import java.util.List;
026    
027    /**
028     * Represent a DNSResponse
029     *
030     */
031    public class DNSResponse {
032        
033        private List<String> response;
034        
035        private TimeoutException exception;
036        
037        public DNSResponse(TimeoutException exception) {
038            this.exception = exception;
039            this.response = null;
040        }
041        
042        public DNSResponse(List<String> response) {
043            this.exception = null;
044            this.response = response;
045        }
046        
047        /**
048         * Returns the DNS response
049         * 
050         * @return the dns repsonse
051         * @throws TimeoutException get thrown if an timeout was returned while tried to 
052         *         process a dns request
053         */
054        public List<String> getResponse() throws TimeoutException {
055            if (exception != null) {
056                throw exception;
057            } else {
058                return response;
059            }
060        }
061    
062        /**
063         * @see java.lang.Object#toString()
064         */
065        public String toString() {
066            if (exception != null) {
067                return "EXCEPTION!";
068            } else if (response != null) {
069                return response.toString();
070            } else {
071                return "NULL?";
072            }
073        }
074    }