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 java.util.Map; 25 26 27 /** 28 * The answer, authority, and additional sections all share the same 29 * format: a variable number of resource records, where the number of 30 * records is specified in the corresponding count field in the header. 31 * Each resource record has the following format: 32 * 1 1 1 1 1 1 33 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 34 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 35 * | | 36 * / / 37 * / NAME / 38 * | | 39 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 40 * | TYPE | 41 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 42 * | CLASS | 43 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 44 * | TTL | 45 * | | 46 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 47 * | RDLENGTH | 48 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--| 49 * / RDATA / 50 * / / 51 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 52 * 53 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 54 * @version $Rev: 664295 $, $Date: 2008-06-07 09:48:16 +0200 (Sa, 07 Jun 2008) $ 55 */ 56 public class ResourceRecordImpl implements ResourceRecord 57 { 58 /** 59 * An owner name, i.e., the name of the node to which this 60 * resource record pertains. 61 */ 62 private String domainName; 63 64 /** 65 * Two octets containing one of the resource record TYPE codes. 66 */ 67 private RecordType recordType; 68 69 /** 70 * Two octets containing one of the resource record CLASS codes. 71 * For example, the CLASS field is IN for the Internet. 72 */ 73 private RecordClass recordClass; 74 75 /** 76 * A 32 bit signed integer that specifies the time interval 77 * that the resource record may be cached before the source 78 * of the information should again be consulted. Zero 79 * values are interpreted to mean that the resource record can only be 80 * used for the transaction in progress, and should not be 81 * cached. For example, SOA records are always distributed 82 * with a zero TTL to prohibit caching. Zero values can 83 * also be used for extremely volatile data. 84 */ 85 private int timeToLive; 86 87 /** 88 * A variable length string of octets that describes the 89 * resource. The format of this information varies 90 * according to the TYPE and CLASS of the resource record. 91 */ 92 private Map<String, Object> attributes; 93 94 95 /** 96 * Creates a new instance of ResourceRecordImpl. 97 * 98 * @param domainName 99 * @param recordType 100 * @param recordClass 101 * @param timeToLive 102 * @param attributes 103 */ 104 public ResourceRecordImpl( String domainName, RecordType recordType, RecordClass recordClass, int timeToLive, 105 Map<String, Object> attributes ) 106 { 107 this.domainName = domainName; 108 this.recordType = recordType; 109 this.recordClass = recordClass; 110 this.timeToLive = timeToLive; 111 this.attributes = attributes; 112 } 113 114 115 /** 116 * @return Returns the domainName. 117 */ 118 public String getDomainName() 119 { 120 return domainName; 121 } 122 123 124 /** 125 * @return Returns the recordType. 126 */ 127 public RecordType getRecordType() 128 { 129 return recordType; 130 } 131 132 133 /** 134 * @return Returns the recordClass. 135 */ 136 public RecordClass getRecordClass() 137 { 138 return recordClass; 139 } 140 141 142 /** 143 * @return Returns the timeToLive. 144 */ 145 public int getTimeToLive() 146 { 147 return timeToLive; 148 } 149 150 151 /** 152 * @return Returns the value for the id. 153 */ 154 public String get( String id ) 155 { 156 return ( String ) attributes.get( id.toLowerCase() ); 157 } 158 159 160 public boolean equals( Object o ) 161 { 162 if ( this == o ) 163 { 164 return true; 165 } 166 167 if ( !( o instanceof ResourceRecord ) ) 168 { 169 return false; 170 } 171 172 ResourceRecordImpl that = ( ResourceRecordImpl ) o; 173 174 return ( this.domainName.equalsIgnoreCase( that.domainName ) ) && ( this.recordType == that.recordType ) 175 && ( this.recordClass == that.recordClass ); 176 } 177 178 179 /** 180 * Compute the instance hash code 181 * @return the instance's hash code 182 */ 183 public int hashCode() 184 { 185 return domainName.hashCode() + recordType.hashCode() + recordClass.hashCode(); 186 } 187 188 189 public String toString() 190 { 191 return getClass().getName() + " [ " + domainName + " ( " + recordType + " " + recordClass + " " + timeToLive 192 + " " + attributes + " ) ]"; 193 } 194 }