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 message sections
07: *
08: * @author Brian Wellington
09: */
10:
11: public final class Section {
12:
13: /** The question (first) section */
14: public static final int QUESTION = 0;
15:
16: /** The answer (second) section */
17: public static final int ANSWER = 1;
18:
19: /** The authority (third) section */
20: public static final int AUTHORITY = 2;
21:
22: /** The additional (fourth) section */
23: public static final int ADDITIONAL = 3;
24:
25: /* Aliases for dynamic update */
26: /** The zone (first) section of a dynamic update message */
27: public static final int ZONE = 0;
28:
29: /** The prerequisite (second) section of a dynamic update message */
30: public static final int PREREQ = 1;
31:
32: /** The update (third) section of a dynamic update message */
33: public static final int UPDATE = 2;
34:
35: private static Mnemonic sections = new Mnemonic("Message Section",
36: Mnemonic.CASE_LOWER);
37: private static String[] longSections = new String[4];
38: private static String[] updateSections = new String[4];
39:
40: static {
41: sections.setMaximum(3);
42: sections.setNumericAllowed(true);
43:
44: sections.add(QUESTION, "qd");
45: sections.add(ANSWER, "an");
46: sections.add(AUTHORITY, "au");
47: sections.add(ADDITIONAL, "ad");
48:
49: longSections[QUESTION] = "QUESTIONS";
50: longSections[ANSWER] = "ANSWERS";
51: longSections[AUTHORITY] = "AUTHORITY RECORDS";
52: longSections[ADDITIONAL] = "ADDITIONAL RECORDS";
53:
54: updateSections[ZONE] = "ZONE";
55: updateSections[PREREQ] = "PREREQUISITES";
56: updateSections[UPDATE] = "UPDATE RECORDS";
57: updateSections[ADDITIONAL] = "ADDITIONAL RECORDS";
58: }
59:
60: private Section() {
61: }
62:
63: /** Converts a numeric Section into an abbreviation String */
64: public static String string(int i) {
65: return sections.getText(i);
66: }
67:
68: /** Converts a numeric Section into a full description String */
69: public static String longString(int i) {
70: sections.check(i);
71: return longSections[i];
72: }
73:
74: /**
75: * Converts a numeric Section into a full description String for an update
76: * Message.
77: */
78: public static String updString(int i) {
79: sections.check(i);
80: return updateSections[i];
81: }
82:
83: /** Converts a String representation of a Section into its numeric value */
84: public static int value(String s) {
85: return sections.getValue(s);
86: }
87:
88: }
|