harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r410240 [2/4] - in /incubator/harmony/enhanced/classlib/trunk/modules/jndi: make/ make/common/ src/main/java/org/apache/harmony/jndi/provider/ src/main/java/org/apache/harmony/jndi/provider/dns/ src/main/java/org/apache/harmony/util/ src/ma...
Date Tue, 30 May 2006 11:25:01 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSContextFactory.java?rev=410240&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSContextFactory.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSContextFactory.java Tue May 30 04:24:59 2006
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Alexei Y. Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+
+package org.apache.harmony.jndi.provider.dns;
+
+import java.util.Hashtable;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+/**
+ * A factory to build DNS contexts.
+ * @author Alexei Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+public class DNSContextFactory implements InitialContextFactory {
+
+    /**
+     * Empty constructor.
+     */
+    public DNSContextFactory() {}
+
+    /**
+     * Creates a new instance of DNS context.
+     * 
+     * @param env an environment to be used
+     * @return new instance of <code>DNSContext</code>
+     * @see javax.naming.spi.InitialContextFactory#getInitialContext(java.util.Hashtable)
+     */
+    public Context getInitialContext(Hashtable env) throws NamingException {
+        return new DNSContext(env);
+    }
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSContextFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSName.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSName.java?rev=410240&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSName.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSName.java Tue May 30 04:24:59 2006
@@ -0,0 +1,411 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Alexei Y. Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+
+package org.apache.harmony.jndi.provider.dns;
+
+import java.util.Enumeration;
+import java.util.Vector;
+import java.util.logging.Level;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+
+
+/**
+ * Represents the name in Domain Name System. The most significant part is the
+ * rightmost part of string representation.
+ * 
+ * @author Alexei Zakharov
+ * @version $Revision: 1.1.2.4 $
+ * TODO add escapes checking for name components (?)
+ */
+public class DNSName implements Name, Cloneable {
+
+    private static final long serialVersionUID = -5931312723719884197L;
+    
+    Vector components = null;
+    
+    /**
+     * Constructs an empty DNS name.
+     */
+    public DNSName() {
+        components = new Vector();
+    }
+
+    /**
+     * Constructs new DNS name with given components.
+     * 
+     * @param compVect the vector of name components
+     */
+    DNSName(Vector compVect) {
+        components = compVect;
+    }
+
+    /**
+     * @return size of this name
+     * @see javax.naming.Name#size()
+     */
+    public int size() {
+        return components.size();
+    }
+
+    /**
+     * @return <code>true</code> if this name is empty
+     * @see javax.naming.Name#isEmpty()
+     */
+    public boolean isEmpty() {
+        return components.isEmpty();
+    }
+
+    /**
+     * @return <code>true</code> if this name is an absolute DNS name,
+     *  i.e. starts with empty label 
+     */
+    public boolean isAbsolute() {
+        if (components.size() > 0) {
+            String el0 = (String) components.get(0);
+
+            if (el0 != null && el0.length() == 0) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns clone of the current name.
+     * @see java.lang.Object#clone()
+     */
+    public Object clone() {
+        Vector compClone = new Vector();
+        Enumeration compEnum = this.components.elements();
+
+        while (compEnum.hasMoreElements()) {
+            compClone.addElement(compEnum.nextElement());
+        }
+        return new DNSName(compClone);
+    }
+
+    /**
+     * Removes component with specified number.
+     * @param posn index of component to remove
+     * @throws ArrayIndexOutOfBoundsException if <code>posn</code> index is
+     *  out of range 
+     * @see javax.naming.Name#remove(int)
+     */
+    public Object remove(int posn) throws InvalidNameException {
+        return components.remove(posn);
+    }
+
+    /**
+     * Compares the specified name with the current name. It checks all components
+     * beginning at the most significant one. The method
+     *  <code>compareToIgnoreCase</code>
+     * of underlying <code>String</code> object will be used for the real
+     * comparison of components.
+     * If two names have different sizes and the longer name begins with
+     * the shorter name then the longer name will be "bigger" than shorter.
+     * @param name the name to compare with
+     * @return negative number; zero or positive number
+     * @throws ClassCastException if the <code>name</code> has class other than
+     * <code>DNSName</code>
+     * @throws NullPointerException if the <code>name</code> is null
+     * @see javax.naming.Name#compareTo(java.lang.Object)
+     * @see java.lang.String#compareToIgnoreCase(java.lang.String)
+     */
+    public int compareTo(Object name) {
+        DNSName nameToCompareWith = null;
+        Enumeration enum1;
+        Enumeration enum2;
+
+        if (name == null) {
+            throw new NullPointerException("The name is null");
+        }
+        if (!(name instanceof DNSName)) {
+            throw new ClassCastException(
+                    "Given name is not an instance of DNSName class");
+        }
+        nameToCompareWith = (DNSName) name;
+        enum1 = this.getAll();
+        enum2 = nameToCompareWith.getAll();
+        while (enum1.hasMoreElements()) {
+            String comp1 = (String) enum1.nextElement();
+            String comp2;
+            int k;
+
+            if (!enum2.hasMoreElements()) {
+                return 1;
+            }
+            comp2 = (String) enum2.nextElement();
+            k = comp1.compareToIgnoreCase(comp2);
+            if (k != 0) {
+                return k;
+            }
+        }
+        if (enum2.hasMoreElements()) {
+            return -1;
+        }
+        return 0;
+    }
+
+    /**
+     * @param posn index of the component to return
+     * @return name component at index <code>posn</code> 
+     * @throws ArrayIndexOutOfBoundsException if <code>posn</code> index is
+     *  out of range 
+     * @see javax.naming.Name#get(int)
+     */
+    public String get(int posn) {
+        return (String) components.elementAt(posn); 
+    }
+
+    /**
+     * Returns all components of the current name.
+     * @return enumeration of strings
+     * @see javax.naming.Name#getAll()
+     */
+    public Enumeration getAll() {
+        return components.elements();
+    }
+
+    /**
+     * @param posn index to stop at
+     * @return a <code>DNSName</code> object that consists of components of the
+     * current name with indexes from <code>0</code> to and not including
+     *  <code>posn</code>.
+     * @throws ArrayIndexOutOfBoundsException if <code>posn</code> index is
+     *  out of range 
+     * @see javax.naming.Name#getPrefix(int)
+     */
+    public Name getPrefix(int posn) {
+        Vector prefix = new Vector();
+
+        for (int i = 0; i < posn; i++) {
+            prefix.addElement(components.elementAt(i));
+        }
+        return new DNSName(prefix);
+    }
+
+    /**
+     * @param posn index to start at
+     * @return a <code>DNSName</code> object that consists of components of the
+     * current name with indexes from <code>posn</code> to and not including
+     *  <code>#size()</code>.
+     * @throws ArrayIndexOutOfBoundsException if <code>posn</code> index is
+     *  out of range 
+     * @see javax.naming.Name#getSuffix(int)
+     */
+    public Name getSuffix(int posn) {
+        Vector prefix = new Vector();
+
+        for (int i = posn; i < components.size(); i++) {
+            prefix.addElement(components.elementAt(i));
+        }
+        return new DNSName(prefix);
+    }
+
+    /**
+     * Checks if the current name ends with the given name. Returns
+     * <code>false</code> if the given name is <code>null</code> or not an
+     * instance of <code>DNSName</code> class.
+     * @param name the name to compare the end of the current message with
+     * @return <code>true</code> or <code>false</code>
+     * @see javax.naming.Name#endsWith(javax.naming.Name)
+     */
+    public boolean endsWith(Name name) {
+        int k = -1;
+        int len1;
+        int len2;
+
+        if (name == null) {
+            return false;
+        }
+        if (!(name instanceof DNSName)) {
+            return false;
+        }
+        len1 = this.size();
+        len2 = name.size();
+        if (len1 == len2) {
+            try {
+                k = this.compareTo(name);
+            } catch (ClassCastException e) {
+                // impossible case
+                ProviderMgr.logger.log(Level.SEVERE, "impossible case", e);
+            }
+        }
+        else if (len1 > len2) {
+            Name suffix = this.getSuffix(len1 - len2);
+
+            k = suffix.compareTo(name);
+        }
+        return (k == 0 ? true : false);
+    }
+
+    /**
+     * Checks if the current name starts with the given name. Returns
+     * <code>false</code> if the given name is <code>null</code> or not an
+     * instance of <code>DNSName</code> class.
+     * @param name the name to compare the beginning of the current message with
+     * @return <code>true</code> or <code>false</code>
+     * @see javax.naming.Name#startsWith(javax.naming.Name)
+     */
+    public boolean startsWith(Name name) {
+        int k = -1;
+        int len1;
+        int len2;
+
+        if (name == null) {
+            return false;
+        }
+        if (!(name instanceof DNSName)) {
+            return false;
+        }
+        len1 = this.size();
+        len2 = name.size();
+        if (len1 == len2) {
+            try {
+                k = this.compareTo(name);
+            } catch (ClassCastException e) {
+                // impossible case
+                ProviderMgr.logger.log(Level.SEVERE, "impossible error", e);
+            }
+        }
+        else if (len1 > len2) {
+            Name prefix = this.getPrefix(len2);
+
+            k = prefix.compareTo(name);
+        }
+        return (k == 0 ? true : false);
+    }
+
+    /**
+     * Adds the given component to the list of components at the specified
+     *  index.
+     * @param posn an index to insert at
+     * @param comp the component to insert
+     * @return updated name (<code>this</code> object)
+     * @throws InvalidNameException if the given string can't be used as a
+     *  DNS name component 
+     * @throws ArrayIndexOutOfBoundsException if <code>posn</code> index is
+     *  out of range 
+     * @see javax.naming.Name#add(int, java.lang.String)
+     */
+    public Name add(int posn, String comp) throws InvalidNameException {
+        if (!componentIsOk(comp)) {
+            throw new InvalidNameException(comp + " can't be used as a " +
+                    "component for DNS name");
+        }
+        components.insertElementAt(comp, posn);
+        return this;
+    }
+
+    /**
+     * Adds the given component to the end of the current name.
+     * @param comp the component to insert
+     * @return updated name (<code>this</code> object)
+     * @throws InvalidNameException if the given string can't be used as a
+     *  DNS name component 
+     * @see javax.naming.Name#add(java.lang.String)
+     */
+    public Name add(String comp) throws InvalidNameException {
+        if (!componentIsOk(comp)) {
+            throw new InvalidNameException(comp + " can't be used as a " +
+                    "component for DNS name");
+        }
+        components.addElement(comp);
+        return this;
+    }
+
+    /**
+     * Add given components to the current name. The order is preserved.
+     * @param posn the index at which given components should be added 
+     * @param name components this name should be added
+     * @return <code>this</code> object
+     * @throws InvalidNameException if the name given is not an instance of
+     *  <code>DNSName</code> class
+     * @see javax.naming.Name#addAll(int, javax.naming.Name)
+     */
+    public Name addAll(int posn, Name name) throws InvalidNameException {
+        Vector newComps;
+
+        if (!(name instanceof DNSName)) {
+            throw new InvalidNameException("Given name is not an instance of " +
+                    "DNSName class");
+        }
+        newComps = ((DNSName) name).components;
+        components.addAll(posn, newComps);
+        return this;
+    }
+
+    /**
+     * Add given components to the end of current name. The order is preserved.
+     * @param name components this name should be added
+     * @return <code>this</code> object
+     * @throws InvalidNameException if the name given is not an instance of
+     *  <code>DNSName</code> class
+     * @see javax.naming.Name#addAll(javax.naming.Name)
+     */
+    public Name addAll(Name name) throws InvalidNameException {
+        Vector newComps;
+
+        if (!(name instanceof DNSName)) {
+            throw new InvalidNameException("Given name is not an instance of " +
+                    "DNSName class");
+        }
+        newComps = ((DNSName) name).components;
+        components.addAll(newComps);
+        return this;
+    }
+
+    /**
+     * Returns the string representation of this DNS name.
+     * @return DNS name in string form
+     */
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+
+        
+        for (int i = components.size() - 1; i >= 0; i--) {
+            String comp = (String) components.elementAt(i);
+            if (sb.length() > 0 || i == 0) {
+                sb.append('.');
+            }
+            if (comp.length() > 0) {
+                sb.append(comp);
+            }
+        }
+        return sb.toString();
+    }
+    
+    /**
+     * Checks if the given string is a correct DNS name component.
+     * @param comp the string component to check
+     * @return <code>true</code> or <code>false</code>
+     */
+    static boolean componentIsOk(String comp) {
+        if (comp.indexOf(".") != -1 || comp.length() >
+                ProviderConstants.LABEL_MAX_CHARS)
+        {
+            return false;
+        }
+        return true;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSName.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSNameParser.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSNameParser.java?rev=410240&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSNameParser.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSNameParser.java Tue May 30 04:24:59 2006
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Alexei Y. Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+
+package org.apache.harmony.jndi.provider.dns;
+
+import java.util.StringTokenizer;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NameParser;
+
+/**
+ * DNS name parser
+ * @author Alexei Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+public class DNSNameParser implements NameParser {
+
+    /**
+     * Constructs a new name parser.
+     */
+    public DNSNameParser() {}
+
+    /**
+     * Parses string representation of DNS name. Following situations will be
+     * treated as an error:
+     * <ul>
+     * <li>The length of the whole name is longer than 255 characters</li>
+     * <li>The length of each label is more than 63 characters</li>
+     * <li>more than one null label encountered or null label is not the least
+     * specific label (the rightmost)</li> 
+     * </ul>
+     * @param name string representation of DNS name
+     * @return new instance of <code>DNSName</code> class
+     * @throws InvalidNameException if given string is not a correct DNS name
+     * @see javax.naming.NameParser#parse(java.lang.String)
+     * @see RFC 1034
+     */
+    public Name parse(String name) throws InvalidNameException {
+        StringTokenizer st;
+        boolean lastTokenWasDilim = false;
+        DNSName dnsName = new DNSName();
+
+        if (name == null) {
+            throw new InvalidNameException("Given name is null");
+        }
+        if (name.length() > 255) {
+            throw new InvalidNameException("The length of the name is more" +
+                    " than 255 characters");
+        }
+        st = new StringTokenizer(name, ".", true);
+        while (st.hasMoreTokens()) {
+            String comp = st.nextToken();
+
+            if (comp.equals(".")) {
+                if (lastTokenWasDilim) {
+                    // two delimiters one after another
+                    throw new InvalidNameException(
+                            "Null label is not the rightmost one");
+                }
+                lastTokenWasDilim = true;
+                if (dnsName.size() == 0 && st.hasMoreTokens()) {
+                    throw new InvalidNameException("DNS name shouldn't " +
+                            "start with a dot"); 
+                }
+            }
+            else {
+                if (comp.length() > 63) {
+                    throw new InvalidNameException("The length of " +
+                            comp + " label is more than 63 characters");
+                }
+                dnsName.add(0, comp);
+                lastTokenWasDilim = false;
+            }
+        }
+        if (lastTokenWasDilim) {
+            dnsName.add(0, "");
+        }
+        return dnsName;
+    }
+
+    /**
+     * @param obj the object to compare with
+     * @return <code>true</code> if and only if the given object is instance of
+     * class <code>DNSParser</code>; otherwise returns <code>false</code>.
+     */
+    public boolean equals(Object obj) {
+        if (obj != null && obj instanceof DNSNameParser) {
+            return true;
+        }
+        return false;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSNameParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSPseudoURL.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSPseudoURL.java?rev=410240&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSPseudoURL.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSPseudoURL.java Tue May 30 04:24:59 2006
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Alexei Y. Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+
+package org.apache.harmony.jndi.provider.dns;
+
+import java.util.StringTokenizer;
+
+/**
+ * Represents a DNS pseudo URL.
+ * @author Alexei Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+public class DNSPseudoURL {
+
+    private String host = "localhost";
+    private int port = ProviderConstants.DEFAULT_DNS_PORT;
+    private String domain = ".";
+    private boolean hostIpWasGiven = false;
+
+    /**
+     * Parses given argument and constructs new <code>DNSPseudoURL</code>
+     * object. The format of the argument is:<br>
+     * <code>dns:[//host[:port]][/domain]</code><br>
+     * If no host information was given then <code>localhost</code> will be
+     * used. If no port was given then the standard DNS server port
+     * <code>53</code> will be used. If no domain was given then the root domain
+     * will be used. All domain here are treated as absolute domains.
+     * @param DNS string representation of DNS URL 
+     * @throws IllegalArgumentException if the argument is not in acceptable
+     * format
+     * @throws NullPointerException if the argument is null 
+     */
+    public DNSPseudoURL(String strForm) throws IllegalArgumentException
+    
+    {
+        StringTokenizer st = null;
+        StringTokenizer st2 = null;
+        String token;
+
+        if (strForm == null) {
+            throw new NullPointerException("strForm is null");
+        }
+        st = new StringTokenizer(strForm, "/", true);
+        if (!st.hasMoreTokens()) {
+            throw new IllegalArgumentException("Empty URL");
+        }
+        // scheme
+        token = st.nextToken();
+        if (!token.equals("dns:")) {
+            throw new IllegalArgumentException("Specified scheme is not dns");
+        }
+        // host
+        if (st.hasMoreTokens()) {
+            token = st.nextToken();
+            if (!token.equals("/") || !st.hasMoreTokens()) { 
+                throw new IllegalArgumentException("Bad URL syntax");
+            }
+            token = st.nextToken();
+            if (token.equals("/")) {
+                // host[:port] was given
+                if (!st.hasMoreElements()) {
+                    throw new IllegalArgumentException("Bad URL syntax");
+                }
+                token = st.nextToken();
+                st2 = new StringTokenizer(token, ":");
+                host = st2.nextToken();
+                try {
+                    ProviderMgr.parseIpStr(host);
+                    hostIpWasGiven = true;
+                } catch (IllegalArgumentException e) {
+                    hostIpWasGiven = false;
+                }
+                // port
+                if (st2.hasMoreTokens()) {
+                    port = Integer.parseInt(st2.nextToken());
+                }
+                // domain
+                if (st.hasMoreTokens()) {
+                    token = st.nextToken();
+                    if (!token.equals("/") || !st.hasMoreTokens()) {
+                        throw new IllegalArgumentException("Bad URL syntax");
+                    }
+                    domain = ProviderMgr.normalizeName(st.nextToken());
+                }
+            } else {
+                // domain
+                domain = ProviderMgr.normalizeName(token);
+            }
+            // extra
+            if (st.hasMoreTokens()) {
+                throw new IllegalArgumentException(
+                        "Extra characters encountered at the end of the URL");
+            }
+        }
+    }
+
+    /**
+     * @return Returns the domain.
+     */
+    public String getDomain() {
+        return domain;
+    }
+    /**
+     * @return Returns the host.
+     */
+    public String getHost() {
+        return host;
+    }
+    /**
+     * @return Returns the hostIpWasGiven.
+     */
+    public boolean isHostIpGiven() {
+        return hostIpWasGiven;
+    }
+    /**
+     * @return Returns the port.
+     */
+    public int getPort() {
+        return port;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DNSPseudoURL.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DomainProtocolException.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DomainProtocolException.java?rev=410240&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DomainProtocolException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DomainProtocolException.java Tue May 30 04:24:59 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Alexei Y. Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+
+package org.apache.harmony.jndi.provider.dns;
+
+import javax.naming.NamingException;
+
+/**
+ * The exception that can be thrown from the DNS Resovler classes. 
+ * 
+ * @author Alexei Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+public class DomainProtocolException extends NamingException {
+    
+    private static final long serialVersionUID = -6631370496197297208L;
+    
+    public DomainProtocolException(String message) {
+        super(message);
+    }
+
+    public DomainProtocolException(Exception cause) {
+        super();
+        setRootCause(cause);
+    }
+    
+    public DomainProtocolException(String mes, Exception cause) {
+        super(mes);
+        setRootCause(cause);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/DomainProtocolException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Message.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Message.java?rev=410240&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Message.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Message.java Tue May 30 04:24:59 2006
@@ -0,0 +1,565 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Alexei Y. Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+
+package org.apache.harmony.jndi.provider.dns;
+
+
+import java.util.Vector;
+import java.util.Enumeration;
+
+/**
+ * This class represents a domain protocol message.
+ * 
+ * @author Alexei Zakharov
+ * @version $Revision: 1.1.2.4 $
+ * @see RFC 1035
+ */
+public class Message {
+    
+    // header section fields
+    
+    /** an ID */
+    private int id = 0;
+
+    /** QR; false stands for QUERY request, true for RESPONSE */
+    private boolean qr = ProviderConstants.QR_QUERY;
+
+    /** OPCODE; QUERY or IQUERY or STATUS */
+    private int opCode = 0; 
+
+    /** AA, Authoritative Answer*/
+    private boolean aa = false; 
+
+    /** TC, TrunCation */
+    private boolean tc = false; 
+
+    /** RD, Recursion Desired */
+    private boolean rd = false; 
+
+    /** RA, Recursion Available */
+    private boolean ra = false; 
+
+    /** Z, always should be zero */
+    //private int z; 
+
+    /** RCODE, Response CODE */
+    private int rCode = 0; 
+
+    /** QDCOUNT, number of records in question section */
+    private int qdCount = 0; 
+
+    /** ANCOUNT, number of records in answer section */
+    private int anCount = 0; 
+
+    /** NSCOUNT, number of records in authority records section */
+    private int nsCount = 0; 
+
+    /** ARCOUNT, number of records in additional section */
+    private int arCount = 0;
+
+    private Vector questionRecords = null;
+    private Vector answerRRs = null;
+    private Vector authorityRRs = null;
+    private Vector additionalRRs = null;
+
+    /** */
+    public Message() {
+        questionRecords = new Vector();
+        answerRRs = new Vector();
+        authorityRRs = new Vector();
+        additionalRRs = new Vector();
+    }
+
+    /** 
+     * Constructs Message object from given parameters 
+     *
+     * @param id ID
+     * @param qr QR
+     * @param opCode OPCODE
+     * @param aa AA
+     * @param tc TC
+     * @param rd RA
+     * @param ra RA
+     * @param rCode RCODE
+     * @param qdCount QDCOUNT
+     * @param anCount ANCOUNT
+     * @param nsCount NSCOUNT
+     * @param arCount ARCOUNT
+     */
+    public Message(
+            int id,
+            boolean qr,
+            int opCode, 
+            boolean aa, 
+            boolean tc, 
+            boolean rd, 
+            boolean ra, 
+            int rCode, 
+            int qdCount, 
+            int anCount, 
+            int nsCount, 
+            int arCount)
+    {
+        this.id = id;
+        this.qr = qr;
+        this.opCode = opCode;
+        this.aa = aa;
+        this.tc = tc;
+        this.rd = rd;
+        this.ra = ra;
+        this.rCode = rCode;
+        this.qdCount = qdCount;
+        this.anCount = anCount;
+        this.nsCount = nsCount;
+        this.arCount = arCount;
+        questionRecords = new Vector();
+        answerRRs = new Vector();
+        authorityRRs = new Vector();
+        additionalRRs = new Vector();
+    }
+    
+    /**
+     * Generates sequence of bytes that represents the message. 
+     * 
+     * @param buffer the buffer to write bytes into
+     * @param startIdx the index of <code>buffer</code> to start writing at
+     * @return updated index of the <code>buffer</code>
+     * @throws DomainProtocolException if something went wrong
+     */
+    public int writeBytes(byte[] buffer, int startIdx)
+            throws DomainProtocolException
+    {
+        int idx = startIdx;
+        int tmp = 0;
+
+        // basic check
+        if (buffer == null) {
+            throw new DomainProtocolException("buffer is null");
+        }
+        // ID
+        idx = ProviderMgr.write16Int(id, buffer, idx);
+        // QR
+        tmp = ProviderMgr.setBit(tmp, ProviderConstants.QR_MASK, qr);
+        // OPCODE
+        tmp &= ~ProviderConstants.OPCODE_MASK;
+        tmp |= (opCode & 0xf) << ProviderConstants.OPCODE_SHIFT;
+        // AA
+        tmp = ProviderMgr.setBit(tmp, ProviderConstants.AA_MASK, aa);
+        // TC
+        tmp = ProviderMgr.setBit(tmp, ProviderConstants.TC_MASK, tc);
+        // RD
+        tmp = ProviderMgr.setBit(tmp, ProviderConstants.RD_MASK, rd);
+        // RA
+        tmp = ProviderMgr.setBit(tmp, ProviderConstants.RA_MASK, ra);
+        // Z, drop all those bits
+        tmp &= ~ProviderConstants.Z_MASK;
+        // RCODE
+        tmp &= ~ProviderConstants.RCODE_MASK;
+        tmp |= (rCode & 0xf) << ProviderConstants.RCODE_SHIFT;
+        // write to buffer
+        idx = ProviderMgr.write16Int(tmp, buffer, idx);
+        // QDCOUNT
+        idx = ProviderMgr.write16Int(qdCount, buffer, idx);
+        // ANCOUNT
+        idx = ProviderMgr.write16Int(anCount, buffer, idx);
+        // NSCOUNT
+        idx = ProviderMgr.write16Int(nsCount, buffer, idx);
+        // ARCOUNT
+        idx = ProviderMgr.write16Int(arCount, buffer, idx);
+        // question section
+        for (int i = 0; i < questionRecords.size(); i++) {
+            QuestionRecord qr = (QuestionRecord) questionRecords.elementAt(i);
+
+            idx = qr.writeBytes(buffer, idx);
+        }
+        // answer section
+        for (int i = 0; i < answerRRs.size(); i++) {
+            ResourceRecord rr = (ResourceRecord) answerRRs.elementAt(i);
+
+            idx = rr.writeBytes(buffer, idx);
+        }
+        // authority section
+        for (int i = 0; i < authorityRRs.size(); i++) {
+            ResourceRecord rr = (ResourceRecord) answerRRs.elementAt(i);
+
+            idx = rr.writeBytes(buffer, idx);
+        }
+        // additional section
+        for (int i = 0; i < additionalRRs.size(); i++) {
+            ResourceRecord rr = (ResourceRecord) answerRRs.elementAt(i);
+
+            idx = rr.writeBytes(buffer, idx);
+        }
+        return idx;
+    }
+
+    /**
+     * Parses given sequence of bytes and constructs a message object from it.
+     * 
+     * @param mesBytes the byte array that should be parsed
+     * @param startIdx an index of <code>mesBytes</code> array to start the
+     *  parsing at
+     * @param mes an object to write a result to, should already be created
+     * @return updated index of <code>mesBytes</code> array
+     * @throws DomainProtocolException if some error has occured
+     */
+    public static int parseMessage(byte[] mesBytes, int startIdx,
+            Message mesObj) throws DomainProtocolException
+    {
+        int idx = startIdx;
+        int tmp, tmp2;
+        int qdCnt;
+        int anCnt;
+        int nsCnt;
+        int arCnt;
+
+        if (mesObj == null) {
+            throw new DomainProtocolException(
+                    "The value of parameter mesObj is null");
+        }
+        // header section
+        // ID
+        mesObj.setId(ProviderMgr.parse16Int(mesBytes, idx));
+        idx += 2;
+        // QR & opCode & AA & TC & RD & RA & Z & rCode
+        tmp = ProviderMgr.parse16Int(mesBytes, idx);
+        idx += 2;
+        // QR
+        mesObj.setQR(ProviderMgr.checkBit(tmp, ProviderConstants.QR_MASK));
+        // OPCODE
+        tmp2 = (tmp & ProviderConstants.OPCODE_MASK)
+                        >> ProviderConstants.OPCODE_SHIFT; 
+        mesObj.setOpCode(tmp2);
+        // AA
+        mesObj.setAA(ProviderMgr.checkBit(tmp, ProviderConstants.AA_MASK));
+        // TC
+        mesObj.setTc(ProviderMgr.checkBit(tmp, ProviderConstants.TC_MASK));
+        // RD
+        mesObj.setRD(ProviderMgr.checkBit(tmp, ProviderConstants.RD_MASK));
+        // RA
+        mesObj.setRA(ProviderMgr.checkBit(tmp, ProviderConstants.RA_MASK));
+        // RCODE
+        tmp2 = (tmp & ProviderConstants.RCODE_MASK)
+                        >> ProviderConstants.RCODE_SHIFT; 
+        mesObj.setRCode(tmp2);
+        // QDCOUNT
+        qdCnt = ProviderMgr.parse16Int(mesBytes, idx);
+        mesObj.setQDCount(qdCnt);
+        idx += 2;
+        // ANCOUNT
+        anCnt = ProviderMgr.parse16Int(mesBytes, idx);
+        mesObj.setANCount(anCnt);
+        idx += 2;
+        // NSCOUNT
+        nsCnt = ProviderMgr.parse16Int(mesBytes, idx);
+        mesObj.setNSCount(nsCnt);
+        idx += 2;
+        // ARCOUNT
+        arCnt = ProviderMgr.parse16Int(mesBytes, idx);
+        mesObj.setARCount(arCnt);
+        idx += 2;
+        // question section
+        for (int i = 0; i < qdCnt; i++) {
+            QuestionRecord qr = new QuestionRecord();
+            idx = QuestionRecord.parseRecord(mesBytes, idx, qr);
+            mesObj.addQuestionRecord(qr);
+        }
+        // answer section
+        for (int i = 0; i < anCnt; i++) {
+            ResourceRecord rr = new ResourceRecord();
+            idx = ResourceRecord.parseRecord(mesBytes, idx, rr);
+            mesObj.addAnswerRR(rr);
+        }
+        // authority section
+        for (int i = 0; i < nsCnt; i++) {
+            ResourceRecord rr = new ResourceRecord();
+            idx = ResourceRecord.parseRecord(mesBytes, idx, rr);
+            mesObj.addAuthorityRR(rr);
+        }
+        // additional section
+        for (int i = 0; i < arCnt; i++) {
+            ResourceRecord rr = new ResourceRecord();
+            idx = ResourceRecord.parseRecord(mesBytes, idx, rr);
+            mesObj.addAdditionalRR(rr);
+        }
+        return idx;
+    }
+
+    /**
+     * @return string representation of this message 
+     */
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+
+        sb.append("ID=" + id + "\n");
+        if (qr) {
+            sb.append(" QR");
+        }
+        sb.append(" OPCODE=" + opCode);
+        if (aa) {
+            sb.append(" AA");
+        }
+        if (tc) {
+            sb.append(" TC");
+        }
+        if (rd) {
+            sb.append(" RD");
+        }
+        if (ra) {
+            sb.append(" RA");
+        }
+        sb.append(" RCODE=" + rCode);
+        sb.append("\n");
+        sb.append("QDCOUNT=" + qdCount);
+        for (int i = 0; i < questionRecords.size(); i++) {
+            sb.append("\n");
+            sb.append(questionRecords.elementAt(i).toString());
+        }
+        sb.append("\n");
+        sb.append(" ANCOUNT=" + anCount);
+        for (int i = 0; i < answerRRs.size(); i++) {
+            sb.append("\n");
+            sb.append(answerRRs.elementAt(i).toString());
+        }
+        sb.append("\n");
+        sb.append(" NSCOUNT=" + nsCount);
+        for (int i = 0; i < authorityRRs.size(); i++) {
+            sb.append("\n");
+            sb.append(authorityRRs.elementAt(i).toString());
+        }
+        sb.append("\n");
+        sb.append(" ARCOUNT=" + arCount);
+        for (int i = 0; i < additionalRRs.size(); i++) {
+            sb.append("\n");
+            sb.append(additionalRRs.elementAt(i).toString());
+        }
+        return sb.toString();
+    }
+
+    // setters and getters
+    
+    /**
+     * @return Returns the AA.
+     */
+    public boolean isAA() {
+        return aa;
+    }
+    /**
+     * @param aa The AA to set.
+     */
+    public void setAA(boolean aa) {
+        this.aa = aa;
+    }
+    /**
+     * @return Returns the anCount.
+     */
+    public int getANCount() {
+        return anCount;
+    }
+    /**
+     * @param anCount The anCount to set.
+     */
+    public void setANCount(int anCount) {
+        this.anCount = anCount;
+    }
+    /**
+     * @return Returns the arCount.
+     */
+    public int getARCount() {
+        return arCount;
+    }
+    /**
+     * @param arCount The arCount to set.
+     */
+    public void setARCount(int arCount) {
+        this.arCount = arCount;
+    }
+    /**
+     * @return Returns the id.
+     */
+    public int getId() {
+        return id;
+    }
+    /**
+     * @param id The id to set.
+     */
+    public void setId(int id) {
+        this.id = id;
+    }
+    /**
+     * @return Returns the nsCount.
+     */
+    public int getNSCount() {
+        return nsCount;
+    }
+    /**
+     * @param nsCount The nsCount to set.
+     */
+    public void setNSCount(int nsCount) {
+        this.nsCount = nsCount;
+    }
+    /**
+     * @return Returns the opCode.
+     */
+    public int getOpCode() {
+        return opCode;
+    }
+    /**
+     * @param opCode The opCode to set.
+     */
+    public void setOpCode(int opCode) {
+        this.opCode = opCode;
+    }
+    /**
+     * @return Returns the qdCount.
+     */
+    public int getQDCount() {
+        return qdCount;
+    }
+    /**
+     * @param qdCount The qdCount to set.
+     */
+    public void setQDCount(int qdCount) {
+        this.qdCount = qdCount;
+    }
+    /**
+     * @return Returns the QR.
+     */
+    public boolean getQR() {
+        return qr;
+    }
+    /**
+     * @param qr The QR to set.
+     */
+    public void setQR(boolean qr) {
+        this.qr = qr;
+    }
+    /**
+     * @return Returns the RA.
+     */
+    public boolean isRA() {
+        return ra;
+    }
+    /**
+     * @param ra The RA to set.
+     */
+    public void setRA(boolean ra) {
+        this.ra = ra;
+    }
+    /**
+     * @return Returns the rCode.
+     */
+    public int getRCode() {
+        return rCode;
+    }
+    /**
+     * @param code The rCode to set.
+     */
+    public void setRCode(int code) {
+        rCode = code;
+    }
+    /**
+     * @return Returns the RD.
+     */
+    public boolean isRD() {
+        return rd;
+    }
+    /**
+     * @param rd The RD to set.
+     */
+    public void setRD(boolean rd) {
+        this.rd = rd;
+    }
+    /**
+     * @return Returns the TC.
+     */
+    public boolean isTc() {
+        return tc;
+    }
+    /**
+     * @param tc The TC to set.
+     */
+    public void setTc(boolean tc) {
+        this.tc = tc;
+    }
+
+    /**
+     * @return question records that are contained by the current message.
+     */
+    public Enumeration getQuestionRecords() {
+        return questionRecords.elements();
+    }
+    
+    /**
+     * Adds a new question record to the message.
+     * @param qr a record to add
+     */
+    public void addQuestionRecord(QuestionRecord qr) {
+        questionRecords.addElement(qr);
+    }
+
+    /**
+     * @return available answer resource records
+     */
+    public Enumeration getAnswerRRs() {
+        return answerRRs.elements();
+    }
+
+    /**
+     * Adds a new question record to the message.
+     * @param rr a record to add
+     */
+    public void addAnswerRR(ResourceRecord rr) {
+        answerRRs.addElement(rr);
+    }
+
+    /**
+     * @return available authority resource records
+     */
+    public Enumeration getAuthorityRRs() {
+        return authorityRRs.elements();
+    }
+
+    /**
+     * Adds a new question record to the message.
+     * @param rr a record to add
+     */
+    public void addAuthorityRR(ResourceRecord rr) {
+        authorityRRs.addElement(rr);
+    }
+
+    /**
+     * @return available additional resource records
+     */
+    public Enumeration getAdditionalRRs() {
+        return additionalRRs.elements();
+    }
+
+    /**
+     * Adds a new question record to the message.
+     * @param rr a record to add
+     */
+    public void addAdditionalRR(ResourceRecord rr) {
+        additionalRRs.addElement(rr);
+    }
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Message.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ProviderConstants.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ProviderConstants.java?rev=410240&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ProviderConstants.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ProviderConstants.java Tue May 30 04:24:59 2006
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Alexei Y. Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+
+package org.apache.harmony.jndi.provider.dns;
+
+import javax.naming.InvalidNameException;
+
+/**
+ * Contains various constants that are used in the provider classes.
+ * 
+ * @author Alexei Zakharov
+ * @version $Revision: 1.1.2.4 $
+ * @see RFC 1035
+ */
+public class ProviderConstants {
+
+    // Constants that should be used as possible values for the header QR field 
+    public static final boolean QR_QUERY = false;
+    public static final boolean QR_RESPONSE = true;
+    
+    // Message header masks
+    public static final int QR_MASK = 0x8000;
+    public static final int OPCODE_MASK = 0x7800;
+    public static final int AA_MASK = 0x400;
+    public static final int TC_MASK = 0x200;
+    public static final int RD_MASK = 0x100;
+    public static final int RA_MASK = 0x80;
+    public static final int Z_MASK = 0x70;
+    public static final int RCODE_MASK = 0xf;
+
+    // Message header fields shifts
+    public static final int OPCODE_SHIFT = 11;
+    public static final int RCODE_SHIFT = 0;
+    
+    // Constants that can be used as OPCODEs in the header
+    public static final int QUERY = 0;
+    public static final int IQUERY = 1;
+    public static final int STATUS = 2;
+
+    // Constants that can be used as RCODEs in the header
+    public static final int NO_ERROR = 0;
+    public static final int FORMAT_ERROR = 1;
+    public static final int SERVER_FAILURE = 2;
+    public static final int NAME_ERROR = 3;
+    public static final int NOT_IMPLEMENTED = 4;
+    public static final int REFUSED = 5;
+
+    // Possible TYPE values
+    public static final int A_TYPE = 1;
+    public static final int NS_TYPE = 2;
+    public static final int MD_TYPE = 3;
+    public static final int MF_TYPE = 4;
+    public static final int CNAME_TYPE = 5;
+    public static final int SOA_TYPE = 6;
+    public static final int MB_TYPE = 7;
+    public static final int MG_TYPE = 8;
+    public static final int MR_TYPE = 9;
+    public static final int NULL_TYPE = 10;
+    public static final int WKS_TYPE = 11;
+    public static final int PTR_TYPE = 12;
+    public static final int HINFO_TYPE = 13;
+    public static final int MINFO_TYPE = 14;
+    public static final int MX_TYPE = 15;
+    public static final int TXT_TYPE = 16;
+    public static final int AAAA_TYPE = 28;
+    public static final int SRV_TYPE = 33;
+    
+    // Possible QTYPE values
+    public static final int AXFR_QTYPE = 252;    
+    public static final int MAILB_QTYPE = 253;    
+    public static final int MAILA_QTYPE = 254;    
+    public static final int ANY_QTYPE = 255;   
+    
+    public static String[] rrTypeNames;
+    public static String[] rrClassNames;
+    
+    // Possible CLASS values
+    public static final int IN_CLASS = 1;
+    public static final int CS_CLASS = 2;
+    public static final int CH_CLASS = 3;
+    public static final int HS_CLASS = 4;
+
+    // Possible QCLASS values
+    public static final int ANY_QCLASS = 255;
+
+    // Maximum lengths
+    public static final int LABEL_MAX_CHARS = 63;
+    public static final int NAME_MAX_CHARS = 255;
+
+    // default DNS port
+    public static final int DEFAULT_DNS_PORT = 53;
+
+    // Resolver settings
+    public static final int DEFAULT_INITIAL_TIMEOUT = 1000;
+    public static final int DEFAULT_TIMEOUT_RETRIES = 4;
+    public static final boolean DEFAULT_AUTHORITATIVE = false;
+    public static final boolean DEFAULT_RECURSION = true;
+    public static final int DEFAULT_LOOKUP_ATTR_TYPE = TXT_TYPE;
+    public static final int DEFAULT_LOOKUP_ATTR_CLASS = IN_CLASS;
+    public static final int DEFAULT_MAX_THREADS = 7;
+    
+    public static DNSName ROOT_ZONE_NAME_OBJ = null;
+    
+    public static final String LOGGER_NAME =
+            "org.apache.harmony.jndi.provider.dns";
+
+    
+    static {
+        // Resource Record types
+        // commented out types are not supported
+        rrTypeNames = new String[256];
+        for (int i = 0; i < 256; i++) {
+            rrTypeNames[i] = String.valueOf(i);
+        }
+        rrTypeNames[A_TYPE] = "A";
+        rrTypeNames[NS_TYPE] = "NS";
+        //rrTypeNames[MD_TYPE] = "MD";
+        //rrTypeNames[MF_TYPE] = "MF";
+        rrTypeNames[CNAME_TYPE] = "CNAME";
+        rrTypeNames[SOA_TYPE] = "SOA";
+        //rrTypeNames[MB_TYPE] = "MB";
+        //rrTypeNames[MG_TYPE] = "MG";
+        //rrTypeNames[MR_TYPE] = "MR";
+        //rrTypeNames[NULL_TYPE] = "NULL";
+        //rrTypeNames[WKS_TYPE] = "WKS";
+        rrTypeNames[PTR_TYPE] = "PTR";
+        rrTypeNames[HINFO_TYPE] = "HINFO";
+        //rrTypeNames[MINFO_TYPE] = "MINFO";
+        rrTypeNames[MX_TYPE] = "MX";
+        rrTypeNames[TXT_TYPE] = "TXT";
+        rrTypeNames[AAAA_TYPE] = "AAAA";
+        rrTypeNames[SRV_TYPE] = "SRV";
+        //rrTypeNames[AXFR_QTYPE] = "AXFR";
+        //rrTypeNames[MAILB_QTYPE] = "MAILB";
+        //rrTypeNames[MAILA_QTYPE] = "MAILA";
+        rrTypeNames[ANY_QTYPE] = "*";
+
+        // Resource Record classes
+        rrClassNames = new String[256];
+        for (int i = 0; i < 256; i++) {
+            rrClassNames[i] = String.valueOf(i);
+        }
+        rrClassNames[IN_CLASS] = "IN";
+        rrClassNames[HS_CLASS] = "HS";
+        rrClassNames[ANY_QCLASS] = "*";
+
+        // Root zone name
+        try {
+            ROOT_ZONE_NAME_OBJ = (DNSName) ((new DNSNameParser()).parse("."));
+        } catch (InvalidNameException e) {
+            // ignore
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ProviderConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ProviderMgr.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ProviderMgr.java?rev=410240&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ProviderMgr.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ProviderMgr.java Tue May 30 04:24:59 2006
@@ -0,0 +1,535 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Alexei Y. Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+
+package org.apache.harmony.jndi.provider.dns;
+
+import java.util.StringTokenizer;
+import java.util.logging.Logger;
+
+/**
+ * Contains some useful routines that are used in other classes.
+ *
+ * @author Alexei Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+public class ProviderMgr {
+
+    static final int LOG_NONE = 0;
+    static final int LOG_ERROR = 1;
+    static final int LOG_WARNING = 2;
+    static final int LOG_DEBUG = 3;
+
+    static final boolean CHECK_NAMES = false;
+
+    static final Logger logger =
+            Logger.getLogger(ProviderConstants.LOGGER_NAME);
+
+    /**
+     * Parses the given domain name and converts it into
+     * <code>length label length label ... length label</code> sequence of bytes.
+     * 
+     * @param name a domain name, a dot-separated list of labels
+     * @param buffer target buffer in which the result will be written
+     * @param startIdx the index to start at while writing to the buffer array
+     * @return updated index of the buffer array
+     */
+    public static int writeName(String name, byte[] buffer, int startIdx)
+            throws DomainProtocolException
+    {
+        StringTokenizer st; 
+        int idx = startIdx;
+        
+        if (name != null) {
+            // initial check
+            if (buffer == null) {
+                throw new NullPointerException("buffer is null");
+            }
+            if (startIdx > buffer.length || startIdx < 0) {
+                throw new ArrayIndexOutOfBoundsException();
+            }
+            // parsing the name
+            //if (CHECK_NAMES && !checkName(name)) {
+            //    throw new DomainProtocolException(
+            //           "The syntax of the domain name " +
+            //            name + " does not conform to RFC 1035");
+            //}
+            st = new StringTokenizer(name, ".");
+            while (st.hasMoreTokens()) {
+                String token = st.nextToken();
+                byte[] tokenBytes;
+                int tokenBytesLen;
+
+                if (token == null || token.length() == 0) {
+                    break;
+                }
+                tokenBytes = token.getBytes();
+                tokenBytesLen = tokenBytes.length;
+                if (tokenBytesLen > ProviderConstants.LABEL_MAX_CHARS) {
+                    throw new DomainProtocolException("The domain label is " +
+                            "too long: " + token);
+                }
+                if (idx + tokenBytesLen + 1 > buffer.length) {
+                    throw new ArrayIndexOutOfBoundsException();
+                }
+                buffer[idx++] = (byte) tokenBytesLen;
+                for (int i = 0; i < tokenBytesLen; i++) {
+                    buffer[idx++] = tokenBytes[i];
+                }
+                if (idx - startIdx + 1 > ProviderConstants.NAME_MAX_CHARS) {
+                    throw new DomainProtocolException("The domain name " +
+                            "is more than " + ProviderConstants.NAME_MAX_CHARS +
+                            " octets long: " + name);
+                }
+            }
+            // every domain name should end with an zero octet
+            buffer[idx++] = (byte) 0;
+        }
+        return idx;
+    }
+
+    /**
+     * Parses the domain name from the sequence of bytes.
+     * 
+     * @param mesBytes byte representation of the message
+     * @param startIdx the position to start the parsing at
+     * @param result the string buffer to store parsed strings into
+     * @return updated index of <code>mesBytes</code> array
+     * @throws DomainProtocolException if something went wrong
+     */
+    public static int parseName(byte[] mesBytes, int startIdx,
+            StringBuffer result) throws DomainProtocolException
+    {
+        int idx = startIdx;
+        boolean firstTime = true;
+
+        if (mesBytes == null) {
+            throw new NullPointerException("Input byte array is null");
+        }
+        if (result == null) {
+            throw new NullPointerException("The result string buffer is null");
+        }
+        while (true) {
+            int n = parse8Int(mesBytes, idx++);
+
+            if (n == 0) {
+                // end of the domain name reached
+                break;
+            }
+            if ((n & 0xc0) == 0xc0) {
+                // compressed label
+                int namePtr = parse16Int(mesBytes, --idx) & 0x3fff;
+
+                idx += 2;
+                if (!firstTime) {
+                    result.append('.');
+                }
+                parseName(mesBytes, namePtr, result);
+                break;
+            }
+            else {
+                // plain label
+                if (n > ProviderConstants.LABEL_MAX_CHARS) {
+                    throw new DomainProtocolException("Domain label is too " +
+                            " long");
+                }
+                if (idx + n > mesBytes.length) {
+                    throw new DomainProtocolException("Truncated data while " +
+                            " parsing the domain name");
+                }
+                // append parsed label
+                if (firstTime) {
+                    firstTime = false;                
+                } else {
+                    result.append('.');
+                }
+                result.append(new String(mesBytes, idx, n));
+                idx += n;
+            }
+        }
+        return idx;
+    }
+    
+    /**
+     * Compares two labels and returns the matching count (number of the
+     *  matching labels down from the root).
+     * 
+     * @param name1 first name
+     * @param name2 second name
+     * @return number of equal labels from the root to leaves
+     */
+    public static int getMatchingCount(String name1, String name2) {
+        StringTokenizer st1, st2;
+        int k = 0;
+
+        if (name1 == null || name2 == null) {
+            return 0;
+        }
+        st1 = new StringTokenizer(name1, ".");
+        st2 = new StringTokenizer(name2, ".");
+        while (st1.hasMoreTokens() && st2.hasMoreTokens()) {
+            if (st1.nextToken().equalsIgnoreCase(st2.nextToken())) {
+                k++;
+            } else {
+                break;
+            }
+        }
+        return k;
+    }
+
+    /**
+     * Returns the name of parent DNS zone for given zone.
+     * @param name the current DNS zone name
+     * @return the name of the parent
+     */
+    public static String getParentName(String name) {
+        int n;
+
+        if (name == null) {
+            return null;
+        }
+        if (name.trim().equals(".") || name.trim().length() == 0) {
+            return ".";
+        }
+        n = name.indexOf('.');
+        if (n != -1 && name.length() > n + 1)  {
+            return name.substring(n + 1, name.length());
+        }
+        return ".";
+    }
+
+    /**
+     * Writes a 16-bit integer value into the buffer, high byte first
+     * 
+     * @param value the value to write, first 16 bits will be taken
+     * @param buffer the buffer to write into
+     * @param startIdx a starting index
+     * @return updated index
+     */
+    public static int write16Int(int value, byte[] buffer, int startIdx) {
+        int idx = startIdx;
+
+        buffer[idx++] = (byte) ((value & 0xff00) >> 8);
+        buffer[idx++] = (byte) (value & 0xff);
+        return idx;
+    }
+
+
+    /**
+     * Writes a 32-bit integer value into the buffer, highest byte first
+     * 
+     * @param value the value to write, first 32 bits will be taken 
+     * @param buffer the buffer to write into
+     * @param startIdx a starting index
+     * @return updated index
+     */
+    public static int write32Int(long value, byte[] buffer, int startIdx) {
+        int idx = startIdx;
+
+        buffer[idx++] = (byte) ((value & 0xff000000l) >> 24);
+        buffer[idx++] = (byte) ((value & 0xff0000) >> 16);
+        buffer[idx++] = (byte) ((value & 0xff00) >> 8);
+        buffer[idx++] = (byte) (value & 0xff);
+        return idx;
+    } 
+
+    /**
+     * Parses 8 bit integer.
+     * Buffer index should be updated manually after call to this method.
+     * @param buffer sequence of bytes
+     * @param startIdx the index to start at
+     * @return parsed integer value
+     */
+    public static int parse8Int(byte[] buffer, int idx) {
+        return ((int) buffer[idx]) & 0xff;
+    }
+
+    /**
+     * Parses 16 bit integer.
+     * Buffer index should be updated manually after call to this method.
+     * @param buffer sequence of bytes
+     * @param startIdx the index to start at
+     * @return parsed integer value
+     */
+    public static int parse16Int(byte[] buffer, int idx) {
+        int a = (((int) buffer[idx]) & 0xff) << 8;
+        int b = ((int) buffer[idx + 1]) & 0xff;
+
+        return (a | b);
+    }
+
+    /**
+     * Parses 32 bit integer.
+     * Buffer index should be updated manually after call to this method.
+     * @param buffer sequence of bytes
+     * @param startIdx the index to start at
+     * @return parsed integer value
+     */
+    public static long parse32Int(byte[] buffer, int idx) {
+        long a = (((long) buffer[idx]) & 0xff) << 24;
+        long b = (((long) buffer[idx + 1]) & 0xff) << 16;
+        long c = (((long) buffer[idx + 2]) & 0xff) << 8;
+        long d = ((long) buffer[idx + 3]) & 0xff;
+
+        return (a | b | c | d); 
+    }
+   
+    /**
+     * Writes character string preceded with length octet.
+     * @param value string value to write
+     * @param buffer buffer to write to
+     * @param startIdx index in buffer to start from
+     * @return updated index
+     * @throws NullPointerExcetpion if some argument is null
+     * @throws DomainProtocolException if string is too long
+     */
+    public static int writeCharString(String value, byte[] buffer, int startIdx)
+            throws DomainProtocolException
+    {
+        byte[] bytes;
+        int idx = startIdx;
+
+        if (value == null || buffer == null) {
+            throw new NullPointerException("value or buffer is null");
+        }
+        if (value.length() > 255) {
+            throw new DomainProtocolException("Character string is too long");
+        }
+        bytes = value.getBytes();
+        buffer[idx++] = (byte) bytes.length; 
+        for (int i = 0; i < bytes.length; i++) {
+            buffer[idx++] = bytes[i];
+        }
+        return idx;
+    }
+
+    /**
+     * Parses the string of characters preceded with length octet.
+     * @param mesBytes message bytes
+     * @param startIdx the index to start parsing from
+     * @param result string buffer to write the result too 
+     * @return updated index
+     */
+    public static int parseCharString(byte[] mesBytes, int startIdx,
+            StringBuffer result)
+    {
+        int len;
+
+        if (mesBytes == null || result == null) {
+            throw new NullPointerException("mesBytes or result is null");
+        }
+        len = mesBytes[startIdx];
+        result.append(new String(mesBytes, startIdx + 1, len));
+        return startIdx + 1 + len;
+    }
+    
+    /**
+     * Sets or drops specific bit(s) of the given number.
+     * 
+     * @param value target integer value 
+     * @param mask specifies bit(s) position(s)
+     * @param bit set if <code>true</code>, drop if <code>false</code>
+     * @return updated <code>value</code>
+     */
+    public static int setBit(int value, int mask, boolean bit) {
+        if (bit) {
+            value |= mask; 
+        } else {
+            value &= ~mask;
+        }
+        return value; 
+    }
+
+    /**
+     * Checks if any of specified bits is set.
+     * 
+     * @param value the number to look at
+     * @param mask a bit mask
+     * @return <code>true</code> of <code>false</code>
+     */
+    public static boolean checkBit(int value, int mask) {
+        if ((value & mask) == 0) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    /**
+     * Compares two DNS names.
+     * <ol>
+     * <li>Case insensitive</li>
+     * <li>Appends "." to the end of the name if necessary before comparison</li>
+     * </ol>   
+     * @param name1 name1
+     * @param name2 name2
+     * @return <code>true</code> if names are equal; <code>false</code> otherwise
+     */
+    public static boolean namesAreEqual(String name1, String name2)
+    {
+        if (!name1.endsWith(".")) {
+            name1 += ".";
+        }
+        if (!name2.endsWith(".")) {
+            name2 += ".";
+        }
+        return name1.equalsIgnoreCase(name2);
+    }
+
+    /**
+     * Removes _Service._Proto fields from SRV-style qName if any. Adds
+     * final dot to the end of name
+     * @param name name to process
+     * @return converted name
+     */
+/*
+    public static String removeSRVExtra(String name) {
+        StringTokenizer st;
+        int k = 0;
+        StringBuffer res = new StringBuffer();
+        
+        if (name == null) {
+            return name;
+        }
+        st = new StringTokenizer(name, ".", false);
+        while (st.hasMoreTokens()) { 
+            String token = st.nextToken();
+
+            if ((k != 0 && k != 1) || !token.startsWith("_")) {
+                res.append(token);
+            }
+            k++;
+        }
+        return res.toString();
+    }
+*/  
+      
+    /**
+     * Converts all letters to lower case and adds "." to the end of zone name
+     * if necessary.
+     * @param zone zone name
+     * @return expanded zone name
+     */
+    public static String normalizeName(String zone) {
+        if (zone == null) {
+            return zone;
+        }
+        else {
+            return zone.endsWith(".") ? zone.toLowerCase() :
+                    zone.toLowerCase() + ".";
+        }
+    }
+    
+
+    /**
+     * Creates the text representation of IPv4 address.
+     * 
+     * @param ip the first four bytes should contain an IPv4 address
+     * @return string in <code>n.n.n.n</code> format
+     * @throws java.lang.IllegalArgumentException if given array has the length
+     *  less than four
+     */
+    public static String getIpStr(byte[] ip) {
+        StringBuffer sb = new StringBuffer();
+
+        if (ip == null || ip.length < 4) {
+            throw new IllegalArgumentException("Given array is null or has the"+
+                    " length less than four");
+        }
+        for (int i = 0; i < 4; i++) {
+            if (i > 0) {
+                sb.append(".");
+            }
+            sb.append("" + (((int) ip[i]) & 0xff));
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Parses the text representation of IPv4 address.
+     * 
+     * @param ipStr string in <code>n.n.n.n</code> format.
+     * @return four bytes with parsed IP address
+     * @throws java.lang.NullPointerException if <code>ipStr</code> is null
+     * @throws java.lang.IllegalArgumentException if given string is not in
+     *  appropriate format
+     */
+    public static byte[] parseIpStr(String ipStr) {
+        StringTokenizer st;
+        byte[] b = new byte[4];
+        final String errMsg1 = "Given string is not in appropriate format"; 
+
+        if (ipStr != null) {
+            int k = 0;
+
+            st = new StringTokenizer(ipStr, ".");
+            while (st.hasMoreTokens()) {
+                String token = st.nextToken();
+                int n;
+
+                try {
+                    n = Integer.parseInt(token);
+                } catch (NumberFormatException e) {
+                    throw new IllegalArgumentException(errMsg1);
+                }
+                b[k++] = (byte) n;
+            }
+            if (k != 4) {
+                throw new IllegalArgumentException(errMsg1);
+            }
+        } else {
+            throw new NullPointerException(
+                    "Given string representation is null");
+        }
+        return b;
+    }
+
+    /**
+     * @param str string name of the DNS record class
+     * @return integer number for the class; <code>-1</code> if not found
+     */
+    public static int getRecordClassNumber(String str) {
+        for (int i = 0; i < ProviderConstants.rrClassNames.length; i++) {
+            if (ProviderConstants.rrClassNames[i] != null) {
+                if (str.equalsIgnoreCase(ProviderConstants.rrClassNames[i])) {
+                    return i;
+                }
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * @param str string name of the DNS record type
+     * @return integer number for the type; <code>-1</code> if not found
+     */
+    public static int getRecordTypeNumber(String str) {
+        for (int i = 0; i < ProviderConstants.rrTypeNames.length; i++) {
+            if (ProviderConstants.rrTypeNames[i] != null) {
+                if (str.equalsIgnoreCase(ProviderConstants.rrTypeNames[i])) {
+                    return i;
+                }
+            }
+        }
+        return -1;
+    }
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/ProviderMgr.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/QuestionRecord.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/QuestionRecord.java?rev=410240&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/QuestionRecord.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/QuestionRecord.java Tue May 30 04:24:59 2006
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Alexei Y. Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+
+package org.apache.harmony.jndi.provider.dns;
+
+
+/**
+ * Represents domain protocol Question Record
+ * 
+ * @author Alexei Zakharov
+ * @version $Revision: 1.1.2.4 $
+ * @see RFC 1035
+ */
+public class QuestionRecord {
+
+    /** domain name */
+    private String qName;
+
+    /** type of query */
+    private int qType;
+
+    /** class of query */
+    private int qClass;
+    
+    /** Empty constructor */
+    public QuestionRecord() {}
+
+    /**
+     * Constructs new question record with given parameters
+     * 
+     * @param qName domain name
+     * @param qType question record type
+     * @param qClass question record class
+     */
+    public QuestionRecord(
+            String qName,
+            int qType,
+            int qClass)
+    {
+        this.qName = qName;
+        this.qType = qType;
+        this.qClass = qClass;
+    }
+
+   
+    /**
+     * Creates a sequence of bytes that represents the current question record.
+     *  
+     * @param buffer the buffer in which the result byte sequence will be
+     *  written
+     * @param startIdx the index in the buffer to start at
+     * @return updated index of the buffer array
+     */
+    public int writeBytes(byte[] buffer, int startIdx)
+        throws DomainProtocolException
+    {
+        int idx = startIdx;
+
+        // basic checkings
+        if (buffer == null) {
+            throw new DomainProtocolException("buffer is null");
+        }
+        if (startIdx >= buffer.length || startIdx < 0) {
+            throw new ArrayIndexOutOfBoundsException();
+        }
+        // write the name
+        idx = ProviderMgr.writeName(qName, buffer, idx);
+        // QTYPE
+        idx = ProviderMgr.write16Int(qType, buffer, idx);
+        // QCLASS
+        idx = ProviderMgr.write16Int(qClass, buffer, idx);
+        return idx;
+    }
+    // getters and setters methods
+
+
+    /**
+     * Parses given sequence of bytes and constructs a question record from it.
+     * 
+     * @param mesBytes the byte array that should be parsed
+     * @param startIdx an index of <code>mesBytes</code> array to start the
+     *  parsing at
+     * @param resultQR an object the result of the operation will be stored into
+     * @return updated index of <code>mesBytes</code> array
+     * @throws DomainProtocolException if something went wrong
+     */
+    public static int parseRecord(byte[] mesBytes, int startIdx,
+            QuestionRecord resultQR) throws DomainProtocolException
+    {
+        int idx = startIdx;
+        StringBuffer nameSB = new StringBuffer();
+
+        if (resultQR == null) {
+            throw new NullPointerException("Given resultQR is null");
+        }
+        // name
+        idx = ProviderMgr.parseName(mesBytes, idx , nameSB);
+        resultQR.setQName(nameSB.toString());
+        // QTYPE
+        resultQR.setQType(ProviderMgr.parse16Int(mesBytes, idx));
+        idx += 2;
+        // QCLASS
+        resultQR.setQClass(ProviderMgr.parse16Int(mesBytes, idx));
+        idx += 2;
+        return idx;
+    }
+   
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+        String qClassStr, qTypeStr;
+
+        if (qType > 0 && qType < 256) {
+            qTypeStr = ProviderConstants.rrTypeNames[qType];
+        } else {
+            qTypeStr = String.valueOf(qType);
+        }
+        if (qClass > 0 && qClass < 256) {
+            qClassStr = ProviderConstants.rrClassNames[qClass];
+        } else {
+            qClassStr = String.valueOf(qClass);
+        }
+        sb.append(qClassStr);
+        sb.append(" ");
+        sb.append(qTypeStr);
+        sb.append(" ");
+        sb.append(qName);
+        return sb.toString();
+    }
+
+    /**
+     * @return Returns the qClass.
+     */
+    public int getQClass() {
+        return qClass;
+    }
+    /**
+     * @param class1 The qClass to set.
+     */
+    public void setQClass(int class1) {
+        qClass = class1;
+    }
+    /**
+     * @return Returns the qName.
+     */
+    public String getQName() {
+        return qName;
+    }
+    /**
+     * @param name The qName to set.
+     */
+    public void setQName(String name) {
+        qName = name;
+    }
+    /**
+     * @return Returns the qType.
+     */
+    public int getQType() {
+        return qType;
+    }
+    /**
+     * @param type The qType to set.
+     */
+    public void setQType(int type) {
+        qType = type;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/QuestionRecord.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message