View Javadoc

1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  
20  package org.apache.james.jspf.core;
21  
22  import org.apache.james.jspf.core.exceptions.NoneException;
23  import org.xbill.DNS.Name;
24  import org.xbill.DNS.TextParseException;
25  
26  /**
27   * Represent a DNSRequest
28   */
29  public final class DNSRequest {
30  
31      /** The record types for the lookups */
32      public static final int A = 1;
33      public static final int AAAA = 2;
34      public static final int MX = 3;
35      public static final int PTR = 4;
36      public static final int TXT = 5;
37      public static final int SPF = 6;
38  
39      /**
40       * The hostname to be resolved
41       */
42      private final String hostname;
43      
44      /**
45       * The record type to look for
46       */
47      private final int recordType;
48  
49      public DNSRequest(final String hostname, final int recordType) throws NoneException {
50          if (recordType == MX || recordType == A || recordType == AAAA) {
51              try {
52                  Name.fromString(hostname);
53              } catch (TextParseException e) {
54                  throw new NoneException(e.getMessage());
55              }
56          }
57          this.hostname = hostname;
58          this.recordType = recordType;
59      }
60  
61      /**
62       * Return the hostname to process the request for
63       * 
64       * @return the hostname
65       */
66      public final String getHostname() {
67          return hostname;
68      }
69  
70      /**
71       * Return the RecordType which is use for this request
72       * 
73       * @return the RecordType
74       */
75      public final int getRecordType() {
76          return recordType;
77      }
78  
79      /**
80       * @see java.lang.Object#toString()
81       */
82      public String toString() {
83          return getHostname()+"#"+getRecordType();
84      }
85  }