1
2
3
4 package javax.jmdns.impl.constants;
5
6 import java.util.logging.Level;
7 import java.util.logging.Logger;
8
9
10
11
12
13
14 public enum DNSRecordClass {
15
16
17
18 CLASS_UNKNOWN("?", 0),
19
20
21
22 CLASS_IN("in", 1),
23
24
25
26 CLASS_CS("cs", 2),
27
28
29
30 CLASS_CH("ch", 3),
31
32
33
34 CLASS_HS("hs", 4),
35
36
37
38 CLASS_NONE("none", 254),
39
40
41
42 CLASS_ANY("any", 255);
43
44 private static Logger logger = Logger.getLogger(DNSRecordClass.class.getName());
45
46
47
48
49
50 public static final int CLASS_MASK = 0x7FFF;
51
52
53
54
55
56 public static final int CLASS_UNIQUE = 0x8000;
57
58
59
60
61 public static final boolean UNIQUE = true;
62
63
64
65
66 public static final boolean NOT_UNIQUE = false;
67
68 private final String _externalName;
69
70 private final int _index;
71
72 DNSRecordClass(String name, int index) {
73 _externalName = name;
74 _index = index;
75 }
76
77
78
79
80
81
82 public String externalName() {
83 return _externalName;
84 }
85
86
87
88
89
90
91 public int indexValue() {
92 return _index;
93 }
94
95
96
97
98
99
100
101 public boolean isUnique(int index) {
102 return (this != CLASS_UNKNOWN) && ((index & CLASS_UNIQUE) != 0);
103 }
104
105
106
107
108
109 public static DNSRecordClass classForName(String name) {
110 if (name != null) {
111 String aName = name.toLowerCase();
112 for (DNSRecordClass aClass : DNSRecordClass.values()) {
113 if (aClass._externalName.equals(aName)) return aClass;
114 }
115 }
116 logger.log(Level.WARNING, "Could not find record class for name: " + name);
117 return CLASS_UNKNOWN;
118 }
119
120
121
122
123
124 public static DNSRecordClass classForIndex(int index) {
125 int maskedIndex = index & CLASS_MASK;
126 for (DNSRecordClass aClass : DNSRecordClass.values()) {
127 if (aClass._index == maskedIndex) return aClass;
128 }
129 logger.log(Level.WARNING, "Could not find record class for index: " + index);
130 return CLASS_UNKNOWN;
131 }
132
133 @Override
134 public String toString() {
135 return this.name() + " index " + this.indexValue();
136 }
137
138 }