directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r500956 [2/3] - in /directory/apacheds/trunk/protocol-dns/src: main/java/org/apache/directory/server/dns/ main/java/org/apache/directory/server/dns/io/decoder/ main/java/org/apache/directory/server/dns/io/encoder/ main/java/org/apache/direc...
Date Mon, 29 Jan 2007 07:46:01 GMT
Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/RecordClass.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/RecordClass.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/RecordClass.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/RecordClass.java Sun Jan 28 23:45:59 2007
@@ -21,97 +21,49 @@
 package org.apache.directory.server.dns.messages;
 
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import org.apache.directory.server.dns.util.EnumConverter;
+import org.apache.directory.server.dns.util.ReverseEnumMap;
 
 
-public final class RecordClass implements Comparable
+public enum RecordClass implements EnumConverter<Short>
 {
-    /**
-     * Enumeration elements are constructed once upon class loading.
-     * Order of appearance here determines the order of compareTo.
-     */
-    public static final RecordClass IN = new RecordClass( 1, "IN", "Internet" );
-    public static final RecordClass CS = new RecordClass( 2, "CS", "CSNET class" );
-    public static final RecordClass CH = new RecordClass( 3, "CH", "CHAOS class" );
-    public static final RecordClass HS = new RecordClass( 4, "HS", "Hesiod [Dyer 87]" );
-    public static final RecordClass NONE = new RecordClass( 254, "NONE",
-        "Special value used in dynamic update messages" );
-    public static final RecordClass ANY = new RecordClass( 255, "*", "Any class" );
-
-    /**
-     * These two lines are all that's necessary to export a List of VALUES.
-     */
-    private static final RecordClass[] values =
-        { IN, CS, CH, HS, NONE, ANY };
-
-    public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
-
-    private final String name;
-    private final String code;
-    private final int ordinal;
-
-
-    /**
-     * Private constructor prevents construction outside of this class.
-     */
-    private RecordClass(int ordinal, String code, String name)
-    {
-        this.ordinal = ordinal;
-        this.code = code;
-        this.name = name;
-    }
+    /** Internet */
+    IN(1),
 
+    /** CSNET class */
+    CS(2),
 
-    public String toString()
-    {
-        return name;
-    }
+    /** CHAOS class */
+    CH(3),
 
+    /** Hesiod [Dyer 87] */
+    HS(4),
 
-    public int compareTo( Object that )
-    {
-        return ordinal - ( ( RecordClass ) that ).ordinal;
-    }
+    /** Special value used in dynamic update messages */
+    NONE(254),
 
+    /** Any class */
+    ANY(255);
 
-    public static RecordClass getTypeByOrdinal( int type )
-    {
-        for ( int ii = 0; ii < values.length; ii++ )
-        {
-            if ( values[ii].ordinal == type )
-            {
-                return values[ii];
-            }
-        }
+    private static ReverseEnumMap<Short, RecordClass> map = new ReverseEnumMap<Short, RecordClass>( RecordClass.class );
 
-        return IN;
-    }
+    private final short value;
 
 
-    public static RecordClass getTypeByName( String type )
+    private RecordClass( int value )
     {
-        for ( int ii = 0; ii < values.length; ii++ )
-        {
-            if ( values[ii].code.equalsIgnoreCase( type ) )
-            {
-                return values[ii];
-            }
-        }
-
-        return IN;
+        this.value = ( byte ) value;
     }
 
 
-    public int getOrdinal()
+    public Short convert()
     {
-        return ordinal;
+        return this.value;
     }
 
 
-    public String getCode()
+    public static RecordClass convert( short value )
     {
-        return code;
+        return map.get( value );
     }
 }

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/RecordType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/RecordType.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/RecordType.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/RecordType.java Sun Jan 28 23:45:59 2007
@@ -21,164 +21,206 @@
 package org.apache.directory.server.dns.messages;
 
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import org.apache.directory.server.dns.util.EnumConverter;
+import org.apache.directory.server.dns.util.ReverseEnumMap;
 
 
-public class RecordType implements Comparable
+public enum RecordType implements EnumConverter<Short>
 {
-    /**
-     * Enumeration elements are constructed once upon class loading.
-     * Order of appearance here determines the order of compareTo.
-     */
-    public static final RecordType A = new RecordType( 1, "A", "Host address" );
-    public static final RecordType NS = new RecordType( 2, "NS", "Authoritative name server" );
-    public static final RecordType MD = new RecordType( 3, "MD", "Mail destination" );
-    public static final RecordType MF = new RecordType( 4, "MF", "Mail forwarder" );
-    public static final RecordType CNAME = new RecordType( 5, "CNAME", "Canonical name for an alias" );
-    public static final RecordType SOA = new RecordType( 6, "SOA", "Start of a zone of authority" );
-    public static final RecordType MB = new RecordType( 7, "MB", "Mailbox domain name" );
-    public static final RecordType MG = new RecordType( 8, "MG", "Mail group member" );
-    public static final RecordType MR = new RecordType( 9, "MR", "Mail rename domain name" );
-    public static final RecordType NULL = new RecordType( 10, "NULL", "Null resource record" );
-    public static final RecordType WKS = new RecordType( 11, "WKS", "Well known service description" );
-    public static final RecordType PTR = new RecordType( 12, "PTR", "Domain name pointer" );
-    public static final RecordType HINFO = new RecordType( 13, "HINFO", "Host information" );
-    public static final RecordType MINFO = new RecordType( 14, "MINFO", "Mailbox or mail list information" );
-    public static final RecordType MX = new RecordType( 15, "MX", "Mail exchange" );
-    public static final RecordType TXT = new RecordType( 16, "TXT", "Text strings" );
-    public static final RecordType RP = new RecordType( 17, "RP", "Responsible person" );
-    public static final RecordType AFSDB = new RecordType( 18, "AFSDB", "AFS cell database" );
-    public static final RecordType X25 = new RecordType( 19, "X25", "X.25 calling address" );
-    public static final RecordType ISDN = new RecordType( 20, "ISDN", "ISDN calling address" );
-    public static final RecordType RT = new RecordType( 21, "RT", "Router" );
-    public static final RecordType NSAP = new RecordType( 22, "NSAP", "NSAP address" );
-    public static final RecordType NSAP_PTR = new RecordType( 23, "NSAP_PTR", "Reverse NSAP address (deprecated)" );
-    public static final RecordType SIG = new RecordType( 24, "SIG", "Signature" );
-    public static final RecordType KEY = new RecordType( 25, "KEY", "Key" );
-    public static final RecordType PX = new RecordType( 26, "PX", "X.400 mail mapping" );
-    public static final RecordType GPOS = new RecordType( 27, "GPOS", "Geographical position (withdrawn)" );
-    public static final RecordType AAAA = new RecordType( 28, "AAAA", "IPv6 address" );
-    public static final RecordType LOC = new RecordType( 29, "LOC", "Location" );
-    public static final RecordType NXT = new RecordType( 30, "NXT", "Next valid name in zone" );
-    public static final RecordType EID = new RecordType( 31, "EID", "Endpoint identifier" );
-    public static final RecordType NIMLOC = new RecordType( 32, "NIMLOC", "Nimrod locator" );
-    public static final RecordType SRV = new RecordType( 33, "SRV", "Server selection" );
-    public static final RecordType ATMA = new RecordType( 34, "ATMA", "ATM address" );
-    public static final RecordType NAPTR = new RecordType( 35, "NAPTR", "Naming authority pointer" );
-    public static final RecordType KX = new RecordType( 36, "KX", "Key exchange" );
-    public static final RecordType CERT = new RecordType( 34, "CERT", "Certificate" );
-    public static final RecordType A6 = new RecordType( 38, "A6", "IPv6 address (experimental)" );
-    public static final RecordType DNAME = new RecordType( 39, "DNAME", "Non-terminal name redirection" );
-    public static final RecordType OPT = new RecordType( 41, "OPT", "Options - contains EDNS metadata" );
-    public static final RecordType APL = new RecordType( 42, "APL", "Address Prefix List" );
-    public static final RecordType DS = new RecordType( 43, "DS", "Delegation Signer" );
-    public static final RecordType SSHFP = new RecordType( 44, "SSHFP", "SSH Key Fingerprint" );
-    public static final RecordType RRSIG = new RecordType( 46, "RRSIG", "Resource Record Signature" );
-    public static final RecordType NSEC = new RecordType( 47, "NSEC", "Next Secure Name" );
-    public static final RecordType DNSKEY = new RecordType( 48, "DNSKEY", "DNSSEC Key" );
-    public static final RecordType TKEY = new RecordType( 249, "TKEY",
-        "Transaction key - used to compute a shared secret or exchange a key" );
-    public static final RecordType TSIG = new RecordType( 250, "TSIG", "Transaction signature" );
-    public static final RecordType IXFR = new RecordType( 251, "IXFR", "Incremental zone transfer" );
-    public static final RecordType AXFR = new RecordType( 252, "AXFR", "Request for transfer of an entire zone" );
-    public static final RecordType MAILB = new RecordType( 253, "MAILB", "Request for mailbox-related records" );
-    public static final RecordType MAILA = new RecordType( 254, "MAILA", "Request for mail agent resource records" );
-    public static final RecordType ANY = new RecordType( 255, "ANY", "Request for all records" );
-
-    /**
-     * These two lines are all that's necessary to export a List of VALUES.
-     */
-    private static final RecordType[] values =
-        { A, NS, MD, MF, CNAME, SOA, MB, MG, MR, NULL, WKS, PTR, HINFO, MINFO, MX, TXT, RP, AFSDB, X25, ISDN, RT, NSAP,
-            NSAP_PTR, SIG, KEY, PX, GPOS, AAAA, LOC, NXT, EID, NIMLOC, SRV, ATMA, NAPTR, KX, CERT, A6, DNAME, OPT, APL,
-            DS, SSHFP, RRSIG, NSEC, DNSKEY, TKEY, TSIG, IXFR, AXFR, MAILB, MAILA, ANY };
-
-    public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
-
-    private final String name;
-    private final String code;
-    private final int ordinal;
-
-
-    /**
-     * Private constructor prevents construction outside of this class.
-     */
-    private RecordType(int ordinal, String code, String name)
-    {
-        this.ordinal = ordinal;
-        this.code = code;
-        this.name = name;
-    }
+    /** Host address */
+    A(1),
 
+    /** Authoritative name server */
+    NS(2),
 
-    public String toString()
-    {
-        return name;
-    }
+    /** Mail destination */
+    MD(3),
 
+    /** Mail forwarder */
+    MF(4),
 
-    public int compareTo( Object that )
-    {
-        return ordinal - ( ( RecordType ) that ).ordinal;
-    }
+    /** Canonical name for an alias */
+    CNAME(5),
 
+    /** Start of a zone of authority */
+    SOA(6),
 
-    public static RecordType getTypeByOrdinal( int type )
-    {
-        for ( int ii = 0; ii < values.length; ii++ )
-        {
-            if ( values[ii].ordinal == type )
-            {
-                return values[ii];
-            }
-        }
+    /** Mailbox domain name */
+    MB(7),
 
-        return A;
-    }
+    /** Mail group member */
+    MG(8),
 
+    /** Mail rename domain name */
+    MR(9),
 
-    public static RecordType getTypeByName( String type )
-    {
-        for ( int ii = 0; ii < values.length; ii++ )
-        {
-            if ( values[ii].code.equalsIgnoreCase( type ) )
-            {
-                return values[ii];
-            }
-        }
+    /** Null resource record */
+    NULL(10),
+
+    /** Well know service description */
+    WKS(11),
+
+    /** Domain name pointer */
+    PTR(12),
+
+    /** Host information */
+    HINFO(13),
+
+    /** Mailbox or mail list information */
+    MINFO(14),
+
+    /** Mail exchange */
+    MX(15),
+
+    /** Text strings */
+    TXT(16),
+
+    /** Responsible person */
+    RP(17),
+
+    /** AFS cell database */
+    AFSDB(18),
+
+    /** X.25 calling address */
+    X25(19),
+
+    /** ISDN calling address */
+    ISDN(20),
+
+    /** Router */
+    RT(21),
+
+    /** NSAP address */
+    NSAP(22),
+
+    /** Reverse NSAP address (deprecated) */
+    NSAP_PTR(23),
+
+    /** Signature */
+    SIG(24),
+
+    /** Key */
+    KEY(25),
+
+    /** X.400 mail mapping */
+    PX(26),
+
+    /** Geographical position (withdrawn) */
+    GPOS(27),
+
+    /** IPv6 address */
+    AAAA(28),
+
+    /** Location */
+    LOC(29),
 
-        return A;
+    /** Next valid name in zone */
+    NXT(30),
+
+    /** Endpoint identifier */
+    EID(31),
+
+    /** Nimrod locator */
+    NIMLOC(32),
+
+    /** Server selection */
+    SRV(33),
+
+    /** ATM address */
+    ATMA(34),
+
+    /** Naming authority pointer */
+    NAPTR(35),
+
+    /** Key exchange */
+    KX(36),
+
+    /** Certificate */
+    CERT(34),
+
+    /** IPv6 address (experimental) */
+    A6(38),
+
+    /** Non-terminal name redirection */
+    DNAME(39),
+
+    /** Options - contains EDNS metadata */
+    OPT(41),
+
+    /** Address Prefix List */
+    APL(42),
+
+    /** Delegation Signer */
+    DS(43),
+
+    /** SSH Key Fingerprint */
+    SSHFP(44),
+
+    /** Resource Record Signature */
+    RRSIG(46),
+
+    /** Next Secure Name */
+    NSEC(47),
+
+    /** DNSSEC Key */
+    DNSKEY(48),
+
+    /** Transaction key - used to compute a shared secret or exchange a key */
+    TKEY(249),
+
+    /** Transaction signature */
+    TSIG(250),
+
+    /** Incremental zone transfer */
+    IXFR(251),
+
+    /** Request for transfer of an entire zone */
+    AXFR(252),
+
+    /** Request for mailbox-related records */
+    MAILB(253),
+
+    /** Request for mail agent resource records */
+    MAILA(254),
+
+    /** Request for all records */
+    ANY(255);
+
+    private static ReverseEnumMap<Short, RecordType> map = new ReverseEnumMap<Short, RecordType>( RecordType.class );
+
+    private final short value;
+
+
+    private RecordType( int value )
+    {
+        this.value = ( short ) value;
     }
 
 
-    public int getOrdinal()
+    public Short convert()
     {
-        return ordinal;
+        return this.value;
     }
 
 
-    public String getCode()
+    public static RecordType convert( short value )
     {
-        return code;
+        return map.get( value );
     }
 
 
     public static boolean isResourceRecord( RecordType resourceType )
     {
-        int type = resourceType.getOrdinal();
-
-        switch ( type )
+        switch ( resourceType )
         {
-            case 41:
-            case 249:
-            case 250:
-            case 251:
-            case 252:
-            case 253:
-            case 254:
-            case 255:
+            case OPT:
+            case TKEY:
+            case TSIG:
+            case IXFR:
+            case AXFR:
+            case MAILB:
+            case MAILA:
+            case ANY:
                 return false;
             default:
                 return true;

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResourceRecordImpl.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResourceRecordImpl.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResourceRecordImpl.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResourceRecordImpl.java Sun Jan 28 23:45:59 2007
@@ -159,7 +159,7 @@
 
         ResourceRecordImpl that = ( ResourceRecordImpl ) o;
 
-        return ( this.domainName.equals( that.domainName ) ) && ( this.recordType == that.recordType )
+        return ( this.domainName.equalsIgnoreCase( that.domainName ) ) && ( this.recordType == that.recordType )
             && ( this.recordClass == that.recordClass );
     }
 
@@ -173,6 +173,6 @@
     public String toString()
     {
         return getClass().getName() + " [ " + domainName + " ( " + recordType + " " + recordClass + " " + timeToLive
-            + " " + attributes.size() + " ) ]";
+            + " " + attributes + " ) ]";
     }
 }

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResourceRecordModifier.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResourceRecordModifier.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResourceRecordModifier.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResourceRecordModifier.java Sun Jan 28 23:45:59 2007
@@ -35,10 +35,7 @@
     private RecordType dnsType;
     private RecordClass dnsClass;
     private int dnsTtl;
-    
-    /**
-     * TODO : Is this object really used? I don't think so...
-     */
+
     private Map<String, String> attributes = new HashMap<String, String>();
 
 

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResponseCode.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResponseCode.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResponseCode.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ResponseCode.java Sun Jan 28 23:45:59 2007
@@ -21,85 +21,49 @@
 package org.apache.directory.server.dns.messages;
 
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import org.apache.directory.server.dns.util.EnumConverter;
+import org.apache.directory.server.dns.util.ReverseEnumMap;
 
 
-public final class ResponseCode implements Comparable
+public enum ResponseCode implements EnumConverter<Byte>
 {
-    /**
-     * Enumeration elements are constructed once upon class loading.
-     * Order of appearance here determines the order of compareTo.
-     */
-    public static final ResponseCode NO_ERROR = new ResponseCode( 0, "No error condition." );
-    public static final ResponseCode FORMAT_ERROR = new ResponseCode( 1,
-        "The name server was unable to interpret the query." );
-    public static final ResponseCode SERVER_FAILURE = new ResponseCode( 2,
-        "The name server was unable to process this query due to a problem with the name server." );
-    public static final ResponseCode NAME_ERROR = new ResponseCode( 3,
-        "The domain name referenced in the query does not exist." );
-    public static final ResponseCode NOT_IMPLEMENTED = new ResponseCode( 4,
-        "The name server does not support the requested kind of query." );
-    public static final ResponseCode REFUSED = new ResponseCode( 5,
-        "The name server refuses to perform the specified operation for policy reasons." );
-
-    /**
-     * These two lines are all that's necessary to export a List of VALUES.
-     */
-    private static final ResponseCode[] values =
-        { NO_ERROR, FORMAT_ERROR, SERVER_FAILURE, NAME_ERROR, NOT_IMPLEMENTED, REFUSED };
-
-    public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
-
-    private final String name;
-    private final int ordinal;
-
-
-    /**
-     * Private constructor prevents construction outside of this class.
-     */
-    private ResponseCode(int ordinal, String name)
-    {
-        this.ordinal = ordinal;
-        this.name = name;
-    }
+    /** No error condition. */
+    NO_ERROR(0),
 
+    /** The name server was unable to interpret the query. */
+    FORMAT_ERROR(1),
 
-    public String getMessage()
-    {
-        return name;
-    }
+    /** The name server was unable to process this query due to a problem with the name server. */
+    SERVER_FAILURE(2),
 
+    /** The domain name referenced in the query does not exist. */
+    NAME_ERROR(3),
 
-    public String toString()
-    {
-        return name;
-    }
+    /** The name server does not support the requested kind of query. */
+    NOT_IMPLEMENTED(4),
+
+    /** The name server refuses to perform the specified operation for policy reasons. */
+    REFUSED(5);
+
+    private static ReverseEnumMap<Byte, ResponseCode> map = new ReverseEnumMap<Byte, ResponseCode>( ResponseCode.class );
 
+    private final byte value;
 
-    public int compareTo( Object that )
+
+    private ResponseCode( int value )
     {
-        return ordinal - ( ( ResponseCode ) that ).ordinal;
+        this.value = ( byte ) value;
     }
 
 
-    public static ResponseCode getTypeByOrdinal( int type )
+    public Byte convert()
     {
-        for ( int ii = 0; ii < values.length; ii++ )
-        {
-            if ( values[ii].ordinal == type )
-            {
-                return values[ii];
-            }
-        }
-
-        return NO_ERROR;
+        return this.value;
     }
 
 
-    public int getOrdinal()
+    public static ResponseCode convert( byte value )
     {
-        return ordinal;
+        return map.get( value );
     }
 }

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ServiceType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ServiceType.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ServiceType.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/messages/ServiceType.java Sun Jan 28 23:45:59 2007
@@ -21,154 +21,271 @@
 package org.apache.directory.server.dns.messages;
 
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import org.apache.directory.server.dns.util.EnumConverter;
+import org.apache.directory.server.dns.util.ReverseEnumMap;
 
 
-public final class ServiceType implements Comparable
+public enum ServiceType implements EnumConverter<Byte>
 {
-    /**
-     * Enumeration elements are constructed once upon class loading.
-     * Order of appearance here determines the order of compareTo.
-     */
-    public static final ServiceType NULL = new ServiceType( 0, "Null" );
-    public static final ServiceType RJE = new ServiceType( 5, "Remote job entry." );
-    public static final ServiceType ECHO = new ServiceType( 7, "Echo" );
-    public static final ServiceType DISCARD = new ServiceType( 9, "Discard" );
-    public static final ServiceType USERS = new ServiceType( 11, "Active users." );
-    public static final ServiceType DAYTIME = new ServiceType( 13, "Daytime" );
-    public static final ServiceType QUOTE = new ServiceType( 17, "Quote of the day." );
-    public static final ServiceType CHARGEN = new ServiceType( 19, "Character generator." );
-    public static final ServiceType FTP_DATA = new ServiceType( 20, "File Transfer [Default Data]" );
-    public static final ServiceType FTP = new ServiceType( 21, "File Transfer [Control]" );
-    public static final ServiceType TELNET = new ServiceType( 23, "Telnet" );
-    public static final ServiceType SMTP = new ServiceType( 25, "Simple Mail Transfer" );
-    public static final ServiceType NSW_FE = new ServiceType( 27, "NSW User System FE" );
-    public static final ServiceType MSG_ICP = new ServiceType( 29, "MSG ICP" );
-    public static final ServiceType MSG_AUTH = new ServiceType( 31, "MSG Authentication" );
-    public static final ServiceType DSP = new ServiceType( 33, "Display Support Protocol" );
-    public static final ServiceType TIME = new ServiceType( 37, "Time" );
-    public static final ServiceType RLP = new ServiceType( 39, "Resource Location Protocol" );
-    public static final ServiceType GRAPHICS = new ServiceType( 41, "Graphics" );
-    public static final ServiceType NAMESERVER = new ServiceType( 42, "Host Name Server" );
-    public static final ServiceType NICKNAME = new ServiceType( 43, "Who Is" );
-    public static final ServiceType MPM_FLAGS = new ServiceType( 44, "MPM FLAGS Protocol" );
-    public static final ServiceType MPM = new ServiceType( 45, "Message Processing Module [recv]" );
-    public static final ServiceType MPM_SND = new ServiceType( 46, "MPM [default send]" );
-    public static final ServiceType NI_FTP = new ServiceType( 47, "NI FTP" );
-    public static final ServiceType LOGIN = new ServiceType( 49, "Login Host Protocol" );
-    public static final ServiceType LA_MAINT = new ServiceType( 51, "IMP Logical Address Maintenance" );
-    public static final ServiceType DOMAIN = new ServiceType( 53, "Domain Name Server" );
-    public static final ServiceType ISI_GL = new ServiceType( 55, "ISI Graphics Language" );
-    public static final ServiceType NI_MAIL = new ServiceType( 61, "NI MAIL" );
-    public static final ServiceType VIA_FTP = new ServiceType( 63, "VIA Systems - FTP" );
-    public static final ServiceType TACACS_DS = new ServiceType( 65, "TACACS-Database Service" );
-    public static final ServiceType BOOTPS = new ServiceType( 67, "Bootstrap Protocol Server" );
-    public static final ServiceType BOOTPC = new ServiceType( 68, "Bootstrap Protocol Client" );
-    public static final ServiceType TFTP = new ServiceType( 69, "Trivial File Transfer" );
-    public static final ServiceType NETRJS_1 = new ServiceType( 71, "Remote Job Service" );
-    public static final ServiceType NETRJS_2 = new ServiceType( 72, "Remote Job Service" );
-    public static final ServiceType NETRJS_3 = new ServiceType( 73, "Remote Job Service" );
-    public static final ServiceType NETRJS_4 = new ServiceType( 74, "Remote Job Service" );
-    public static final ServiceType FINGER = new ServiceType( 79, "Finger" );
-    public static final ServiceType HOSTS2_NS = new ServiceType( 81, "HOSTS2 Name Server" );
-    public static final ServiceType SU_MIT_TG = new ServiceType( 89, "SU/MIT Telnet Gateway" );
-    public static final ServiceType MIT_DOV = new ServiceType( 91, "MIT Dover Spooler" );
-    public static final ServiceType DCP = new ServiceType( 93, "Device Control Protocol" );
-    public static final ServiceType SUPDUP = new ServiceType( 95, "SUPDUP" );
-    public static final ServiceType SWIFT_RVF = new ServiceType( 97, "Swift Remote Virtual File Protocol" );
-    public static final ServiceType TACNEWS = new ServiceType( 98, "TAC News" );
-    public static final ServiceType METAGRAM = new ServiceType( 99, "Metagram Relay" );
-    public static final ServiceType HOSTNAME = new ServiceType( 101, "NIC Host Name Server" );
-    public static final ServiceType ISO_TSAP = new ServiceType( 102, "ISO-TSAP" );
-    public static final ServiceType X400 = new ServiceType( 103, "X400" );
-    public static final ServiceType X400_SND = new ServiceType( 104, "X400-SND" );
-    public static final ServiceType CSNET_NS = new ServiceType( 105, "Mailbox Name Nameserver" );
-    public static final ServiceType RTELNET = new ServiceType( 107, "Remote Telnet Service" );
-    public static final ServiceType POP_2 = new ServiceType( 109, "Post Office Protocol - Version 2" );
-    public static final ServiceType SUNRPC = new ServiceType( 111, "SUN Remote Procedure Call" );
-    public static final ServiceType AUTH = new ServiceType( 113, "Authentication Service" );
-    public static final ServiceType SFTP = new ServiceType( 115, "Simple File Transfer Protocol" );
-    public static final ServiceType UUCP_PATH = new ServiceType( 117, "UUCP Path Service" );
-    public static final ServiceType NNTP = new ServiceType( 119, "Network News Transfer Protocol" );
-    public static final ServiceType ERPC = new ServiceType( 121, "HYDRA Expedited Remote Procedure" );
-    public static final ServiceType NTP = new ServiceType( 123, "Network Time Protocol" );
-    public static final ServiceType LOCUS_MAP = new ServiceType( 125, "Locus PC-Interface Net Map Server" );
-    public static final ServiceType LOCUS_CON = new ServiceType( 127, "Locus PC-Interface Conn Server" );
-    public static final ServiceType PWDGEN = new ServiceType( 129, "Password Generator Protocol" );
-    public static final ServiceType CISCO_FNA = new ServiceType( 130, "CISCO FNATIVE" );
-    public static final ServiceType CISCO_TNA = new ServiceType( 131, "CISCO TNATIVE" );
-    public static final ServiceType CISCO_SYS = new ServiceType( 132, "CISCO SYSMAINT" );
-    public static final ServiceType STATSRV = new ServiceType( 133, "Statistics Service" );
-    public static final ServiceType INGRES_NET = new ServiceType( 134, "INGRES-NET Service" );
-    public static final ServiceType LOC_SRV = new ServiceType( 135, "Location Service" );
-    public static final ServiceType PROFILE = new ServiceType( 136, "PROFILE Naming System" );
-    public static final ServiceType NETBIOS_NS = new ServiceType( 137, "NETBIOS Name Service" );
-    public static final ServiceType NETBIOS_DGM = new ServiceType( 138, "NETBIOS Datagram Service" );
-    public static final ServiceType NETBIOS_SSN = new ServiceType( 139, "NETBIOS Session Service" );
-    public static final ServiceType EMFIS_DATA = new ServiceType( 140, "EMFIS Data Service" );
-    public static final ServiceType EMFIS_CNTL = new ServiceType( 141, "EMFIS Control Service" );
-    public static final ServiceType BL_IDM = new ServiceType( 142, "Britton-Lee IDM" );
-    public static final ServiceType SUR_MEAS = new ServiceType( 243, "Survey Measurement" );
-    public static final ServiceType LINK = new ServiceType( 245, "LINK" );
-
-    /**
-     * These two lines are all that's necessary to export a List of VALUES.
-     */
-    private static final ServiceType[] values =
-        { NULL, RJE, ECHO, DISCARD, USERS, DAYTIME, QUOTE, CHARGEN, FTP_DATA, FTP, TELNET, SMTP, NSW_FE, MSG_ICP,
-            MSG_AUTH, DSP, TIME, RLP, GRAPHICS, NAMESERVER, NICKNAME, MPM_FLAGS, MPM, MPM_SND, NI_FTP, LOGIN, LA_MAINT,
-            DOMAIN, ISI_GL, NI_MAIL, VIA_FTP, TACACS_DS, BOOTPS, BOOTPC, TFTP, NETRJS_1, NETRJS_2, NETRJS_3, NETRJS_4,
-            FINGER, HOSTS2_NS, SU_MIT_TG, MIT_DOV, DCP, SUPDUP, SWIFT_RVF, TACNEWS, METAGRAM, HOSTNAME, ISO_TSAP, X400,
-            X400_SND, CSNET_NS, RTELNET, POP_2, SUNRPC, AUTH, SFTP, UUCP_PATH, NNTP, ERPC, NTP, LOCUS_MAP, LOCUS_CON,
-            PWDGEN, CISCO_FNA, CISCO_TNA, CISCO_SYS, STATSRV, INGRES_NET, LOC_SRV, PROFILE, NETBIOS_NS, NETBIOS_DGM,
-            NETBIOS_SSN, EMFIS_DATA, EMFIS_CNTL, BL_IDM, SUR_MEAS, LINK };
-
-    public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
-
-    private final String name;
-    private final int ordinal;
-
-
-    /**
-     * Private constructor prevents construction outside of this class.
-     */
-    private ServiceType(int ordinal, String name)
-    {
-        this.ordinal = ordinal;
-        this.name = name;
-    }
+    /** Null */
+    NULL(0),
 
+    /** Remote job entry */
+    RJE(5),
 
-    public String toString()
-    {
-        return name;
-    }
+    /** Echo */
+    ECHO(7),
+
+    /** Discard */
+    DISCARD(9),
+
+    /** Active users */
+    USERS(11),
+
+    /** Daytime */
+    DAYTIME(13),
+
+    /** Quote of the day */
+    QUOTE(17),
+
+    /** Character generator */
+    CHARGEN(19),
+
+    /** File Transfer [Default Data] */
+    FTP_DATA(20),
+
+    /** File Transfer [Control] */
+    FTP(21),
+
+    /** Telnet */
+    TELNET(23),
+
+    /** Simple Mail Transfer */
+    SMTP(25),
+
+    /** NSW User System FE */
+    NSW_FE(27),
+
+    /** MSG ICP */
+    MSG_ICP(29),
+
+    /** MSG Authentication */
+    MSG_AUTH(31),
+
+    /** Display Support Protocol */
+    DSP(33),
+
+    /** Time */
+    TIME(37),
+
+    /** Resource Location Protocol */
+    RLP(39),
+
+    /** Graphics */
+    GRAPHICS(41),
+
+    /** Host Name Server */
+    NAMESERVER(42),
+
+    /** Who Is */
+    NICKNAME(43),
+
+    /** MPM FLAGS Protocol */
+    MPM_FLAGS(44),
+
+    /** Message Processing Module [recv] */
+    MPM(45),
+
+    /** MPM [default send] */
+    MPM_SND(46),
+
+    /** NI FTP */
+    NI_FTP(47),
+
+    /** Login Host Protocol */
+    LOGIN(49),
+
+    /** IMP Logical Address Maintenance */
+    LA_MAINT(51),
+
+    /** Domain Name Server */
+    DOMAIN(53),
+
+    /** ISI Graphics Language */
+    ISI_GL(55),
+
+    /** NI MAIL */
+    NI_MAIL(61),
+
+    /** VIA Systems - FTP */
+    VIA_FTP(63),
+
+    /** TACACS-Database Service */
+    TACACS_DS(65),
+
+    /** Bootstrap Protocol Server */
+    BOOTPS(67),
+
+    /** Bootstrap Protocol Client */
+    BOOTPC(68),
+
+    /** Trivial File Transfer */
+    TFTP(69),
+
+    /** Remote Job Service */
+    NETRJS_1(71),
+
+    /** Remote Job Service */
+    NETRJS_2(72),
+
+    /** Remote Job Service */
+    NETRJS_3(73),
+
+    /** Remote Job Service */
+    NETRJS_4(74),
+
+    /** Finger */
+    FINGER(79),
+
+    /** HOSTS2 Name Server */
+    HOSTS2_NS(81),
 
+    /** SU/MIT Telnet Gateway */
+    SU_MIT_TG(89),
 
-    public int compareTo( Object that )
+    /** MIT Dover Spooler */
+    MIT_DOV(91),
+
+    /** Device Control Protocol */
+    DCP(93),
+
+    /** SUPDUP */
+    SUPDUP(95),
+
+    /** Swift Remote Virtual File Protocol */
+    SWIFT_RVF(97),
+
+    /** TAC News */
+    TACNEWS(98),
+
+    /** Metagram Relay */
+    METAGRAM(99),
+
+    /** NIC Host Name Server */
+    HOSTNAME(101),
+
+    /** ISO-TSAP */
+    ISO_TSAP(102),
+
+    /** X400 */
+    X400(103),
+
+    /** X400-SND */
+    X400_SND(104),
+
+    /** Mailbox Name Nameserver */
+    CSNET_NS(105),
+
+    /** Remote Telnet Service */
+    RTELNET(107),
+
+    /** Post Office Protocol - Version 2 */
+    POP_2(109),
+
+    /** SUN Remote Procedure Call */
+    SUNRPC(111),
+
+    /** Authentication Service */
+    AUTH(113),
+
+    /** Simple File Transfer Protocol */
+    SFTP(115),
+
+    /** UUCP Path Service */
+    UUCP_PATH(117),
+
+    /** Network News Transfer Protocol */
+    NNTP(119),
+
+    /** HYDRA Expedited Remote Procedure */
+    ERPC(121),
+
+    /** Network Time Protocol */
+    NTP(123),
+
+    /** Locus PC-Interface Net Map Server */
+    LOCUS_MAP(125),
+
+    /** Locus PC-Interface Conn Server */
+    LOCUS_CON(127),
+
+    /** Password Generator Protocol */
+    PWDGEN(129),
+
+    /** CISCO FNATIVE */
+    CISCO_FNA(130),
+
+    /** CISCO TNATIVE */
+    CISCO_TNA(131),
+
+    /** CISCO SYSMAINT */
+    CISCO_SYS(132),
+
+    /** Statistics Service */
+    STATSRV(133),
+
+    /** INGRES-NET Service */
+    INGRES_NET(134),
+
+    /** Location Service */
+    LOC_SRV(135),
+
+    /** PROFILE Naming System */
+    PROFILE(136),
+
+    /** NETBIOS Name Service */
+    NETBIOS_NS(137),
+
+    /** NETBIOS Datagram Service */
+    NETBIOS_DGM(138),
+
+    /** NETBIOS Session Service */
+    NETBIOS_SSN(139),
+
+    /** EMFIS Data Service */
+    EMFIS_DATA(140),
+
+    /** EMFIS Control Service */
+    EMFIS_CNTL(141),
+
+    /** Britton-Lee IDM */
+    BL_IDM(142),
+
+    /** Survey Measurement */
+    SUR_MEAS(243),
+
+    /** LINK */
+    LINK(245);
+
+    private static ReverseEnumMap<Byte, ServiceType> map = new ReverseEnumMap<Byte, ServiceType>( ServiceType.class );
+
+    private final byte value;
+
+
+    private ServiceType( int value )
     {
-        return ordinal - ( ( ServiceType ) that ).ordinal;
+        this.value = ( byte ) value;
     }
 
 
-    public static ServiceType getTypeByOrdinal( int type )
+    public Byte convert()
     {
-        for ( int ii = 0; ii < values.length; ii++ )
-        {
-            if ( values[ii].ordinal == type )
-            {
-                return values[ii];
-            }
-        }
-
-        return NULL;
+        return this.value;
     }
 
 
-    public int getOrdinal()
+    public static ServiceType convert( byte value )
     {
-        return ordinal;
+        return map.get( value );
     }
 }

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsDecoder.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsDecoder.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsDecoder.java Sun Jan 28 23:45:59 2007
@@ -22,242 +22,22 @@
 
 
 import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.directory.server.dns.io.decoder.Decoder;
-import org.apache.directory.server.dns.messages.DnsMessage;
-import org.apache.directory.server.dns.messages.DnsMessageModifier;
-import org.apache.directory.server.dns.messages.MessageType;
-import org.apache.directory.server.dns.messages.OpCode;
-import org.apache.directory.server.dns.messages.QuestionRecord;
-import org.apache.directory.server.dns.messages.QuestionRecords;
-import org.apache.directory.server.dns.messages.RecordClass;
-import org.apache.directory.server.dns.messages.RecordType;
-import org.apache.directory.server.dns.messages.ResourceRecordImpl;
-import org.apache.directory.server.dns.messages.ResourceRecords;
-import org.apache.directory.server.dns.messages.ResponseCode;
+
+import org.apache.directory.server.dns.io.decoder.DnsMessageDecoder;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.filter.codec.ProtocolDecoder;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 public class DnsDecoder implements ProtocolDecoder
 {
-    /** the log for this class */
-    private static final Logger log = LoggerFactory.getLogger( DnsDecoder.class );
-
-    /**
-     * A Hashed Adapter mapping record types to their encoders.
-     */
-    private static final Map DEFAULT_DECODERS;
-
-    static
-    {
-        Map map = new HashMap();
-
-        // map.put( RecordType.SOA, new StartOfAuthorityRecordEncoder() );
-
-        DEFAULT_DECODERS = Collections.unmodifiableMap( map );
-    }
-
-
-    public void decode( IoSession session, ByteBuffer in, ProtocolDecoderOutput out )
-    {
-        out.write( decode( in ) );
-    }
-
-
-    DnsMessage decode( ByteBuffer in )
-    {
-        DnsMessageModifier modifier = new DnsMessageModifier();
-
-        modifier.setTransactionId( in.getShort() );
-
-        byte header = in.get();
-        modifier.setMessageType( decodeMessageType( header ) );
-        modifier.setOpCode( decodeOpCode( header ) );
-        modifier.setAuthoritativeAnswer( decodeAuthoritativeAnswer( header ) );
-        modifier.setTruncated( decodeTruncated( header ) );
-        modifier.setRecursionDesired( decodeRecursionDesired( header ) );
-
-        header = in.get();
-        modifier.setRecursionAvailable( decodeRecursionAvailable( header ) );
-        modifier.setResponseCode( decodeResponseCode( header ) );
-
-        short questionCount = in.getShort();
-        short answerCount = in.getShort();
-        short authorityCount = in.getShort();
-        short additionalCount = in.getShort();
-
-        modifier.setQuestionRecords( decodeQuestions( questionCount, in ) );
-        modifier.setAnswerRecords( decodeRecords( answerCount, in ) );
-        modifier.setAuthorityRecords( decodeRecords( authorityCount, in ) );
-        modifier.setAdditionalRecords( decodeRecords( additionalCount, in ) );
-
-        return modifier.getDnsMessage();
-    }
-
-
-    private ResourceRecords decodeRecords( short recordCount, ByteBuffer byteBuffer )
-    {
-        ResourceRecords records = new ResourceRecords( recordCount );
-
-        for ( int ii = 0; ii < recordCount; ii++ )
-        {
-            String domainName = decodeDomainName( byteBuffer );
-
-            RecordType recordType = RecordType.getTypeByOrdinal( byteBuffer.getShort() );
-            RecordClass recordClass = RecordClass.getTypeByOrdinal( byteBuffer.getShort() );
-
-            int timeToLive = byteBuffer.getInt();
-            short dataLength = byteBuffer.getShort();
-
-            byte[] data = new byte[dataLength];
-            byteBuffer.get( data );
-
-            try
-            {
-                Map attributes = decode( recordType, data );
-                records.add( new ResourceRecordImpl( domainName, recordType, recordClass, timeToLive, attributes ) );
-            }
-            catch ( IOException ioe )
-            {
-                log.error( ioe.getMessage(), ioe );
-            }
-        }
-
-        return records;
-    }
-
-
-    private Map decode( RecordType type, byte[] resourceData ) throws IOException
-    {
-        Decoder decoder = ( Decoder ) DEFAULT_DECODERS.get( type );
-
-        if ( decoder == null )
-        {
-            throw new IOException( "Decoder unavailable for " + type );
-        }
-
-        return decoder.decode( resourceData );
-    }
-
-
-    private QuestionRecords decodeQuestions( short questionCount, ByteBuffer byteBuffer )
-    {
-        QuestionRecords questions = new QuestionRecords( questionCount );
-
-        for ( int ii = 0; ii < questionCount; ii++ )
-        {
-            String domainName = decodeDomainName( byteBuffer );
-
-            RecordType recordType = RecordType.getTypeByOrdinal( byteBuffer.getShort() );
-            RecordClass recordClass = RecordClass.getTypeByOrdinal( byteBuffer.getShort() );
-
-            questions.add( new QuestionRecord( domainName, recordType, recordClass ) );
-        }
-
-        return questions;
-    }
-
-
-    private String decodeDomainName( ByteBuffer byteBuffer )
-    {
-        StringBuffer domainName = new StringBuffer();
-        recurseDomainName( domainName, byteBuffer );
-
-        return domainName.toString();
-    }
-
-
-    private void recurseDomainName( StringBuffer domainName, ByteBuffer byteBuffer )
-    {
-        byte currentByte = byteBuffer.get();
-
-        boolean isCompressed = ( ( currentByte & ( byte ) 0xc0 ) == ( byte ) 0xc0 );
-        boolean isLabelLength = ( ( currentByte != 0 ) && !isCompressed );
-
-        if ( isCompressed )
-        {
-            int position = byteBuffer.get();
-            int originalPosition = byteBuffer.position();
-            byteBuffer.position( position );
-
-            int labelLength = byteBuffer.get();
-            getLabel( labelLength, byteBuffer, domainName );
-            recurseDomainName( domainName, byteBuffer );
-
-            byteBuffer.position( originalPosition );
-        }
-
-        if ( isLabelLength )
-        {
-            int labelLength = currentByte;
-            getLabel( labelLength, byteBuffer, domainName );
-            recurseDomainName( domainName, byteBuffer );
-        }
-    }
-
-
-    private void getLabel( int labelLength, ByteBuffer byteBuffer, StringBuffer domainName )
-    {
-        for ( int jj = 0; jj < labelLength; jj++ )
-        {
-            char character = ( char ) byteBuffer.get();
-            domainName.append( character );
-        }
-
-        if ( byteBuffer.get( byteBuffer.position() ) != 0 )
-        {
-            domainName.append( "." );
-        }
-    }
-
-
-    private MessageType decodeMessageType( byte header )
-    {
-        return MessageType.getTypeByOrdinal( ( header & 0x80 ) >>> 7 );
-    }
-
-
-    private OpCode decodeOpCode( byte header )
-    {
-        return OpCode.getTypeByOrdinal( ( header & 0x78 ) >>> 3 );
-    }
-
-
-    private boolean decodeAuthoritativeAnswer( byte header )
-    {
-        return ( ( header & 0x04 ) >>> 2 ) == 1;
-    }
-
-
-    private boolean decodeTruncated( byte header )
-    {
-        return ( ( header & 0x02 ) >>> 1 ) == 1;
-    }
-
-
-    private boolean decodeRecursionDesired( byte header )
-    {
-        return ( ( header & 0x01 ) ) == 1;
-    }
-
-
-    private boolean decodeRecursionAvailable( byte header )
-    {
-        return ( ( header & 0x80 ) >>> 7 ) == 1;
-    }
+    private DnsMessageDecoder decoder = new DnsMessageDecoder();
 
 
-    private ResponseCode decodeResponseCode( byte header )
+    public void decode( IoSession session, ByteBuffer in, ProtocolDecoderOutput out ) throws IOException
     {
-        return ResponseCode.getTypeByOrdinal( header & 0x0F );
+        out.write( decoder.decode( in.buf() ) );
     }
 
 
@@ -268,6 +48,5 @@
 
     public void finishDecode( IoSession session, ProtocolDecoderOutput out ) throws Exception
     {
-        // TODO Auto-generated method stub
     }
 }

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsEncoder.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsEncoder.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsEncoder.java Sun Jan 28 23:45:59 2007
@@ -21,213 +21,27 @@
 package org.apache.directory.server.dns.protocol;
 
 
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.directory.server.dns.io.encoder.AddressRecordEncoder;
-import org.apache.directory.server.dns.io.encoder.CanonicalNameRecordEncoder;
-import org.apache.directory.server.dns.io.encoder.MailExchangeRecordEncoder;
-import org.apache.directory.server.dns.io.encoder.NameServerRecordEncoder;
-import org.apache.directory.server.dns.io.encoder.PointerRecordEncoder;
-import org.apache.directory.server.dns.io.encoder.QuestionRecordEncoder;
-import org.apache.directory.server.dns.io.encoder.RecordEncoder;
-import org.apache.directory.server.dns.io.encoder.ServerSelectionRecordEncoder;
-import org.apache.directory.server.dns.io.encoder.StartOfAuthorityRecordEncoder;
-import org.apache.directory.server.dns.io.encoder.TextRecordEncoder;
+import org.apache.directory.server.dns.io.encoder.DnsMessageEncoder;
 import org.apache.directory.server.dns.messages.DnsMessage;
-import org.apache.directory.server.dns.messages.MessageType;
-import org.apache.directory.server.dns.messages.OpCode;
-import org.apache.directory.server.dns.messages.QuestionRecord;
-import org.apache.directory.server.dns.messages.QuestionRecords;
-import org.apache.directory.server.dns.messages.RecordType;
-import org.apache.directory.server.dns.messages.ResourceRecord;
-import org.apache.directory.server.dns.messages.ResourceRecords;
-import org.apache.directory.server.dns.messages.ResponseCode;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.filter.codec.ProtocolEncoder;
 import org.apache.mina.filter.codec.ProtocolEncoderOutput;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 public class DnsEncoder implements ProtocolEncoder
 {
-    /** the log for this class */
-    private static final Logger log = LoggerFactory.getLogger( DnsEncoder.class );
-
-    /**
-     * A Hashed Adapter mapping record types to their encoders.
-     */
-    private static final Map DEFAULT_ENCODERS;
-
-    static
-    {
-        Map<RecordType, RecordEncoder> map = new HashMap<RecordType, RecordEncoder>();
-
-        map.put( RecordType.SOA, new StartOfAuthorityRecordEncoder() );
-        map.put( RecordType.A, new AddressRecordEncoder() );
-        map.put( RecordType.NS, new NameServerRecordEncoder() );
-        map.put( RecordType.CNAME, new CanonicalNameRecordEncoder() );
-        map.put( RecordType.PTR, new PointerRecordEncoder() );
-        map.put( RecordType.MX, new MailExchangeRecordEncoder() );
-        map.put( RecordType.SRV, new ServerSelectionRecordEncoder() );
-        map.put( RecordType.TXT, new TextRecordEncoder() );
-
-        DEFAULT_ENCODERS = Collections.unmodifiableMap( map );
-    }
+    private DnsMessageEncoder encoder = new DnsMessageEncoder();
 
 
     public void encode( IoSession session, Object message, ProtocolEncoderOutput out )
     {
         ByteBuffer buf = ByteBuffer.allocate( 1024 );
-        encode( buf, ( DnsMessage ) message );
+        encoder.encode( buf.buf(), ( DnsMessage ) message );
 
         buf.flip();
 
         out.write( buf );
-    }
-
-
-    public void encode( ByteBuffer byteBuffer, DnsMessage message )
-    {
-        byteBuffer.putShort( message.getTransactionId() );
-
-        byte header = ( byte ) 0x00;
-        header = encodeMessageType( message.getMessageType(), header );
-        header = encodeOpCode( message.getOpCode(), header );
-        header = encodeAuthoritativeAnswer( message.isAuthoritativeAnswer(), header );
-        header = encodeTruncated( message.isTruncated(), header );
-        header = encodeRecursionDesired( message.isRecursionDesired(), header );
-        byteBuffer.put( header );
-
-        header = ( byte ) 0x00;
-        header = encodeRecursionAvailable( message.isRecursionAvailable(), header );
-        header = encodeResponseCode( message.getResponseCode(), header );
-        byteBuffer.put( header );
-
-        byteBuffer.putShort( ( short ) message.getQuestionRecords().size() );
-        byteBuffer.putShort( ( short ) message.getAnswerRecords().size() );
-        byteBuffer.putShort( ( short ) message.getAuthorityRecords().size() );
-        byteBuffer.putShort( ( short ) message.getAdditionalRecords().size() );
-
-        encodeRecords( message.getQuestionRecords(), byteBuffer );
-        encodeRecords( message.getAnswerRecords(), byteBuffer );
-        encodeRecords( message.getAuthorityRecords(), byteBuffer );
-        encodeRecords( message.getAdditionalRecords(), byteBuffer );
-    }
-
-
-    private void encodeRecords( QuestionRecords questions, ByteBuffer byteBuffer )
-    {
-        QuestionRecordEncoder encoder = new QuestionRecordEncoder();
-
-        Iterator it = questions.iterator();
-
-        while ( it.hasNext() )
-        {
-            QuestionRecord question = ( QuestionRecord ) it.next();
-            encoder.encode( byteBuffer, question );
-        }
-    }
-
-
-    private void encodeRecords( ResourceRecords records, ByteBuffer byteBuffer )
-    {
-        Iterator it = records.iterator();
-
-        while ( it.hasNext() )
-        {
-            ResourceRecord record = ( ResourceRecord ) it.next();
-
-            try
-            {
-                encode( byteBuffer, record );
-            }
-            catch ( IOException ioe )
-            {
-                log.error( ioe.getMessage(), ioe );
-            }
-        }
-    }
-
-
-    private void encode( ByteBuffer out, ResourceRecord record ) throws IOException
-    {
-        RecordType type = record.getRecordType();
-
-        RecordEncoder encoder = ( RecordEncoder ) DEFAULT_ENCODERS.get( type );
-
-        if ( encoder == null )
-        {
-            throw new IOException( "Encoder unavailable for " + type );
-        }
-
-        encoder.encode( out, record );
-    }
-
-
-    private byte encodeMessageType( MessageType messageType, byte header )
-    {
-        byte oneBit = ( byte ) ( messageType.getOrdinal() & 0x01 );
-        return ( byte ) ( ( oneBit << 7 ) | header );
-    }
-
-
-    private byte encodeOpCode( OpCode opCode, byte header )
-    {
-        byte fourBits = ( byte ) ( opCode.getOrdinal() & 0x0F );
-        return ( byte ) ( ( fourBits << 3 ) | header );
-    }
-
-
-    private byte encodeAuthoritativeAnswer( boolean authoritative, byte header )
-    {
-        if ( authoritative )
-        {
-            header = ( byte ) ( ( ( byte ) 0x01 << 2 ) | header );
-        }
-        return header;
-    }
-
-
-    private byte encodeTruncated( boolean truncated, byte header )
-    {
-        if ( truncated )
-        {
-            header = ( byte ) ( ( ( byte ) 0x01 << 1 ) | header );
-        }
-        return header;
-    }
-
-
-    private byte encodeRecursionDesired( boolean recursionDesired, byte header )
-    {
-        if ( recursionDesired )
-        {
-            header = ( byte ) ( ( ( byte ) 0x01 ) | header );
-        }
-        return header;
-    }
-
-
-    private byte encodeRecursionAvailable( boolean recursionAvailable, byte header )
-    {
-        if ( recursionAvailable )
-        {
-            header = ( byte ) ( ( ( byte ) 0x01 << 7 ) | header );
-        }
-        return header;
-    }
-
-
-    private byte encodeResponseCode( ResponseCode responseCode, byte header )
-    {
-        byte fourBits = ( byte ) ( responseCode.getOrdinal() & 0x0F );
-        return ( byte ) ( fourBits | header );
     }
 
 

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java Sun Jan 28 23:45:59 2007
@@ -21,13 +21,15 @@
 package org.apache.directory.server.dns.protocol;
 
 
+import java.util.ArrayList;
+
 import org.apache.directory.server.dns.DnsConfiguration;
 import org.apache.directory.server.dns.DnsException;
 import org.apache.directory.server.dns.messages.DnsMessage;
 import org.apache.directory.server.dns.messages.DnsMessageModifier;
 import org.apache.directory.server.dns.messages.MessageType;
 import org.apache.directory.server.dns.messages.OpCode;
-import org.apache.directory.server.dns.messages.ResourceRecords;
+import org.apache.directory.server.dns.messages.ResourceRecord;
 import org.apache.directory.server.dns.messages.ResponseCode;
 import org.apache.directory.server.dns.service.DnsContext;
 import org.apache.directory.server.dns.service.DomainNameServiceChain;
@@ -51,7 +53,7 @@
     private String contextKey = "context";
 
 
-    public DnsProtocolHandler(DnsConfiguration config, RecordStore store)
+    public DnsProtocolHandler( DnsConfiguration config, RecordStore store )
     {
         this.config = config;
         this.store = store;
@@ -114,8 +116,8 @@
         {
             log.error( e.getMessage(), e );
 
-            DnsMessage request = (DnsMessage) message;
-            DnsException de = (DnsException) e;
+            DnsMessage request = ( DnsMessage ) message;
+            DnsException de = ( DnsException ) e;
 
             DnsMessageModifier modifier = new DnsMessageModifier();
 
@@ -128,11 +130,11 @@
             modifier.setRecursionAvailable( false );
             modifier.setReserved( false );
             modifier.setAcceptNonAuthenticatedData( false );
-            modifier.setResponseCode( ResponseCode.getTypeByOrdinal( de.getResponseCode() ) );
+            modifier.setResponseCode( ResponseCode.convert( ( byte ) de.getResponseCode() ) );
             modifier.setQuestionRecords( request.getQuestionRecords() );
-            modifier.setAnswerRecords( new ResourceRecords() );
-            modifier.setAuthorityRecords( new ResourceRecords() );
-            modifier.setAdditionalRecords( new ResourceRecords() );
+            modifier.setAnswerRecords( new ArrayList<ResourceRecord>() );
+            modifier.setAuthorityRecords( new ArrayList<ResourceRecord>() );
+            modifier.setAdditionalRecords( new ArrayList<ResourceRecord>() );
 
             session.write( modifier.getDnsMessage() );
         }

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/BuildReply.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/BuildReply.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/BuildReply.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/BuildReply.java Sun Jan 28 23:45:59 2007
@@ -20,11 +20,14 @@
 package org.apache.directory.server.dns.service;
 
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.directory.server.dns.messages.DnsMessage;
 import org.apache.directory.server.dns.messages.DnsMessageModifier;
 import org.apache.directory.server.dns.messages.MessageType;
 import org.apache.directory.server.dns.messages.OpCode;
-import org.apache.directory.server.dns.messages.ResourceRecords;
+import org.apache.directory.server.dns.messages.ResourceRecord;
 import org.apache.directory.server.dns.messages.ResponseCode;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.handler.chain.IoHandlerCommand;
@@ -34,11 +37,12 @@
 {
     private String contextKey = "context";
 
+
     public void execute( NextCommand next, IoSession session, Object message ) throws Exception
     {
-        DnsContext dnsContext = (DnsContext) session.getAttribute( getContextKey() );
-        ResourceRecords records = dnsContext.getResourceRecords();
-        DnsMessage request = (DnsMessage) message;
+        DnsContext dnsContext = ( DnsContext ) session.getAttribute( getContextKey() );
+        List<ResourceRecord> records = dnsContext.getResourceRecords();
+        DnsMessage request = ( DnsMessage ) message;
 
         DnsMessageModifier modifier = new DnsMessageModifier();
 
@@ -55,13 +59,14 @@
         modifier.setQuestionRecords( request.getQuestionRecords() );
 
         modifier.setAnswerRecords( records );
-        modifier.setAuthorityRecords( new ResourceRecords() );
-        modifier.setAdditionalRecords( new ResourceRecords() );
+        modifier.setAuthorityRecords( new ArrayList<ResourceRecord>() );
+        modifier.setAdditionalRecords( new ArrayList<ResourceRecord>() );
 
         dnsContext.setReply( modifier.getDnsMessage() );
 
         next.execute( session, message );
     }
+
 
     public String getContextKey()
     {

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DnsContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DnsContext.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DnsContext.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/DnsContext.java Sun Jan 28 23:45:59 2007
@@ -20,12 +20,13 @@
 package org.apache.directory.server.dns.service;
 
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 import org.apache.directory.server.dns.DnsConfiguration;
 import org.apache.directory.server.dns.messages.DnsMessage;
 import org.apache.directory.server.dns.messages.ResourceRecord;
-import org.apache.directory.server.dns.messages.ResourceRecords;
 import org.apache.directory.server.dns.store.RecordStore;
 
 
@@ -36,13 +37,13 @@
     private DnsConfiguration config;
     private RecordStore store;
     private DnsMessage reply;
-    private ResourceRecords records = new ResourceRecords();
+    private List<ResourceRecord> records = new ArrayList<ResourceRecord>();
 
 
     /**
      * @return Returns the recordEntry.
      */
-    public ResourceRecords getResourceRecords()
+    public List<ResourceRecord> getResourceRecords()
     {
         return records;
     }

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/GetResourceRecords.java Sun Jan 28 23:45:59 2007
@@ -21,12 +21,12 @@
 
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.directory.server.dns.DnsException;
 import org.apache.directory.server.dns.messages.DnsMessage;
 import org.apache.directory.server.dns.messages.QuestionRecord;
-import org.apache.directory.server.dns.messages.QuestionRecords;
 import org.apache.directory.server.dns.messages.ResponseCode;
 import org.apache.directory.server.dns.store.RecordStore;
 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
@@ -43,13 +43,14 @@
 
     private String contextKey = "context";
 
+
     public void execute( NextCommand next, IoSession session, Object message ) throws Exception
     {
-        DnsContext dnsContext = (DnsContext) session.getAttribute( getContextKey() );
+        DnsContext dnsContext = ( DnsContext ) session.getAttribute( getContextKey() );
         RecordStore store = dnsContext.getStore();
 
-        DnsMessage request = (DnsMessage) message;
-        QuestionRecords questions = request.getQuestionRecords();
+        DnsMessage request = ( DnsMessage ) message;
+        List<QuestionRecord> questions = request.getQuestionRecords();
 
         Iterator it = questions.iterator();
 
@@ -92,6 +93,7 @@
 
         return records;
     }
+
 
     public String getContextKey()
     {

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorContext.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorContext.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorContext.java Sun Jan 28 23:45:59 2007
@@ -20,7 +20,9 @@
 package org.apache.directory.server.dns.service;
 
 
-import org.apache.directory.server.dns.messages.ResourceRecords;
+import java.util.List;
+
+import org.apache.directory.server.dns.messages.ResourceRecord;
 import org.apache.directory.server.dns.store.RecordStore;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.handler.chain.IoHandlerCommand;
@@ -35,15 +37,16 @@
 
     private String contextKey = "context";
 
+
     public void execute( NextCommand next, IoSession session, Object message ) throws Exception
     {
         if ( log.isDebugEnabled() )
         {
             try
             {
-                DnsContext dnsContext = (DnsContext) session.getAttribute( getContextKey() );
+                DnsContext dnsContext = ( DnsContext ) session.getAttribute( getContextKey() );
                 RecordStore store = dnsContext.getStore();
-                ResourceRecords records = dnsContext.getResourceRecords();
+                List<ResourceRecord> records = dnsContext.getResourceRecords();
 
                 StringBuffer sb = new StringBuffer();
                 sb.append( "Monitoring context:" );
@@ -61,6 +64,7 @@
 
         next.execute( session, message );
     }
+
 
     public String getContextKey()
     {

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorMessage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorMessage.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorMessage.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/service/MonitorMessage.java Sun Jan 28 23:45:59 2007
@@ -20,10 +20,12 @@
 package org.apache.directory.server.dns.service;
 
 
+import java.util.List;
+
 import org.apache.directory.server.dns.messages.DnsMessage;
 import org.apache.directory.server.dns.messages.MessageType;
 import org.apache.directory.server.dns.messages.OpCode;
-import org.apache.directory.server.dns.messages.QuestionRecords;
+import org.apache.directory.server.dns.messages.QuestionRecord;
 import org.apache.directory.server.dns.messages.ResponseCode;
 import org.apache.mina.handler.chain.IoHandlerCommand;
 
@@ -35,7 +37,7 @@
         MessageType messageType = message.getMessageType();
         OpCode opCode = message.getOpCode();
         ResponseCode responseCode = message.getResponseCode();
-        short transactionId = message.getTransactionId();
+        int transactionId = message.getTransactionId();
 
         StringBuffer sb = new StringBuffer();
         sb.append( "Monitoring " + direction + ":" );
@@ -51,7 +53,7 @@
         sb.append( "\n\t" + "reserved                   " + message.isReserved() );
         sb.append( "\n\t" + "acceptNonAuthenticatedData " + message.isAcceptNonAuthenticatedData() );
 
-        QuestionRecords questions = message.getQuestionRecords();
+        List<QuestionRecord> questions = message.getQuestionRecords();
 
         sb.append( "\n\t" + "questions:                 " + questions );
 

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/GetFlatRecord.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/GetFlatRecord.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/GetFlatRecord.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/GetFlatRecord.java Sun Jan 28 23:45:59 2007
@@ -56,7 +56,7 @@
     /**
      * Creates the action to be used against the embedded JNDI provider.
      */
-    public GetFlatRecord(QuestionRecord question)
+    public GetFlatRecord( QuestionRecord question )
     {
         this.question = question;
     }
@@ -76,8 +76,8 @@
         Attributes matchAttrs = new AttributesImpl( true );
 
         matchAttrs.put( new AttributeImpl( DnsAttribute.NAME, question.getDomainName() ) );
-        matchAttrs.put( new AttributeImpl( DnsAttribute.TYPE, question.getRecordType().getCode() ) );
-        matchAttrs.put( new AttributeImpl( DnsAttribute.CLASS, question.getRecordClass().getCode() ) );
+        matchAttrs.put( new AttributeImpl( DnsAttribute.TYPE, question.getRecordType().name() ) );
+        matchAttrs.put( new AttributeImpl( DnsAttribute.CLASS, question.getRecordClass().name() ) );
 
         ResourceRecord record = null;
 
@@ -120,8 +120,8 @@
         String dnsTtl = ( attr = attrs.get( DnsAttribute.TTL ) ) != null ? ( String ) attr.get() : null;
 
         modifier.setDnsName( dnsName );
-        modifier.setDnsType( RecordType.getTypeByName( dnsType ) );
-        modifier.setDnsClass( RecordClass.getTypeByName( dnsClass ) );
+        modifier.setDnsType( RecordType.valueOf( dnsType ) );
+        modifier.setDnsClass( RecordClass.valueOf( dnsClass ) );
         modifier.setDnsTtl( Integer.parseInt( dnsTtl ) );
 
         NamingEnumeration ids = attrs.getIDs();

Modified: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/GetRecords.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/GetRecords.java?view=diff&rev=500956&r1=500955&r2=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/GetRecords.java (original)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/store/operations/GetRecords.java Sun Jan 28 23:45:59 2007
@@ -64,7 +64,7 @@
     /**
      * Creates the action to be used against the embedded JNDI provider.
      */
-    public GetRecords(QuestionRecord question)
+    public GetRecords( QuestionRecord question )
     {
         this.question = question;
     }
@@ -184,7 +184,7 @@
 
         if ( attr != null )
         {
-            modifier.setDnsType( RecordType.getTypeByName( ( String ) attr.get() ) );
+            modifier.setDnsType( RecordType.valueOf( ( String ) attr.get() ) );
         }
         else
         {
@@ -193,7 +193,7 @@
 
         // class defaults to SOA CLASS
         String dnsClass = ( attr = attrs.get( DnsAttribute.CLASS ) ) != null ? ( String ) attr.get() : SOA_CLASS;
-        modifier.setDnsClass( RecordClass.getTypeByName( dnsClass ) );
+        modifier.setDnsClass( RecordClass.valueOf( dnsClass ) );
 
         // ttl defaults to SOA MINIMUM
         String dnsTtl = ( attr = attrs.get( DnsAttribute.TTL ) ) != null ? ( String ) attr.get() : SOA_MINIMUM;

Added: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/ByteBufferUtil.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/ByteBufferUtil.java?view=auto&rev=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/ByteBufferUtil.java (added)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/ByteBufferUtil.java Sun Jan 28 23:45:59 2007
@@ -0,0 +1,105 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.server.dns.util;
+
+
+import java.nio.ByteBuffer;
+
+
+public class ByteBufferUtil
+{
+
+    private ByteBufferUtil()
+    {
+    }
+
+
+    public static short getUnsignedByte( ByteBuffer byteBuffer )
+    {
+        return ( ( short ) ( byteBuffer.get() & 0xff ) );
+    }
+
+
+    public static short getUnsignedByte( ByteBuffer byteBuffer, int position )
+    {
+        return ( ( short ) ( byteBuffer.get( position ) & ( short ) 0xff ) );
+    }
+
+
+    public static int getUnsignedShort( ByteBuffer byteBuffer )
+    {
+        return ( byteBuffer.getShort() & 0xffff );
+    }
+
+
+    public static int getUnsignedShort( ByteBuffer byteBuffer, int position )
+    {
+        return ( byteBuffer.getShort( position ) & 0xffff );
+    }
+
+
+    public static long getUnsignedInt( ByteBuffer byteBuffer )
+    {
+        return ( byteBuffer.getInt() & 0xffffffffL );
+    }
+
+
+    public static long getUnsignedInt( ByteBuffer byteBuffer, int position )
+    {
+        return ( byteBuffer.getInt( position ) & 0xffffffffL );
+    }
+
+
+    public static void putUnsignedByte( ByteBuffer byteBuffer, int value )
+    {
+        byteBuffer.put( ( byte ) ( value & 0xff ) );
+    }
+
+
+    public static void putUnsignedByte( ByteBuffer byteBuffer, int position, int value )
+    {
+        byteBuffer.put( position, ( byte ) ( value & 0xff ) );
+    }
+
+
+    public static void putUnsignedShort( ByteBuffer byteBuffer, int value )
+    {
+        byteBuffer.putShort( ( short ) ( value & 0xffff ) );
+    }
+
+
+    public static void putUnsignedShort( ByteBuffer byteBuffer, int position, int value )
+    {
+        byteBuffer.putShort( position, ( short ) ( value & 0xffff ) );
+    }
+
+
+    public static void putUnsignedInt( ByteBuffer byteBuffer, long value )
+    {
+        byteBuffer.putInt( ( int ) ( value & 0xffffffffL ) );
+    }
+
+
+    public static void putUnsignedInt( ByteBuffer byteBuffer, int position, long value )
+    {
+        byteBuffer.putInt( position, ( int ) ( value & 0xffffffffL ) );
+    }
+}

Propchange: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/ByteBufferUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/EnumConverter.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/EnumConverter.java?view=auto&rev=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/EnumConverter.java (added)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/EnumConverter.java Sun Jan 28 23:45:59 2007
@@ -0,0 +1,27 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.server.dns.util;
+
+
+public interface EnumConverter<K>
+{
+    K convert();
+}

Propchange: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/EnumConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/ReverseEnumMap.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/ReverseEnumMap.java?view=auto&rev=500956
==============================================================================
--- directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/ReverseEnumMap.java (added)
+++ directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/ReverseEnumMap.java Sun Jan 28 23:45:59 2007
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.server.dns.util;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * A map to easily get the actual Enum instance from it's value as seen in the
+ * <a href="http://www.javaspecialists.co.za/archive/newsletter.do?issue=113">
+ * The JavaSpecialists newsletter</a>.
+ */
+public class ReverseEnumMap<K, E extends Enum<E> & EnumConverter<K>>
+{
+    private Map<K, E> reverseMap = new HashMap<K, E>();
+
+
+    public ReverseEnumMap( Class<E> enumType )
+    {
+        for ( E e : enumType.getEnumConstants() )
+        {
+            reverseMap.put( e.convert(), e );
+        }
+    }
+
+
+    public E get( K value )
+    {
+        E e = reverseMap.get( value );
+        if ( e == null )
+        {
+            throw new IllegalArgumentException( "Invalid enum value: " + value );
+        }
+        return e;
+    }
+}

Propchange: directory/apacheds/trunk/protocol-dns/src/main/java/org/apache/directory/server/dns/util/ReverseEnumMap.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message