01: // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
02:
03: package org.xbill.DNS;
04:
05: /**
06: * Constants and functions relating to DNS classes. This is called DClass
07: * to avoid confusion with Class.
08: *
09: * @author Brian Wellington
10: */
11:
12: public final class DClass {
13:
14: /** Internet */
15: public static final int IN = 1;
16:
17: /** Chaos network (MIT) */
18: public static final int CH = 3;
19:
20: /** Chaos network (MIT, alternate name) */
21: public static final int CHAOS = 3;
22:
23: /** Hesiod name server (MIT) */
24: public static final int HS = 4;
25:
26: /** Hesiod name server (MIT, alternate name) */
27: public static final int HESIOD = 4;
28:
29: /** Special value used in dynamic update messages */
30: public static final int NONE = 254;
31:
32: /** Matches any class */
33: public static final int ANY = 255;
34:
35: private static class DClassMnemonic extends Mnemonic {
36: public DClassMnemonic() {
37: super ("DClass", CASE_UPPER);
38: setPrefix("CLASS");
39: }
40:
41: public void check(int val) {
42: DClass.check(val);
43: }
44: }
45:
46: private static Mnemonic classes = new DClassMnemonic();
47:
48: static {
49: classes.add(IN, "IN");
50: classes.add(CH, "CH");
51: classes.addAlias(CH, "CHAOS");
52: classes.add(HS, "HS");
53: classes.addAlias(HS, "HESIOD");
54: classes.add(NONE, "NONE");
55: classes.add(ANY, "ANY");
56: }
57:
58: private DClass() {
59: }
60:
61: static void check(int i) {
62: if (i < 0 || i > 0xFFFF)
63: throw new InvalidDClassException(i);
64: }
65:
66: /**
67: * Converts a numeric DClass into a String
68: * @return The canonical string representation of the class
69: * @throws InvalidDClassException The class is out of range.
70: */
71: public static String string(int i) {
72: return classes.getText(i);
73: }
74:
75: /**
76: * Converts a String representation of a DClass into its numeric value
77: * @return The class code, or -1 on error.
78: */
79: public static int value(String s) {
80: return classes.getValue(s);
81: }
82:
83: }
|