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 java.util.Map; 025 026 027 /** 028 * The answer, authority, and additional sections all share the same 029 * format: a variable number of resource records, where the number of 030 * records is specified in the corresponding count field in the header. 031 * Each resource record has the following format: 032 * 1 1 1 1 1 1 033 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 034 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 035 * | | 036 * / / 037 * / NAME / 038 * | | 039 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 040 * | TYPE | 041 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 042 * | CLASS | 043 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 044 * | TTL | 045 * | | 046 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 047 * | RDLENGTH | 048 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--| 049 * / RDATA / 050 * / / 051 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 052 * 053 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 054 * @version $Rev: 664295 $, $Date: 2008-06-07 09:48:16 +0200 (Sat, 07 Jun 2008) $ 055 */ 056 public class ResourceRecordImpl implements ResourceRecord 057 { 058 /** 059 * An owner name, i.e., the name of the node to which this 060 * resource record pertains. 061 */ 062 private String domainName; 063 064 /** 065 * Two octets containing one of the resource record TYPE codes. 066 */ 067 private RecordType recordType; 068 069 /** 070 * Two octets containing one of the resource record CLASS codes. 071 * For example, the CLASS field is IN for the Internet. 072 */ 073 private RecordClass recordClass; 074 075 /** 076 * A 32 bit signed integer that specifies the time interval 077 * that the resource record may be cached before the source 078 * of the information should again be consulted. Zero 079 * values are interpreted to mean that the resource record can only be 080 * used for the transaction in progress, and should not be 081 * cached. For example, SOA records are always distributed 082 * with a zero TTL to prohibit caching. Zero values can 083 * also be used for extremely volatile data. 084 */ 085 private int timeToLive; 086 087 /** 088 * A variable length string of octets that describes the 089 * resource. The format of this information varies 090 * according to the TYPE and CLASS of the resource record. 091 */ 092 private Map<String, Object> attributes; 093 094 095 /** 096 * Creates a new instance of ResourceRecordImpl. 097 * 098 * @param domainName 099 * @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 }