~ubuntu-branches/ubuntu/wily/dnsjava/wily-proposed

« back to all changes in this revision

Viewing changes to org/xbill/DNS/DClass.java

  • Committer: Bazaar Package Importer
  • Author(s): Thierry Carrez
  • Date: 2009-07-21 15:17:03 UTC
  • Revision ID: james.westby@ubuntu.com-20090721151703-6v0107p1s3h7gv1c
Tags: upstream-2.0.6
ImportĀ upstreamĀ versionĀ 2.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
 
2
 
 
3
package org.xbill.DNS;
 
4
 
 
5
/**
 
6
 * Constants and functions relating to DNS classes.  This is called DClass
 
7
 * to avoid confusion with Class.
 
8
 *
 
9
 * @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
 
37
        DClassMnemonic() {
 
38
                super("DClass", CASE_UPPER);
 
39
                setPrefix("CLASS");
 
40
        }
 
41
 
 
42
        public void
 
43
        check(int val) {
 
44
                DClass.check(val);
 
45
        }
 
46
}
 
47
 
 
48
private static Mnemonic classes = new DClassMnemonic();
 
49
 
 
50
static {
 
51
        classes.add(IN, "IN");
 
52
        classes.add(CH, "CH");
 
53
        classes.addAlias(CH, "CHAOS");
 
54
        classes.add(HS, "HS");
 
55
        classes.addAlias(HS, "HESIOD");
 
56
        classes.add(NONE, "NONE");
 
57
        classes.add(ANY, "ANY");
 
58
}
 
59
 
 
60
private
 
61
DClass() {}
 
62
 
 
63
static void
 
64
check(int i) {
 
65
        if (i < 0 || i > 0xFFFF)
 
66
                throw new InvalidDClassException(i);
 
67
}
 
68
 
 
69
/**
 
70
 * Converts a numeric DClass into a String
 
71
 * @return The canonical string representation of the class
 
72
 * @throws InvalidDClassException The class is out of range.
 
73
 */
 
74
public static String
 
75
string(int i) {
 
76
        return classes.getText(i);
 
77
}
 
78
 
 
79
/**
 
80
 * Converts a String representation of a DClass into its numeric value
 
81
 * @return The class code, or -1 on error.
 
82
 */
 
83
public static int
 
84
value(String s) {
 
85
        return classes.getValue(s);
 
86
}
 
87
 
 
88
}