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 021 package org.apache.directory.server.dns.messages; 022 023 024 import org.apache.commons.lang.builder.EqualsBuilder; 025 import org.apache.commons.lang.builder.HashCodeBuilder; 026 import org.apache.commons.lang.builder.ToStringBuilder; 027 028 029 /** 030 * The question section is used to carry the "question" in most queries, 031 * i.e., the parameters that define what is being asked. The section 032 * contains QDCOUNT (usually 1) entries, each of the following format: 033 * 034 * 1 1 1 1 1 1 035 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 036 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 037 * | | 038 * / QNAME / 039 * / / 040 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 041 * | QTYPE | 042 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 043 * | QCLASS | 044 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 045 * 046 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 047 * @version $Rev: 664295 $, $Date: 2008-06-07 09:48:16 +0200 (Sat, 07 Jun 2008) $ 048 */ 049 public class QuestionRecord 050 { 051 /** 052 * A domain name represented as a sequence of labels, where 053 * each label consists of a length octet followed by that 054 * number of octets. The domain name terminates with the 055 * zero length octet for the null label of the root. Note 056 * that this field may be an odd number of octets; no 057 * padding is used. 058 */ 059 private String domainName; 060 061 /** 062 * A two octet code which specifies the type. 063 */ 064 private RecordType recordType; 065 066 /** 067 * A two octet code that specifies the class. 068 * For example, the CLASS field is IN for the Internet. 069 */ 070 private RecordClass recordClass; 071 072 073 /** 074 * Creates a new instance of QuestionRecord. 075 * 076 * @param domainName 077 * @param recordType 078 * @param recordClass 079 */ 080 public QuestionRecord( String domainName, RecordType recordType, RecordClass recordClass ) 081 { 082 this.domainName = domainName; 083 this.recordType = recordType; 084 this.recordClass = recordClass; 085 } 086 087 088 /** 089 * The domain name of this query. 090 * For example, www.example.com. 091 * 092 * @return The domain name. 093 */ 094 public String getDomainName() 095 { 096 return domainName; 097 } 098 099 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 }