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 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 /**
     64  * Checks that a numeric DClass is valid.
     65  * @throws InvalidDClassException The class is out of range.
     66  */
     67 public static void
     68 check(int i) {
     69 	if (i < 0 || i > 0xFFFF)
     70 		throw new InvalidDClassException(i);
     71 }
     72 
     73 /**
     74  * Converts a numeric DClass into a String
     75  * @return The canonical string representation of the class
     76  * @throws InvalidDClassException The class is out of range.
     77  */
     78 public static String
     79 string(int i) {
     80 	return classes.getText(i);
     81 }
     82 
     83 /**
     84  * Converts a String representation of a DClass into its numeric value
     85  * @return The class code, or -1 on error.
     86  */
     87 public static int
     88 value(String s) {
     89 	return classes.getValue(s);
     90 }
     91 
     92 }
     93