Home | History | Annotate | Download | only in DNS
      1 // Copyright (c) 1999-2004 Brian Wellington (bwelling (at) xbill.org)
      2 
      3 package org.xbill.DNS;
      4 
      5 /**
      6  * Constants and functions relating to DNS message sections
      7  *
      8  * @author Brian Wellington
      9  */
     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
     61 Section() {}
     62 
     63 /** Converts a numeric Section into an abbreviation String */
     64 public static String
     65 string(int i) {
     66 	return sections.getText(i);
     67 }
     68 
     69 /** Converts a numeric Section into a full description String */
     70 public static String
     71 longString(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  */
     80 public static String
     81 updString(int i) {
     82 	sections.check(i);
     83 	return updateSections[i];
     84 }
     85 
     86 /** Converts a String representation of a Section into its numeric value */
     87 public static int
     88 value(String s) {
     89 	return sections.getValue(s);
     90 }
     91 
     92 }
     93