1// Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2
3package org.xbill.DNS;
4
5/**
6 * Constants and functions relating to DNS message sections
7 *
8 * @author Brian Wellington
9 */
10
11public final class Section {
12
13/** The question (first) section */
14public static final int QUESTION	= 0;
15
16/** The answer (second) section */
17public static final int ANSWER		= 1;
18
19/** The authority (third) section */
20public static final int AUTHORITY	= 2;
21
22/** The additional (fourth) section */
23public static final int ADDITIONAL	= 3;
24
25/* Aliases for dynamic update */
26/** The zone (first) section of a dynamic update message */
27public static final int ZONE		= 0;
28
29/** The prerequisite (second) section of a dynamic update message */
30public static final int PREREQ		= 1;
31
32/** The update (third) section of a dynamic update message */
33public static final int UPDATE		= 2;
34
35private static Mnemonic sections = new Mnemonic("Message Section",
36						Mnemonic.CASE_LOWER);
37private static String [] longSections = new String[4];
38private static String [] updateSections = new String[4];
39
40static {
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
60private
61Section() {}
62
63/** Converts a numeric Section into an abbreviation String */
64public static String
65string(int i) {
66	return sections.getText(i);
67}
68
69/** Converts a numeric Section into a full description String */
70public static String
71longString(int i) {
72	sections.check(i);
73	return longSections[i];
74}
75
76/**
77 * Converts a numeric Section into a full description String for an update
78 * Message.
79 */
80public static String
81updString(int i) {
82	sections.check(i);
83	return updateSections[i];
84}
85
86/** Converts a String representation of a Section into its numeric value */
87public static int
88value(String s) {
89	return sections.getValue(s);
90}
91
92}
93