$search
00001 00004 package javax.jmdns.impl.constants; 00005 00006 import java.util.logging.Level; 00007 import java.util.logging.Logger; 00008 00014 public enum DNSRecordClass { 00018 CLASS_UNKNOWN("?", 0), 00022 CLASS_IN("in", 1), 00026 CLASS_CS("cs", 2), 00030 CLASS_CH("ch", 3), 00034 CLASS_HS("hs", 4), 00038 CLASS_NONE("none", 254), 00042 CLASS_ANY("any", 255); 00043 00044 private static Logger logger = Logger.getLogger(DNSRecordClass.class.getName()); 00045 00050 public static final int CLASS_MASK = 0x7FFF; 00051 00056 public static final int CLASS_UNIQUE = 0x8000; 00057 00061 public static final boolean UNIQUE = true; 00062 00066 public static final boolean NOT_UNIQUE = false; 00067 00068 private final String _externalName; 00069 00070 private final int _index; 00071 00072 DNSRecordClass(String name, int index) { 00073 _externalName = name; 00074 _index = index; 00075 } 00076 00082 public String externalName() { 00083 return _externalName; 00084 } 00085 00091 public int indexValue() { 00092 return _index; 00093 } 00094 00101 public boolean isUnique(int index) { 00102 return (this != CLASS_UNKNOWN) && ((index & CLASS_UNIQUE) != 0); 00103 } 00104 00109 public static DNSRecordClass classForName(String name) { 00110 if (name != null) { 00111 String aName = name.toLowerCase(); 00112 for (DNSRecordClass aClass : DNSRecordClass.values()) { 00113 if (aClass._externalName.equals(aName)) return aClass; 00114 } 00115 } 00116 logger.log(Level.WARNING, "Could not find record class for name: " + name); 00117 return CLASS_UNKNOWN; 00118 } 00119 00124 public static DNSRecordClass classForIndex(int index) { 00125 int maskedIndex = index & CLASS_MASK; 00126 for (DNSRecordClass aClass : DNSRecordClass.values()) { 00127 if (aClass._index == maskedIndex) return aClass; 00128 } 00129 logger.log(Level.WARNING, "Could not find record class for index: " + index); 00130 return CLASS_UNKNOWN; 00131 } 00132 00133 @Override 00134 public String toString() { 00135 return this.name() + " index " + this.indexValue(); 00136 } 00137 00138 }