Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/strangeberry/rendezvous/DNSEntry.java


1   // Copyright (C) 2002  Strangeberry Inc.
2   // @(#)DNSEntry.java, 1.10, 11/29/2002
3   //
4   // This library is free software; you can redistribute it and/or
5   // modify it under the terms of the GNU Lesser General Public
6   // License as published by the Free Software Foundation; either
7   // version 2.1 of the License, or (at your option) any later version.
8   // 
9   // This library is distributed in the hope that it will be useful,
10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  // Lesser General Public License for more details.
13  // 
14  // You should have received a copy of the GNU Lesser General Public
15  // License along with this library; if not, write to the Free Software
16  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  
18  package com.strangeberry.rendezvous;
19  
20  /**
21   * DNS entry with a name, type, and class. This is the base
22   * class for questions and records.
23   *
24   * @author  Arthur van Hoff
25   * @version   1.10, 11/29/2002
26   */
27  abstract class DNSEntry extends DNSConstants
28  {
29      String key;
30      String name;
31      int type;
32      int clazz;
33      boolean unique;
34  
35      /**
36       * Create an entry.
37       */
38      DNSEntry(String name, int type, int clazz)
39      {
40    this.key = name.toLowerCase();
41    this.name = name;
42    this.type = type;
43    this.clazz = clazz & CLASS_MASK;
44    this.unique = (clazz & CLASS_UNIQUE) != 0;
45      }
46  
47      /**
48       * Check if two entries have exactly the same name, type, and class.
49       */
50      public boolean equals(Object obj)
51      {
52    if (obj instanceof DNSEntry) {
53        DNSEntry other = (DNSEntry)obj;
54        return name.equals(other.name) && type == other.type && clazz == other.clazz;
55    }
56    return false;
57      }
58  
59      /**
60       * Get a string given a clazz.
61       */
62      static String getClazz(int clazz)
63      {
64    switch (clazz & CLASS_MASK) {
65          case CLASS_IN:  return "in";
66          case CLASS_CS:  return "cs";
67          case CLASS_CH:  return "ch";
68          case CLASS_HS:  return "hs";
69          case CLASS_NONE:  return "none";
70          case CLASS_ANY:  return "any";
71      default:    return "?";
72    }
73      }
74  
75      /**
76       * Get a string given a type.
77       */
78      static String getType(int type)
79      {
80    switch (type) {
81          case TYPE_A:     return "a";
82          case TYPE_NS:    return "ns";
83          case TYPE_MD:    return "md";
84          case TYPE_MF:    return "mf";
85          case TYPE_CNAME:  return "cname";
86          case TYPE_SOA:  return "soa";
87          case TYPE_MB:    return "mb";
88          case TYPE_MG:    return "mg";
89          case TYPE_MR:    return "mr";
90          case TYPE_NULL:  return "null";
91          case TYPE_WKS:  return "wks";
92          case TYPE_PTR:  return "ptr";
93          case TYPE_HINFO:  return "hinfo";
94          case TYPE_MINFO:  return "minfo";
95          case TYPE_MX:    return "mx";
96          case TYPE_TXT:  return "txt";
97          case TYPE_SRV:  return "srv";
98      case TYPE_ANY:  return "any";
99      default:    return "?";
100   }
101     }
102 
103     public String toString(String hdr, String other)
104     {
105   return hdr + "[" + getType(type) + "," + getClazz(clazz) + (unique ? "-unique," : ",") + name + ((other != null) ? "," + other + "]" : "]");
106     }
107 }