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 import org.apache.james.jspf.core.exceptions.NoneException; 023 import org.xbill.DNS.Name; 024 import org.xbill.DNS.TextParseException; 025 026 /** 027 * Represent a DNSRequest 028 */ 029 public final class DNSRequest { 030 031 /** The record types for the lookups */ 032 public static final int A = 1; 033 public static final int AAAA = 2; 034 public static final int MX = 3; 035 public static final int PTR = 4; 036 public static final int TXT = 5; 037 public static final int SPF = 6; 038 039 /** 040 * The hostname to be resolved 041 */ 042 private final String hostname; 043 044 /** 045 * The record type to look for 046 */ 047 private final int recordType; 048 049 public DNSRequest(final String hostname, final int recordType) throws NoneException { 050 if (recordType == MX || recordType == A || recordType == AAAA) { 051 try { 052 Name.fromString(hostname); 053 } catch (TextParseException e) { 054 throw new NoneException(e.getMessage()); 055 } 056 } 057 this.hostname = hostname; 058 this.recordType = recordType; 059 } 060 061 /** 062 * Return the hostname to process the request for 063 * 064 * @return the hostname 065 */ 066 public final String getHostname() { 067 return hostname; 068 } 069 070 /** 071 * Return the RecordType which is use for this request 072 * 073 * @return the RecordType 074 */ 075 public final int getRecordType() { 076 return recordType; 077 } 078 079 /** 080 * @see java.lang.Object#toString() 081 */ 082 public String toString() { 083 return getHostname()+"#"+getRecordType(); 084 } 085 }