01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
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: ****************************************************************/package org.apache.james.jspf.core;
19:
20: import org.apache.james.jspf.core.exceptions.NoneException;
21: import org.xbill.DNS.Name;
22: import org.xbill.DNS.TextParseException;
23:
24: /**
25: * Represent a DNSRequest
26: */
27: public final class DNSRequest {
28:
29: /** The record types for the lookups */
30: public static final int A = 1;
31: public static final int AAAA = 2;
32: public static final int MX = 3;
33: public static final int PTR = 4;
34: public static final int TXT = 5;
35: public static final int SPF = 6;
36:
37: /**
38: * The hostname to be resolved
39: */
40: private final String hostname;
41:
42: /**
43: * The record type to look for
44: */
45: private final int recordType;
46:
47: public DNSRequest(final String hostname, final int recordType)
48: throws NoneException {
49: if (recordType == MX || recordType == A || recordType == AAAA) {
50: try {
51: Name.fromString(hostname);
52: } catch (TextParseException e) {
53: throw new NoneException(e.getMessage());
54: }
55: }
56: this .hostname = hostname;
57: this .recordType = recordType;
58: }
59:
60: /**
61: * Return the hostname to process the request for
62: *
63: * @return the hostname
64: */
65: public final String getHostname() {
66: return hostname;
67: }
68:
69: /**
70: * Return the RecordType which is use for this request
71: *
72: * @return the RecordType
73: */
74: public final int getRecordType() {
75: return recordType;
76: }
77:
78: /**
79: * @see java.lang.Object#toString()
80: */
81: public String toString() {
82: return getHostname() + "#" + getRecordType();
83: }
84: }
|