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
21 package org.apache.directory.server.dns.messages;
22
23
24 import org.apache.commons.lang.builder.EqualsBuilder;
25 import org.apache.commons.lang.builder.HashCodeBuilder;
26 import org.apache.commons.lang.builder.ToStringBuilder;
27
28
29 /**
30 * The question section is used to carry the "question" in most queries,
31 * i.e., the parameters that define what is being asked. The section
32 * contains QDCOUNT (usually 1) entries, each of the following format:
33 *
34 * 1 1 1 1 1 1
35 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
36 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
37 * | |
38 * / QNAME /
39 * / /
40 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
41 * | QTYPE |
42 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
43 * | QCLASS |
44 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
45 *
46 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
47 * @version $Rev: 664295 $, $Date: 2008-06-07 09:48:16 +0200 (Sa, 07 Jun 2008) $
48 */
49 public class QuestionRecord
50 {
51 /**
52 * A domain name represented as a sequence of labels, where
53 * each label consists of a length octet followed by that
54 * number of octets. The domain name terminates with the
55 * zero length octet for the null label of the root. Note
56 * that this field may be an odd number of octets; no
57 * padding is used.
58 */
59 private String domainName;
60
61 /**
62 * A two octet code which specifies the type.
63 */
64 private RecordType recordType;
65
66 /**
67 * A two octet code that specifies the class.
68 * For example, the CLASS field is IN for the Internet.
69 */
70 private RecordClass recordClass;
71
72
73 /**
74 * Creates a new instance of QuestionRecord.
75 *
76 * @param domainName
77 * @param recordType
78 * @param recordClass
79 */
80 public QuestionRecord( String domainName, RecordType recordType, RecordClass recordClass )
81 {
82 this.domainName = domainName;
83 this.recordType = recordType;
84 this.recordClass = recordClass;
85 }
86
87
88 /**
89 * The domain name of this query.
90 * For example, www.example.com.
91 *
92 * @return The domain name.
93 */
94 public String getDomainName()
95 {
96 return domainName;
97 }
98
99
100 /**
101 * The type of the query.
102 * For example, the type is A for address records.
103 *
104 * @return The {@link RecordType}.
105 */
106 public RecordType getRecordType()
107 {
108 return recordType;
109 }
110
111
112 /**
113 * The class for this query.
114 * For example, the class is IN for the Internet.
115 *
116 * @return The {@link RecordClass}.
117 */
118 public RecordClass getRecordClass()
119 {
120 return recordClass;
121 }
122
123
124 /**
125 * @see java.lang.Object#equals(Object)
126 */
127 public boolean equals( Object object )
128 {
129 if ( object == this )
130 {
131 return true;
132 }
133 if ( !( object instanceof QuestionRecord ) )
134 {
135 return false;
136 }
137 QuestionRecord rhs = ( QuestionRecord ) object;
138 return new EqualsBuilder().append( this.domainName, rhs.domainName ).append( this.recordClass, rhs.recordClass )
139 .append( this.recordType, rhs.recordType ).isEquals();
140 }
141
142
143 /**
144 * @see java.lang.Object#hashCode()
145 * @return the instance's hash code
146 */
147 public int hashCode()
148 {
149 return new HashCodeBuilder( 1493545107, 315848479 ).append( this.domainName ).append( this.recordClass )
150 .append( this.recordType ).toHashCode();
151 }
152
153
154 /**
155 * @see java.lang.Object#toString()
156 */
157 public String toString()
158 {
159 return new ToStringBuilder( this ).appendSuper( super.toString() ).append( "domainName", this.domainName )
160 .append( "recordClass", this.recordClass ).append( "recordType", this.recordType ).toString();
161 }
162
163 }