harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r549955 [14/16] - in /harmony/enhanced/classlib/trunk/modules/jndi/src/main/java: javax/naming/ javax/naming/directory/ javax/naming/event/ javax/naming/ldap/ javax/naming/spi/ org/apache/harmony/jndi/internal/ org/apache/harmony/jndi/inter...
Date Fri, 22 Jun 2007 20:48:56 GMT
Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Resolver.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Resolver.java?view=diff&rev=549955&r1=549954&r2=549955
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Resolver.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/dns/Resolver.java Fri Jun 22 13:48:49 2007
@@ -42,10 +42,8 @@
 import org.apache.harmony.jndi.internal.nls.Messages;
 import org.apache.harmony.jndi.provider.dns.SList.Server;
 
-//import org.apache.harmony.util.logging.LogConst;
-
 /**
- * This class implements the functionality of a simple DNS resolver.<br> 
+ * This class implements the functionality of a simple DNS resolver.<br>
  * Following DNS Resource Records are supported:
  * <ul>
  * <li>A</li>
@@ -66,53 +64,57 @@
  * <li>HS (TODO)</li>
  * </ul>
  * <br>
- * @author Alexei Zakharov
- * @version $Revision: 1.1.2.5 $
- * TODO do we need broadcasting and IP multicasting to obtain initial name
- * server address?
- * TODO network-preference feature for choosing most welcome address 
- * for multihomed hosts (RFC 1123 point 6.1.3.4)
- * TODO add general IPv6 support and support for AAAA resource record 
+ * TODO: do we need broadcasting and IP multicasting to obtain initial name
+ * server address? TODO: network-preference feature for choosing most welcome
+ * address for multihomed hosts (RFC 1123 point 6.1.3.4) TODO: add general IPv6
+ * support and support for AAAA resource record
  */
 public class Resolver implements Runnable {
-    
+
     private static final int MSG_MAX_BYTES = 512;
+
     /**
      * Entry of the resolver thread list.
-     * @author Alexei Zakharov
      */
     private static class ThreadListEntry {
         Thread thread;
+
         String serverNameToResolve;
+
         int dnsClass;
     }
 
-    
     private static final Random rndGen = new Random();
 
     // resolver configuration
     private int initialTimeout;
+
     private int timeoutRetries;
+
     private boolean authoritativeAnswerDesired;
+
     private boolean recursionDesired;
+
     // maximum number of active threads
     private int threadNumberLimit;
-    
-    // vector with currently running Resolver threads 
+
+    // vector with currently running Resolver threads
     private final ArrayList<ThreadListEntry> resolverThreads = new ArrayList<ThreadListEntry>();
+
     // the list of host names that should be resolved
     private final ArrayList<ThreadListEntry> hostnamesToResolve = new ArrayList<ThreadListEntry>();
+
     // semaphore that controls access to both lists above
-    private class ThreadListSemaphore {}
+    private class ThreadListSemaphore {
+    }
+
     private final Object threadListSemaphore = new ThreadListSemaphore();
-    
-    // <---- Constructor's section
-    
-    /**
-     * Constructs a <code>Resolver</code> object with default initial
-     * timeout (1 second), default timeout retries (4 times), default 
-     * recursion desired switch (true) and default authoritative answer
-     * desired 
+
+    /**
+     * Constructs a <code>Resolver</code> object with default initial timeout
+     * (1 second), default timeout retries (4 times), default recursion desired
+     * switch (true) and default authoritative answer desired
+     * 
      * @see #Resolver(int, int)
      */
     public Resolver() {
@@ -122,30 +124,27 @@
                 ProviderConstants.DEFAULT_AUTHORITATIVE,
                 ProviderConstants.DEFAULT_RECURSION);
     }
-    
+
     /**
-     * Constructs a <code>Resolver</code> object with given initial
-     * timeout and timeout retries. Initially the resolver will try to access
-     * DNS servers with timeout set to initial timeout. If none of servers
-     * answer it will double the timeout and perform the second round. The
-     * process will continue for <code>timeoutRetries</code> rounds. If there
-     * is no answer still the resolver will give up.   
+     * Constructs a <code>Resolver</code> object with given initial timeout
+     * and timeout retries. Initially the resolver will try to access DNS
+     * servers with timeout set to initial timeout. If none of servers answer it
+     * will double the timeout and perform the second round. The process will
+     * continue for <code>timeoutRetries</code> rounds. If there is no answer
+     * still the resolver will give up.
      * 
-     * @param initialTimeout the initial timeout that is used during the
-     *  first round (in milliseconds)
-     * @param timeoutRetries number of rounds the Resolver should perform
-     *  before giving up 
-     * @param authoritativeAnswerDesired do we want to receive only
-     *  authoritative answers
-     * @param recursionDesired do we want our outgoing packages to have
-     * RD but set
-     */
-    public Resolver(int initialTimeout,
-                    int timeoutRetries,
-                    int maxThreads,
-                    boolean authoritativeAnswerDesired,
-                    boolean recursionDesired)
-    {
+     * @param initialTimeout
+     *            the initial timeout that is used during the first round (in
+     *            milliseconds)
+     * @param timeoutRetries
+     *            number of rounds the Resolver should perform before giving up
+     * @param authoritativeAnswerDesired
+     *            do we want to receive only authoritative answers
+     * @param recursionDesired
+     *            do we want our outgoing packages to have RD but set
+     */
+    public Resolver(int initialTimeout, int timeoutRetries, int maxThreads,
+            boolean authoritativeAnswerDesired, boolean recursionDesired) {
         this.initialTimeout = initialTimeout;
         this.timeoutRetries = timeoutRetries;
         this.threadNumberLimit = maxThreads;
@@ -159,121 +158,133 @@
     public int getThreadNumberLimit() {
         return threadNumberLimit;
     }
+
     /**
-     * @param threadNumberLimit The threadNumberLimit to set.
+     * @param threadNumberLimit
+     *            The threadNumberLimit to set.
      */
     public void setThreadNumberLimit(int threadNumberLimit) {
         this.threadNumberLimit = threadNumberLimit;
     }
+
     /**
      * @return Returns the authoritativeAnswerDesired.
      */
     public boolean isAuthoritativeAnswerDesired() {
         return authoritativeAnswerDesired;
     }
+
     /**
-     * @param authoritativeAnswerDesired The authoritativeAnswerDesired to set.
+     * @param authoritativeAnswerDesired
+     *            The authoritativeAnswerDesired to set.
      */
-    public void setAuthoritativeAnswerDesired(
-            boolean authoritativeAnswerDesired) {
+    public void setAuthoritativeAnswerDesired(boolean authoritativeAnswerDesired) {
         this.authoritativeAnswerDesired = authoritativeAnswerDesired;
     }
+
     /**
      * @return Returns the initialTimeout.
      */
     public int getInitialTimeout() {
         return initialTimeout;
     }
+
     /**
-     * @param initialTimeout The initialTimeout to set.
+     * @param initialTimeout
+     *            The initialTimeout to set.
      */
     public void setInitialTimeout(int initialTimeout) {
         this.initialTimeout = initialTimeout;
     }
+
     /**
      * @return Returns the recursionDesired.
      */
     public boolean isRecursionDesired() {
         return recursionDesired;
     }
+
     /**
-     * @param recursionDesired The recursionDesired to set.
+     * @param recursionDesired
+     *            The recursionDesired to set.
      */
     public void setRecursionDesired(boolean recursionDesired) {
         this.recursionDesired = recursionDesired;
     }
+
     /**
      * @return Returns the timeoutRetries.
      */
     public int getTimeoutRetries() {
         return timeoutRetries;
     }
+
     /**
-     * @param timeoutRetries The timeoutRetries to set.
+     * @param timeoutRetries
+     *            The timeoutRetries to set.
      */
     public void setTimeoutRetries(int timeoutRetries) {
         this.timeoutRetries = timeoutRetries;
     }
-    
-    // <---- End of constructor's section
-    
+
     /**
      * Checks available name servers if they have any resource records related
      * to given name & type & class combination. Standard DNS lookup algorithm
-     * is used.  
-     *
-     * @param name well-formed domain name
-     * @param types an array of types; only records that have such types will
-     *  be returned
+     * is used.
+     * 
+     * @param name
+     *            well-formed domain name
+     * @param types
+     *            an array of types; only records that have such types will be
+     *            returned
      * @param classes
      * @return enumeration with found resource records
-     * @throws SecurityException if the resolver is not allowed to use a
-     *  network subsystem
-     * @throws NameNotFoundException if authoritative server for desired
-     * zone was contacted but given name has not been found in that zone
-     * @throws ServiceUnavailableException if no authoritative server for
-     * desired name was found or all servers are dead or malfunction   
-     * @throws DomainProtocolException if some DNS specific error has occured 
-     */
-    public Enumeration<ResourceRecord> lookup(String name, int[] types, int[] classes)
-           throws SecurityException,
-                  NameNotFoundException,
-                  ServiceUnavailableException,
-                  DomainProtocolException
-    {
-                
+     * @throws SecurityException
+     *             if the resolver is not allowed to use a network subsystem
+     * @throws NameNotFoundException
+     *             if authoritative server for desired zone was contacted but
+     *             given name has not been found in that zone
+     * @throws ServiceUnavailableException
+     *             if no authoritative server for desired name was found or all
+     *             servers are dead or malfunction
+     * @throws DomainProtocolException
+     *             if some DNS specific error has occurred
+     */
+    public Enumeration<ResourceRecord> lookup(String name, int[] types,
+            int[] classes) throws SecurityException, NameNotFoundException,
+            ServiceUnavailableException, DomainProtocolException {
+
         // Algorithm:
-        //  1. Set workZone to the parent of qName; clear queriedServers. 
-        //  2. Try to get a complete answer for the workZone from the servers
-        //   currently available in SLIST exclude servers from queriedServers.
-        //  3. update queriedServers with "visited servers" info.
-        //  4. If the complete answer was received - return it to the user;exit.
-        //  5. If the delegation was received:
-        //    a) If we already have this server & zone pair in SLIST - skip it.
-        //    b) If we don't have - put it into SLIST
-        //    c) If we haven't received any new delegations - goto step (7)
-        //    d) If some new delegation has been received:
-        //      1) from delegations: found the zone with the best matching count
-        //       with qName
-        //      2) if this matching count is bigger than matching count between
-        //       workZone and qName:
-        //        - set workZone to zone with biggest matching count determined
-        //           at step (5.d.1)
-        //        - goto step (2)
-        //      3) if it doesn't then goto step 2 with the same workZone
-        //  6. If ALIAS was received ...
-        //  7. If no answer has been received:
-        //    a) Check if the  workZone is the root zone.
-        //    b) If so - give up; return empty result to the user.
-        //    c) If it isn't, set workZone to parent of workZone. Goto step (2).
+        // 1. Set workZone to the parent of qName; clear queriedServers.
+        // 2. Try to get a complete answer for the workZone from the servers
+        // currently available in SLIST exclude servers from queriedServers.
+        // 3. update queriedServers with "visited servers" info.
+        // 4. If the complete answer was received - return it to the user;exit.
+        // 5. If the delegation was received:
+        // a) If we already have this server & zone pair in SLIST - skip it.
+        // b) If we don't have - put it into SLIST
+        // c) If we haven't received any new delegations - goto step (7)
+        // d) If some new delegation has been received:
+        // 1) from delegations: found the zone with the best matching count
+        // with qName
+        // 2) if this matching count is bigger than matching count between
+        // workZone and qName:
+        // - set workZone to zone with biggest matching count determined
+        // at step (5.d.1)
+        // - goto step (2)
+        // 3) if it doesn't then goto step 2 with the same workZone
+        // 6. If ALIAS was received ...
+        // 7. If no answer has been received:
+        // a) Check if the workZone is the root zone.
+        // b) If so - give up; return empty result to the user.
+        // c) If it isn't, set workZone to parent of workZone. Goto step (2).
 
-        //SList slist = SList.getInstance();
+        // SList slist = SList.getInstance();
         ResolverCache cache = ResolverCache.getInstance();
-        
+
         Vector<QuestionRecord> questions = new Vector<QuestionRecord>();
-        Vector<ResourceRecord> answers = new Vector<ResourceRecord>(); 
+        Vector<ResourceRecord> answers = new Vector<ResourceRecord>();
 
-        
         if (name == null) {
             // jndi.2E=The name is null
             throw new NullPointerException(Messages.getString("jndi.2E")); //$NON-NLS-1$
@@ -295,8 +306,7 @@
         }
         // iterate over question records
         for (int i = 0; i < questions.size(); i++) {
-            QuestionRecord curQuestion =
-                    questions.elementAt(i);
+            QuestionRecord curQuestion = questions.elementAt(i);
             String qName = curQuestion.getQName();
             Message mesToSend = null;
             Message receivedMes = null;
@@ -304,14 +314,13 @@
             String workZone;
             Hashtable<Server, Object> visitedServers = new Hashtable<Server, Object>();
 
-            //if (LogConst.DEBUG) {
-            //    ProviderMgr.logger.fine("Current question: " +
-            //            curQuestion.toString());
-            //}
+            // if (LogConst.DEBUG) {
+            // ProviderMgr.logger.fine("Current question: " +
+            // curQuestion.toString());
+            // }
             // look in cache
-            if (curQuestion.getQType() != ProviderConstants.ANY_QTYPE &&
-                    curQuestion.getQClass() != ProviderConstants.ANY_QCLASS)
-            {
+            if (curQuestion.getQType() != ProviderConstants.ANY_QTYPE
+                    && curQuestion.getQClass() != ProviderConstants.ANY_QCLASS) {
                 Enumeration<ResourceRecord> recEnum = cache.get(curQuestion);
 
                 if (recEnum.hasMoreElements()) {
@@ -320,38 +329,38 @@
                     }
                     // we don't need to query any servers since the information
                     // we want has been found in the local cache
-                    //if (LogConst.DEBUG) {
-                    //    ProviderMgr.logger.fine(
-                    //            "Information was gathered from cache");
-                    //}
+                    // if (LogConst.DEBUG) {
+                    // ProviderMgr.logger.fine(
+                    // "Information was gathered from cache");
+                    // }
                     continue;
                 }
             }
 
             // query remote DNS servers
 
-            // determine work zone 
+            // determine work zone
             if (qName != null && !qName.equals(".")) { //$NON-NLS-1$
                 workZone = qName;
-                // support for SRV-style qNames 
+                // support for SRV-style qNames
                 while (workZone.startsWith("_")) { //$NON-NLS-1$
                     workZone = ProviderMgr.getParentName(workZone);
                 }
             } else {
                 workZone = "."; //$NON-NLS-1$
             }
-            //if (LogConst.DEBUG) {
-            //    ProviderMgr.logger.fine("Lookup: new workZone is " +
-            //            "\"" + workZone + "\"");
-            //}
+            // if (LogConst.DEBUG) {
+            // ProviderMgr.logger.fine("Lookup: new workZone is " +
+            // "\"" + workZone + "\"");
+            // }
             // construct request message
             try {
-                mesToSend = createMessageForSending(qName,
-                        curQuestion.getQType(), curQuestion.getQClass());
-                //if (LogConst.DEBUG) {
-                //    ProviderMgr.logger.finest("Message to send:\n" +
-                //            mesToSend.toString());
-                //}
+                mesToSend = createMessageForSending(qName, curQuestion
+                        .getQType(), curQuestion.getQClass());
+                // if (LogConst.DEBUG) {
+                // ProviderMgr.logger.finest("Message to send:\n" +
+                // mesToSend.toString());
+                // }
 
             } catch (DomainProtocolException e) {
                 throw e;
@@ -367,15 +376,13 @@
                         if (!report.messageWasTruncated) {
                             // Put all extra records into the cache for
                             // future use
-                            for (int k = 0; k < report.extraRecords.size();
-                                     k++)
-                            {
-                                ResourceRecord rec = report.extraRecords.elementAt(k);
-    
+                            for (int k = 0; k < report.extraRecords.size(); k++) {
+                                ResourceRecord rec = report.extraRecords
+                                        .elementAt(k);
+
                                 cache.put(rec);
                             }
-                        }
-                        else {
+                        } else {
                             // Truncated message MUST NOT be cached and later
                             // used in such a way that the fact that they are
                             // truncated is lost (RFC 1123 point 6.1.3.2).
@@ -383,12 +390,13 @@
                         // examine the report
                         if (report.completeAnswerWasReceived) {
                             // complete answer
-                            //if (LogConst.DEBUG) {
-                            //    ProviderMgr.logger.fine(
-                            //          "Lookup: a complete answer was received");
-                            //}
+                            // if (LogConst.DEBUG) {
+                            // ProviderMgr.logger.fine(
+                            // "Lookup: a complete answer was received");
+                            // }
                             for (int k = 0; k < report.records.size(); k++) {
-                                ResourceRecord rec = report.records.elementAt(k); 
+                                ResourceRecord rec = report.records
+                                        .elementAt(k);
                                 answers.addElement(rec);
                                 // we are sure that the answer section has not
                                 // been truncated so we can put the record
@@ -397,37 +405,35 @@
                             }
                             // exit the loop
                             break;
-                        }
-                        else if (report.nameError) {
+                        } else if (report.nameError) {
                             // name error
-                            //if (LogConst.DEBUG) {                            
-                            //    ProviderMgr.logger.fine("Lookup: name error");
-                            //}
+                            // if (LogConst.DEBUG) {
+                            // ProviderMgr.logger.fine("Lookup: name error");
+                            // }
                             // jndi.6D=Name {0} was not found
-                            throw new NameNotFoundException(Messages.getString("jndi.6D", name)); //$NON-NLS-1$
-                        }
-                        else if (report.aliasInfoWasReceived) {
+                            throw new NameNotFoundException(Messages.getString(
+                                    "jndi.6D", name)); //$NON-NLS-1$
+                        } else if (report.aliasInfoWasReceived) {
                             // alias received
-                            //QuestionRecord newQuestion = new QuestionRecord();
+                            // QuestionRecord newQuestion = new
+                            // QuestionRecord();
 
-                            //if (LogConst.DEBUG) {                            
-                            //    ProviderMgr.logger.fine(
-                            //            "Lookup: an alias was received");
-                            //}                           
+                            // if (LogConst.DEBUG) {
+                            // ProviderMgr.logger.fine(
+                            // "Lookup: an alias was received");
+                            // }
                             qName = report.newName;
                             curQuestion.setQName(qName);
                             // look in cache
-                            if (curQuestion.getQType() !=
-                                        ProviderConstants.ANY_QTYPE &&
-                                curQuestion.getQClass() !=
-                                        ProviderConstants.ANY_QCLASS)
-                            {
-                                Enumeration<ResourceRecord> recEnum = cache.get(curQuestion);
+                            if (curQuestion.getQType() != ProviderConstants.ANY_QTYPE
+                                    && curQuestion.getQClass() != ProviderConstants.ANY_QCLASS) {
+                                Enumeration<ResourceRecord> recEnum = cache
+                                        .get(curQuestion);
 
                                 if (recEnum.hasMoreElements()) {
                                     while (recEnum.hasMoreElements()) {
-                                        answers.addElement(
-                                                recEnum.nextElement());
+                                        answers.addElement(recEnum
+                                                .nextElement());
                                     }
                                     // We don't need to query any more servers
                                     // since the information we want has been
@@ -439,8 +445,7 @@
                             if (qName != null && !qName.equals(".")) //$NON-NLS-1$
                             {
                                 workZone = qName;
-                            }
-                            else {
+                            } else {
                                 workZone = "."; //$NON-NLS-1$
                             }
                             visitedServers = new Hashtable<Server, Object>();
@@ -450,57 +455,54 @@
                             // construct a new request message
                             try {
                                 mesToSend = createMessageForSending(qName,
-                                            curQuestion.getQType(),
-                                            curQuestion.getQClass());
+                                        curQuestion.getQType(), curQuestion
+                                                .getQClass());
                             } catch (DomainProtocolException e) {
                                 throw e;
                             }
-                            //if (LogConst.DEBUG) {                            
-                            //    ProviderMgr.logger.fine("Lookup: new name is " +
-                            //            "\"" + qName + "\"");
-                            //    ProviderMgr.logger.fine(
-                            //            "Lookup: new workZone is " +
-                            //            "\"" + workZone + "\"");
-                            //}
-                        }
-                        else if (report.delegationArrived) {
+                            // if (LogConst.DEBUG) {
+                            // ProviderMgr.logger.fine("Lookup: new name is " +
+                            // "\"" + qName + "\"");
+                            // ProviderMgr.logger.fine(
+                            // "Lookup: new workZone is " +
+                            // "\"" + workZone + "\"");
+                            // }
+                        } else if (report.delegationArrived) {
                             // new delegation, probably need to query once again
                             int k17 = -1;
                             int matchingCount = ProviderMgr.getMatchingCount(
                                     qName, workZone);
 
-                            //if (LogConst.DEBUG) {                            
-                            //    ProviderMgr.logger.fine(
-                            //            "Lookup: delegation arrived");
-                            //}
-                            for (int k = 0; k < report.delegationZones.size();
-                                    k++)
-                            {
-                                String curZone = report.delegationZones.elementAt(k);
-                                int tmpMatchingCount = ProviderMgr.
-                                        getMatchingCount(qName, curZone);
-    
+                            // if (LogConst.DEBUG) {
+                            // ProviderMgr.logger.fine(
+                            // "Lookup: delegation arrived");
+                            // }
+                            for (int k = 0; k < report.delegationZones.size(); k++) {
+                                String curZone = report.delegationZones
+                                        .elementAt(k);
+                                int tmpMatchingCount = ProviderMgr
+                                        .getMatchingCount(qName, curZone);
+
                                 if (tmpMatchingCount > matchingCount) {
                                     k17 = k;
                                     matchingCount = tmpMatchingCount;
                                 }
-                                
+
                             }
                             if (k17 != -1) {
                                 // better delegation was received
-                                workZone = report.delegationZones.elementAt(k17);
-                                //if (LogConst.DEBUG) {                            
-                                //    ProviderMgr.logger.fine(
-                                //         "Lookup: better delegation was found");
-                                //}
-                            }
-                            else {
+                                workZone = report.delegationZones
+                                        .elementAt(k17);
+                                // if (LogConst.DEBUG) {
+                                // ProviderMgr.logger.fine(
+                                // "Lookup: better delegation was found");
+                                // }
+                            } else {
                                 // no better delegation
                                 // do nothing, just query the next server of
-                                // the current workZone 
+                                // the current workZone
                             }
-                        }
-                        else {
+                        } else {
                             noIdea = true;
                         }
                     } // end of if report != null block
@@ -508,36 +510,33 @@
                         noIdea = true;
                     }
                     if (noIdea) {
-                        // Resolver has no idea how to get info about 
+                        // Resolver has no idea how to get info about
                         // desired host while querying master hosts of the
                         // current workZone.
                         // Let's make one step up to the root.
-                        //if (LogConst.DEBUG) {                            
-                        //    ProviderMgr.logger.fine("Lookup: no idea");
-                        //}
+                        // if (LogConst.DEBUG) {
+                        // ProviderMgr.logger.fine("Lookup: no idea");
+                        // }
                         if (!workZone.equals(".")) { //$NON-NLS-1$
                             workZone = ProviderMgr.getParentName(workZone);
-                            //if (LogConst.DEBUG) {                            
-                            //    ProviderMgr.logger.fine(
-                            //            "Lookup: new work zone is " +
-                            //            "\"" + workZone + "\"");
-                            //}
-                        }
-                        else {
+                            // if (LogConst.DEBUG) {
+                            // ProviderMgr.logger.fine(
+                            // "Lookup: new work zone is " +
+                            // "\"" + workZone + "\"");
+                            // }
+                        } else {
                             // give up
                             break;
-                            //throw new ServiceUnavailableException(
-                            //        "Unable to " +
-                            //        "contact authoritative server for " +
-                            //        qName +
-                            //        " and no other results were found");
+                            // throw new ServiceUnavailableException(
+                            // "Unable to " +
+                            // "contact authoritative server for " +
+                            // qName +
+                            // " and no other results were found");
                         }
                     }
-                }
-                catch (NameNotFoundException e) {
+                } catch (NameNotFoundException e) {
                     throw e;
-                }
-                catch (DomainProtocolException e) {
+                } catch (DomainProtocolException e) {
                     throw e;
                 }
             } // query servers loop
@@ -549,25 +548,28 @@
     /**
      * Lists entire DNS zone using zone transfer mechanism.
      * 
-     * @param name DNS zone name
+     * @param name
+     *            DNS zone name
      * @return enumeration with found <code>ResourceRecord</code> objects
-     * @throws SecurityException if the resolver is not allowed to use a
-     *  network subsystem
-     * @throws NameNotFoundException if authoritative server(s) was not found
-     * @throws ServiceUnavailableException if none of found servers permits zone
-     * transfers   
-     * @throws DomainProtocolException if some DNS specific error has occured 
+     * @throws SecurityException
+     *             if the resolver is not allowed to use a network subsystem
+     * @throws NameNotFoundException
+     *             if authoritative server(s) was not found
+     * @throws ServiceUnavailableException
+     *             if none of found servers permits zone transfers
+     * @throws DomainProtocolException
+     *             if some DNS specific error has occured
      */
     public Enumeration<ResourceRecord> list(String name) throws NamingException {
         final int OUT_BUF_SIZE = 512;
         final int IN_BUF_SIZE = 65536;
-        
-        Vector<ResourceRecord> answerVect = new Vector<ResourceRecord>(); 
+
+        Vector<ResourceRecord> answerVect = new Vector<ResourceRecord>();
         Message mesToSend = null;
         Message receivedMes = null;
         Enumeration<ResourceRecord> enum1;
-        //String zoneMasterServer = null;
-        //Vector authoritativeServerIPs = new Vector();
+        // String zoneMasterServer = null;
+        // Vector authoritativeServerIPs = new Vector();
         HashSet<Object> authoritativeServers = new HashSet<Object>();
         Iterator<Object> authServersIter;
         int qClassArr[] = new int[1];
@@ -579,13 +581,13 @@
         String proto = null;
 
         ResolverCache cache = ResolverCache.getInstance();
-        //SList slist = SList.getInstance();
-        
+        // SList slist = SList.getInstance();
+
         if (name == null) {
             // jndi.2E=The name is null
             throw new NullPointerException(Messages.getString("jndi.2E")); //$NON-NLS-1$
         }
-        // if given name is SRV style name where domain name is prefixed 
+        // if given name is SRV style name where domain name is prefixed
         // with _Proto
         if (name.startsWith("_")) { //$NON-NLS-1$
             int n = name.indexOf('.');
@@ -603,10 +605,10 @@
                 name = "."; //$NON-NLS-1$
             }
         }
-        enum1 = lookup(name, new int[] {ProviderConstants.NS_TYPE}, 
-                new int[] {ProviderConstants.ANY_QTYPE} );
-        mesToSend = createMessageForSending(name,
-                ProviderConstants.AXFR_QTYPE, ProviderConstants.ANY_QCLASS);
+        enum1 = lookup(name, new int[] { ProviderConstants.NS_TYPE },
+                new int[] { ProviderConstants.ANY_QTYPE });
+        mesToSend = createMessageForSending(name, ProviderConstants.AXFR_QTYPE,
+                ProviderConstants.ANY_QCLASS);
         outLen = mesToSend.writeBytes(outBuf, 0);
         // determine the list of zone authoritative servers
         while (enum1.hasMoreElements()) {
@@ -630,98 +632,100 @@
         }
         // try to perform a zone transfer
         authServersIter = authoritativeServers.iterator();
-      authServersLoop:
-        while (authServersIter.hasNext()) {
+        authServersLoop: while (authServersIter.hasNext()) {
             String authServerName = (String) authServersIter.next();
             Enumeration<ResourceRecord> addrEnum = lookup(authServerName,
-                    new int[] {ProviderConstants.A_TYPE}, qClassArr);
-            
+                    new int[] { ProviderConstants.A_TYPE }, qClassArr);
+
             while (addrEnum.hasMoreElements()) {
                 ResourceRecord curRR = addrEnum.nextElement();
                 String ip = (String) curRR.getRData();
 
                 try {
-                    //if (LogConst.DEBUG) {                            
-                    //    ProviderMgr.logger.fine(
-                    //            "Initiating zone transfer, IP=" + ip);
-                    //}
+                    // if (LogConst.DEBUG) {
+                    // ProviderMgr.logger.fine(
+                    // "Initiating zone transfer, IP=" + ip);
+                    // }
                     TransportMgr.sendReceiveTCP(ip,
-                            ProviderConstants.DEFAULT_DNS_PORT,
-                            outBuf, outLen, inBuf, IN_BUF_SIZE,
-                            this.initialTimeout * this.timeoutRetries);
+                            ProviderConstants.DEFAULT_DNS_PORT, outBuf, outLen,
+                            inBuf, IN_BUF_SIZE, this.initialTimeout
+                                    * this.timeoutRetries);
                     received = true;
                 } catch (SocketTimeoutException e) {
-                    
-                    //if (LogConst.DEBUG) {                            
-                    //    ProviderMgr.logger.fine("Socket timeout");
-                    //}
+
+                    // if (LogConst.DEBUG) {
+                    // ProviderMgr.logger.fine("Socket timeout");
+                    // }
                 } catch (DomainProtocolException e) {
                     // some problem was encountered
-                    //ProviderMgr.logger.log(Level.WARNING,
-                    //        "Connection failure", e);
+                    // ProviderMgr.logger.log(Level.WARNING,
+                    // "Connection failure", e);
                 }
                 if (received) {
                     receivedMes = new Message();
                     try {
                         int rCode;
-    
+
                         Message.parseMessage(inBuf, 0, receivedMes);
                         rCode = receivedMes.getRCode();
                         switch (rCode) {
-                        case ProviderConstants.NO_ERROR:
-                            // put all received records into Resolver's cache
-                            for (int k = 0; k < 3; k++) {
-                                switch (k) {
-                                case 0:
-                                    enum1 = receivedMes.getAnswerRRs();
-                                    break;
-                                case 1:
-                                    enum1 = receivedMes.getAuthorityRRs();
-                                    break;
-                                case 2:
-                                    enum1 = receivedMes.getAdditionalRRs();
-                                    break;
-                                }
-                                while (enum1.hasMoreElements()) {
-                                    ResourceRecord rr = enum1.nextElement();
-    
-                                    cache.put(rr);
-                                    if (k == 0) {
-                                        answerVect.addElement(rr);
+                            case ProviderConstants.NO_ERROR:
+                                // put all received records into Resolver's
+                                // cache
+                                for (int k = 0; k < 3; k++) {
+                                    switch (k) {
+                                        case 0:
+                                            enum1 = receivedMes.getAnswerRRs();
+                                            break;
+                                        case 1:
+                                            enum1 = receivedMes
+                                                    .getAuthorityRRs();
+                                            break;
+                                        case 2:
+                                            enum1 = receivedMes
+                                                    .getAdditionalRRs();
+                                            break;
+                                    }
+                                    while (enum1.hasMoreElements()) {
+                                        ResourceRecord rr = enum1.nextElement();
+
+                                        cache.put(rr);
+                                        if (k == 0) {
+                                            answerVect.addElement(rr);
+                                        }
                                     }
                                 }
-                            }
-                            completeAnswer = true;
-                            break;
-                        case ProviderConstants.NAME_ERROR:
-                            // jndi.6D=Name {0} was not found
-                            throw new NameNotFoundException(Messages.getString("jndi.6D", name)); //$NON-NLS-1$
-                        case ProviderConstants.SERVER_FAILURE:
-                        case ProviderConstants.FORMAT_ERROR:
-                        case ProviderConstants.NOT_IMPLEMENTED:
-                        case ProviderConstants.REFUSED:        
-                        default:
+                                completeAnswer = true;
+                                break;
+                            case ProviderConstants.NAME_ERROR:
+                                // jndi.6D=Name {0} was not found
+                                throw new NameNotFoundException(Messages
+                                        .getString("jndi.6D", name)); //$NON-NLS-1$
+                            case ProviderConstants.SERVER_FAILURE:
+                            case ProviderConstants.FORMAT_ERROR:
+                            case ProviderConstants.NOT_IMPLEMENTED:
+                            case ProviderConstants.REFUSED:
+                            default:
                         }
                     } catch (DomainProtocolException e) {
-                        //ProviderMgr.logger.log(Level.WARNING,
-                        //        "Error while parsing of DNS message", e);
-                    }    
+                        // ProviderMgr.logger.log(Level.WARNING,
+                        // "Error while parsing of DNS message", e);
+                    }
                 } // if received
                 if (completeAnswer) {
-                    //if (LogConst.DEBUG) {                            
-                    //    ProviderMgr.logger.fine(
-                    //            "list: Complete answer received");
-                    //}
+                    // if (LogConst.DEBUG) {
+                    // ProviderMgr.logger.fine(
+                    // "list: Complete answer received");
+                    // }
                     break authServersLoop;
                 }
-            } // address loop 
+            } // address loop
         } // authoritative servers loop
-        
+
         if (!completeAnswer) {
             // found nothing
             // jndi.6E=Unable to perform zone transfer
-            throw new ServiceUnavailableException(
-                    Messages.getString("jndi.6E")); //$NON-NLS-1$
+            throw new ServiceUnavailableException(Messages.getString("jndi.6E")); //$NON-NLS-1$
         }
         // SRV _Proto prefix support - filter all records that don't have given
         // _Proto field
@@ -730,16 +734,14 @@
 
             for (int i = 0; i < answerVect.size(); i++) {
                 ResourceRecord rr = answerVect.elementAt(i);
-                StringTokenizer st = new StringTokenizer(rr.getName(),
-                        "."); //$NON-NLS-1$
+                StringTokenizer st = new StringTokenizer(rr.getName(), "."); //$NON-NLS-1$
                 String token = null;
                 boolean valid = false;
 
                 if (st.hasMoreTokens()) {
                     token = st.nextToken();
-                    if (token.length() > 0 && token.charAt(0) == '_' &&
-                            st.hasMoreTokens())
-                    {
+                    if (token.length() > 0 && token.charAt(0) == '_'
+                            && st.hasMoreTokens()) {
                         token = st.nextToken();
                         if (token.equalsIgnoreCase(proto)) {
                             valid = true;
@@ -759,13 +761,15 @@
      * Adds initial DNS server the resolver should start with. Trying underlying
      * OS services to determine IP from name.
      * 
-     * @param name server's name
-     * @param ip server's IP address
-     * @param port port on server
+     * @param name
+     *            server's name
+     * @param ip
+     *            server's IP address
+     * @param port
+     *            port on server
      */
     public void addInitialServer(String name, String ip, int port,
-            String zoneName)
-    {
+            String zoneName) {
         SList.Server server = new SList.Server(name, ip, port);
         SList slist = SList.getInstance();
 
@@ -795,26 +799,29 @@
     /**
      * Query available DNS servers for desired information. This method doesn't
      * look into the local cache. Drops all answers that contains "server fail"
-     * and "not implemented" answer codes and returns the first "good" answer. 
+     * and "not implemented" answer codes and returns the first "good" answer.
      * 
-     * @param request a DNS message that contains the request record  
-     * @param workZone a zone that is closest known (grand-) parent of the
-     *  desired name
-     * @param visitedServers the hash list of servers, that should not be
-     *  examined; this method also appends to this list all server that have
-     *  been visited during execution of this method 
-     * @param tcpOnly <code>true</code> if we want to use TCP protocol only;
-     * otherwise UDP will be tried first
+     * @param request
+     *            a DNS message that contains the request record
+     * @param workZone
+     *            a zone that is closest known (grand-) parent of the desired
+     *            name
+     * @param visitedServers
+     *            the hash list of servers, that should not be examined; this
+     *            method also appends to this list all server that have been
+     *            visited during execution of this method
+     * @param tcpOnly
+     *            <code>true</code> if we want to use TCP protocol only;
+     *            otherwise UDP will be tried first
      * @return the message received; <code>null</code> if none found
-     * @throws DomainProtocolException some domain protocol related error
-     *  occured
-     * @throws SecurityException if the resolver doesn't have the permission 
-     *  to use sockets
+     * @throws DomainProtocolException
+     *             some domain protocol related error occured
+     * @throws SecurityException
+     *             if the resolver doesn't have the permission to use sockets
      */
     Message queryServers(Message request, String workZone,
             Hashtable<Server, Object> visitedServers, boolean tcpOnly)
-            throws DomainProtocolException, SecurityException
-    {
+            throws DomainProtocolException, SecurityException {
         QuestionRecord qRecord;
 
         SList slist = SList.getInstance();
@@ -830,7 +837,6 @@
         boolean correctAnswer = false;
         int rCode = -1;
 
-      
         // determine a question
         if (!request.getQuestionRecords().hasMoreElements()) {
             // jndi.71=no question record
@@ -860,8 +866,8 @@
                 if (curServer.getIP() == null) {
                     // if we don't know IP lets start background resolving
                     // thread
-                    startResolvingThread(curServer.getName(),
-                            qRecord.getQClass());
+                    startResolvingThread(curServer.getName(), qRecord
+                            .getQClass());
                     slist.updateEntry(workZone, curServer,
                             SList.NETWORK_FAILURE);
                     queriedServers.add(curServer);
@@ -869,43 +875,39 @@
                 }
                 // send the message and receive the answer
                 try {
-                    //if (LogConst.DEBUG) {                            
-                    //    ProviderMgr.logger.fine("Timeout is set to " +
-                    //            curTimeout);
-                    //    ProviderMgr.logger.fine("Querying server \"" +
-                    //            curServer + "\"");
-                    //}
-                    //timeBeforeSending = System.currentTimeMillis();
+                    // if (LogConst.DEBUG) {
+                    // ProviderMgr.logger.fine("Timeout is set to " +
+                    // curTimeout);
+                    // ProviderMgr.logger.fine("Querying server \"" +
+                    // curServer + "\"");
+                    // }
+                    // timeBeforeSending = System.currentTimeMillis();
                     if (tcpOnly) {
                         TransportMgr.sendReceiveTCP(curServer.getIP(),
-                                curServer.getPort(),
-                                outBuf, outBufLen,
-                                inBuf, inBuf.length,
-                                curTimeout);
+                                curServer.getPort(), outBuf, outBufLen, inBuf,
+                                inBuf.length, curTimeout);
                     } else {
                         TransportMgr.sendReceiveUDP(curServer.getIP(),
-                                curServer.getPort(),
-                                outBuf, outBufLen,
-                                inBuf, inBuf.length,
-                                curTimeout);
+                                curServer.getPort(), outBuf, outBufLen, inBuf,
+                                inBuf.length, curTimeout);
                     }
-                    //responseTime = (int) (System.currentTimeMillis() -
-                    //        timeBeforeSending);
-                    //ProviderMgr.logger.fine("Answer received in " +
-                    //        responseTime + " milliseconds");
+                    // responseTime = (int) (System.currentTimeMillis() -
+                    // timeBeforeSending);
+                    // ProviderMgr.logger.fine("Answer received in " +
+                    // responseTime + " milliseconds");
                     received = true;
                 } catch (SocketTimeoutException e) {
                     slist.updateEntry(workZone, curServer, SList.TIMEOUT);
-                    //if (LogConst.DEBUG) {                            
-                    //    ProviderMgr.logger.fine("Socket timeout");
-                    //}
+                    // if (LogConst.DEBUG) {
+                    // ProviderMgr.logger.fine("Socket timeout");
+                    // }
                 } catch (DomainProtocolException e) {
                     // problems with receiving the message
                     // skipping this server
                     slist.updateEntry(workZone, curServer,
                             SList.NETWORK_FAILURE);
-                    //ProviderMgr.logger.log(Level.WARNING,
-                    //        "Connection failure", e);
+                    // ProviderMgr.logger.log(Level.WARNING,
+                    // "Connection failure", e);
                 }
                 // parse the message
                 if (received) {
@@ -916,31 +918,28 @@
                         idx = 0;
                         idx = Message.parseMessage(inBuf, idx, receivedMes);
 
-                        //if (LogConst.DEBUG) {                            
-                        //    ProviderMgr.logger.finest("Received message:\n" +
-                        //            receivedMes.toString());
-                        //}
+                        // if (LogConst.DEBUG) {
+                        // ProviderMgr.logger.finest("Received message:\n" +
+                        // receivedMes.toString());
+                        // }
                         parsed = true;
                         // handle a truncation
                         if (receivedMes.isTc() && !tcpOnly) {
                             // The Message is truncated.
-                            // Let's try to establish a TCP connection 
+                            // Let's try to establish a TCP connection
                             // and retransmit the message over that connection.
-                            //if (LogConst.DEBUG) {                            
-                            //    ProviderMgr.logger.fine("Message is truncated");
-                            //    ProviderMgr.logger.fine("Trying to establish " +
-                            //            "a connection over TCP");
-                            //}
+                            // if (LogConst.DEBUG) {
+                            // ProviderMgr.logger.fine("Message is truncated");
+                            // ProviderMgr.logger.fine("Trying to establish " +
+                            // "a connection over TCP");
+                            // }
                             try {
                                 Message receivedMesTcp;
                                 int idx2;
 
-                                TransportMgr.sendReceiveTCP(
-                                        curServer.getIP(),
-                                        curServer.getPort(),
-                                        outBuf, outBufLen,
-                                        inBuf, inBuf.length,
-                                        curTimeout);
+                                TransportMgr.sendReceiveTCP(curServer.getIP(),
+                                        curServer.getPort(), outBuf, outBufLen,
+                                        inBuf, inBuf.length, curTimeout);
                                 receivedMesTcp = new Message();
                                 idx2 = Message.parseMessage(inBuf, 0,
                                         receivedMesTcp);
@@ -950,15 +949,15 @@
                                     idx = idx2;
                                 }
                             } catch (Exception e) {
-                                //ProviderMgr.logger.log(Level.WARNING,
-                                //        "Receiving a complete message" +
-                                //        " over TCP failed", e);
-                                //if (LogConst.DEBUG) {                            
-                                //    ProviderMgr.logger.fine(
-                                //            "Parsing the message " +
-                                //            "previously received over UDP");
-                                //}
-                            }                                
+                                // ProviderMgr.logger.log(Level.WARNING,
+                                // "Receiving a complete message" +
+                                // " over TCP failed", e);
+                                // if (LogConst.DEBUG) {
+                                // ProviderMgr.logger.fine(
+                                // "Parsing the message " +
+                                // "previously received over UDP");
+                                // }
+                            }
                         }
                         // Is the message still truncated?
                         // (It is possible in case if TCP connection failed)
@@ -966,93 +965,91 @@
                             // check if the ANSWER section is truncated
                             // or not
                             if (!receivedMes.getAuthorityRRs()
-                                        .hasMoreElements() &&
-                                !receivedMes.getAdditionalRRs()
-                                        .hasMoreElements())
-                            {
+                                    .hasMoreElements()
+                                    && !receivedMes.getAdditionalRRs()
+                                            .hasMoreElements()) {
                                 answerSectionIsTruncated = true;
                             }
                         }
                         rCode = receivedMes.getRCode();
-                        if (rCode == ProviderConstants.NO_ERROR)
-                        {
+                        if (rCode == ProviderConstants.NO_ERROR) {
                             // correct message has been received
-                            slist.updateEntry(workZone, curServer,
-                                    responseTime);
-                            visitedServers.put(curServer, new Object());  //$NON-LOCK-1$
+                            slist
+                                    .updateEntry(workZone, curServer,
+                                            responseTime);
+                            visitedServers.put(curServer, new Object()); // $NON-LOCK-1$
                             if (!answerSectionIsTruncated) {
                                 correctAnswer = true;
                                 break;
                             }
                         } else if (rCode == ProviderConstants.SERVER_FAILURE) {
                             // removing server from list
-                            //ProviderMgr.logger.warning("Server failure. " +
-                            //        errMsg);
+                            // ProviderMgr.logger.warning("Server failure. " +
+                            // errMsg);
                             slist.updateEntry(workZone, curServer,
                                     SList.SERVER_FAILURE);
-                            visitedServers.put(curServer, new Object());  //$NON-LOCK-1$
+                            visitedServers.put(curServer, new Object()); // $NON-LOCK-1$
                         } else if (rCode == ProviderConstants.FORMAT_ERROR) {
                             // removing server from list
-                            //ProviderMgr.logger.warning("Format error. " +
-                            //        errMsg);
+                            // ProviderMgr.logger.warning("Format error. " +
+                            // errMsg);
                             slist.updateEntry(workZone, curServer,
                                     SList.SERVER_FAILURE);
-                            visitedServers.put(curServer, new Object());  //$NON-LOCK-1$
+                            visitedServers.put(curServer, new Object()); // $NON-LOCK-1$
                         } else if (rCode == ProviderConstants.NAME_ERROR) {
-                            //ProviderMgr.logger.warning("Name error. " +
-                            //        errMsg);
+                            // ProviderMgr.logger.warning("Name error. " +
+                            // errMsg);
                             if (receivedMes.isAA()) {
                                 slist.updateEntry(workZone, curServer,
                                         responseTime);
-                                visitedServers.put(curServer, new Object());  //$NON-LOCK-1$
+                                visitedServers.put(curServer, new Object()); // $NON-LOCK-1$
                                 correctAnswer = true;
-                                //if (LogConst.DEBUG) {                            
-                                //    ProviderMgr.logger.fine(
-                                //            "Return name error to user");
-                                //}
+                                // if (LogConst.DEBUG) {
+                                // ProviderMgr.logger.fine(
+                                // "Return name error to user");
+                                // }
                                 break;
                             }
                             // This server is not authoritative server for
-                            // this zone. It should not answer with a 
+                            // this zone. It should not answer with a
                             // name error. Probably it is misconfigured.
                             slist.updateEntry(workZone, curServer,
                                     SList.SERVER_FAILURE);
-                            visitedServers.put(curServer, new Object());  //$NON-LOCK-1$
-                            //if (LogConst.DEBUG) {                            
-                            //    ProviderMgr.logger.fine(
-                            //            "Not authoritative answer. " +
-                            //            "Skip it.");
-                            //}
+                            visitedServers.put(curServer, new Object()); // $NON-LOCK-1$
+                            // if (LogConst.DEBUG) {
+                            // ProviderMgr.logger.fine(
+                            // "Not authoritative answer. " +
+                            // "Skip it.");
+                            // }
                         } else if (rCode == ProviderConstants.NOT_IMPLEMENTED) {
-                            //ProviderMgr.logger.warning("Not implemented. " +
-                            //        errMsg);
+                            // ProviderMgr.logger.warning("Not implemented. " +
+                            // errMsg);
                             slist.updateEntry(workZone, curServer,
                                     SList.SERVER_FAILURE);
-                            visitedServers.put(curServer, new Object());  //$NON-LOCK-1$
+                            visitedServers.put(curServer, new Object()); // $NON-LOCK-1$
                         } else if (rCode == ProviderConstants.REFUSED) {
-                            //ProviderMgr.logger.warning("Refused. " +
-                            //        errMsg);
+                            // ProviderMgr.logger.warning("Refused. " +
+                            // errMsg);
                             slist.updateEntry(workZone, curServer,
                                     SList.SERVER_FAILURE);
-                            visitedServers.put(curServer, new Object());  //$NON-LOCK-1$
+                            visitedServers.put(curServer, new Object()); // $NON-LOCK-1$
                         }
                     } catch (DomainProtocolException e) {
                         // removing this server from SLIST
                         slist.dropServer(workZone, curServer);
-                        //ProviderMgr.logger.warning("Unknown error.");
+                        // ProviderMgr.logger.warning("Unknown error.");
                     } catch (IndexOutOfBoundsException e) {
                         // bad message received
                         slist.dropServer(workZone, curServer);
-                        //ProviderMgr.logger.warning("Bad message received: " + 
-                        //        " IndexOutOfBoundsException.");
+                        // ProviderMgr.logger.warning("Bad message received: " +
+                        // " IndexOutOfBoundsException.");
                     }
                 }
                 queriedServers.add(curServer);
             }
             // end of round
 
-            if (received & parsed & correctAnswer) 
-            {
+            if (received & parsed & correctAnswer) {
                 // correct answer received
                 return receivedMes;
             }
@@ -1063,30 +1060,31 @@
     }
 
     /**
-     * Analyzes the answer message and constructs an analysis report. 
-     *  
-     * @param request the request has been send to the server
-     * @param answer the answer has been received
-     * @param workZone the current resolver's work zone
-     * @return analysis report
-     * TODO may be optimized 
+     * Analyzes the answer message and constructs an analysis report.
+     * 
+     * @param request
+     *            the request has been send to the server
+     * @param answer
+     *            the answer has been received
+     * @param workZone
+     *            the current resolver's work zone
+     * @return analysis report TODO may be optimized
      */
     AnalysisReport analyzeAnswer(Message request, Message answer)
-            throws DomainProtocolException
-    {
+            throws DomainProtocolException {
         Enumeration<QuestionRecord> questions = request.getQuestionRecords();
         Enumeration<ResourceRecord> answerRRs = answer.getAnswerRRs();
         Enumeration<ResourceRecord> authorityRRs = answer.getAuthorityRRs();
         Enumeration<ResourceRecord> additionalRRs;
         QuestionRecord question;
-        Resolver.AnalysisReport report = new AnalysisReport(); 
+        Resolver.AnalysisReport report = new AnalysisReport();
 
         // Check the ID.
         if (request.getId() != answer.getId()) {
             // jndi.72=Request and Answer have different ids
             throw new DomainProtocolException(Messages.getString("jndi.72")); //$NON-NLS-1$
         }
-        
+
         // Determine a question.
         if (questions.hasMoreElements()) {
             question = questions.nextElement();
@@ -1099,7 +1097,7 @@
             report.nameError = true;
             return report;
         }
-        // check truncation, truncated message should not be cached 
+        // check truncation, truncated message should not be cached
         if (answer.isTc()) {
             report.messageWasTruncated = true;
         }
@@ -1107,59 +1105,52 @@
         while (answerRRs.hasMoreElements()) {
             ResourceRecord curRec = answerRRs.nextElement();
 
-            if (question.getQClass() == curRec.getRRClass() ||
-                    question.getQClass() == ProviderConstants.ANY_QCLASS)
-            {
-                if (question.getQType() == ProviderConstants.ANY_QTYPE &&
-                        ProviderMgr.namesAreEqual(curRec.getName(),
-                                question.getQName()))
-                {
+            if (question.getQClass() == curRec.getRRClass()
+                    || question.getQClass() == ProviderConstants.ANY_QCLASS) {
+                if (question.getQType() == ProviderConstants.ANY_QTYPE
+                        && ProviderMgr.namesAreEqual(curRec.getName(), question
+                                .getQName())) {
                     // If we query for ANY record types and the server returns
                     // some record for the SAME domain name we will collect
                     // all of such records and treat
                     // this situation as a complete answer for this query.
-                    // We will not perform any more attempts to obtain more 
+                    // We will not perform any more attempts to obtain more
                     // records.
-                    
+
                     report.records.addElement(curRec);
-                    //if (LogConst.DEBUG) {                            
-                    //    ProviderMgr.logger.fine("Adding " +
-                    //            ProviderConstants.rrTypeNames[
-                    //                    curRec.getRRType()]);
-                    //}
+                    // if (LogConst.DEBUG) {
+                    // ProviderMgr.logger.fine("Adding " +
+                    // ProviderConstants.rrTypeNames[
+                    // curRec.getRRType()]);
+                    // }
                     if (curRec.getRRType() == ProviderConstants.CNAME_TYPE) {
                         report.aliasInfoWasReceived = true;
                         report.newName = (String) curRec.getRData();
-                        //if (LogConst.DEBUG) {                            
-                        //    ProviderMgr.logger.fine("Alias \"" +
-                        //            report.newName + "\" was received");
-                        //}
-                    }
-                    else {
+                        // if (LogConst.DEBUG) {
+                        // ProviderMgr.logger.fine("Alias \"" +
+                        // report.newName + "\" was received");
+                        // }
+                    } else {
                         // XXX have we received a complete set of records?
                         report.completeAnswerWasReceived = true;
                     }
-                }
-                else if (question.getQType() == curRec.getRRType() &&
-                         ProviderMgr.namesAreEqual(
-                                 question.getQName(), curRec.getName()))
-                {
+                } else if (question.getQType() == curRec.getRRType()
+                        && ProviderMgr.namesAreEqual(question.getQName(),
+                                curRec.getName())) {
                     // This is a situation when we get the record with the
                     // name and type exactly matching to that we have asked for.
-                    // We will treat this as a complete answer.  
+                    // We will treat this as a complete answer.
 
                     report.records.addElement(curRec);
-                    //if (LogConst.DEBUG) {                            
-                    //    ProviderMgr.logger.fine("Adding " +
-                    //            ProviderConstants.rrTypeNames[
-                    //                    curRec.getRRType()]);
-                    //}
+                    // if (LogConst.DEBUG) {
+                    // ProviderMgr.logger.fine("Adding " +
+                    // ProviderConstants.rrTypeNames[
+                    // curRec.getRRType()]);
+                    // }
                     report.completeAnswerWasReceived = true;
-                }
-                else if (curRec.getRRType() == ProviderConstants.CNAME_TYPE &&
-                        ProviderMgr.namesAreEqual(curRec.getName(), 
-                                question.getQName()))
-                {
+                } else if (curRec.getRRType() == ProviderConstants.CNAME_TYPE
+                        && ProviderMgr.namesAreEqual(curRec.getName(), question
+                                .getQName())) {
                     // This is the case of an alias. If we received an alias for
                     // the name we have asked the information for then we need
                     // to change the desired name to this newly received name.
@@ -1167,106 +1158,105 @@
                     // this new name in the current answer. If we fail then
                     // we will continue our general lookup algorithm with the
                     // new name instead of an old one. We will query servers
-                    // from the SLIST with this new name.   
-                    
+                    // from the SLIST with this new name.
+
                     // TODO this is not effective
-                    Enumeration<ResourceRecord> answerRRs2 = answer.getAnswerRRs();
-                    Enumeration<ResourceRecord> additionalRRs2 = answer.getAdditionalRRs();
-                        
+                    Enumeration<ResourceRecord> answerRRs2 = answer
+                            .getAnswerRRs();
+                    Enumeration<ResourceRecord> additionalRRs2 = answer
+                            .getAdditionalRRs();
+
                     report.aliasInfoWasReceived = true;
                     report.newName = (String) curRec.getRData();
                     report.extraRecords.addElement(curRec);
-                    //if (LogConst.DEBUG) {                            
-                    //    ProviderMgr.logger.fine("Alias \"" + report.newName +
-                    //            "\" was received");
-                    //}
+                    // if (LogConst.DEBUG) {
+                    // ProviderMgr.logger.fine("Alias \"" + report.newName +
+                    // "\" was received");
+                    // }
                     // if we find the one of desired records in the
                     // current answer then we will treat the answer as complete
                     while (answerRRs2.hasMoreElements()) {
 
-                        // Try to look for info about newly received name 
+                        // Try to look for info about newly received name
                         // in ANSWER section.
 
                         ResourceRecord tmpRec = answerRRs2.nextElement();
 
-                        //if (LogConst.DEBUG) {                            
-                        //    ProviderMgr.logger.fine(
-                        //            "Look for an answer in ANSWER section");
-                        //}
-                        if (tmpRec.getRRType() == question.getQType() &&
-                                ProviderMgr.namesAreEqual(
-                                        tmpRec.getName(), report.newName))
-                        {
-                            // the answer is founded in ANSWER section 
+                        // if (LogConst.DEBUG) {
+                        // ProviderMgr.logger.fine(
+                        // "Look for an answer in ANSWER section");
+                        // }
+                        if (tmpRec.getRRType() == question.getQType()
+                                && ProviderMgr.namesAreEqual(tmpRec.getName(),
+                                        report.newName)) {
+                            // the answer is founded in ANSWER section
                             report.records.addElement(tmpRec);
-                            //if (LogConst.DEBUG) {                                
-                            //    ProviderMgr.logger.fine("Adding " +
-                            //            ProviderConstants.rrTypeNames[
-                            //                    tmpRec.getRRType()]);
-                            //}
+                            // if (LogConst.DEBUG) {
+                            // ProviderMgr.logger.fine("Adding " +
+                            // ProviderConstants.rrTypeNames[
+                            // tmpRec.getRRType()]);
+                            // }
                             report.completeAnswerWasReceived = true;
                         }
                     }
                     while (additionalRRs2.hasMoreElements()) {
-                        // Try to look for info about newly received name 
+                        // Try to look for info about newly received name
                         // in ADDITIONAL section.
 
                         ResourceRecord tmpRec = additionalRRs2.nextElement();
 
-                        //if (LogConst.DEBUG) {                            
-                        //    ProviderMgr.logger.fine("Look for an answer in " +
-                        //            "ADDITIONAL section");
-                        //}
-                        if (tmpRec.getRRType() == question.getQType() &&
-                                ProviderMgr.namesAreEqual(tmpRec.getName(),
-                                        report.newName))
-                        {
-                            // the answer is founded in ADDITIONAL section 
+                        // if (LogConst.DEBUG) {
+                        // ProviderMgr.logger.fine("Look for an answer in " +
+                        // "ADDITIONAL section");
+                        // }
+                        if (tmpRec.getRRType() == question.getQType()
+                                && ProviderMgr.namesAreEqual(tmpRec.getName(),
+                                        report.newName)) {
+                            // the answer is founded in ADDITIONAL section
                             report.records.addElement(tmpRec);
-                            //if (LogConst.DEBUG) {                            
-                            //    ProviderMgr.logger.fine("Adding " +
-                            //            ProviderConstants.rrTypeNames[
-                            //                    tmpRec.getRRType()]);
-                            //}
+                            // if (LogConst.DEBUG) {
+                            // ProviderMgr.logger.fine("Adding " +
+                            // ProviderConstants.rrTypeNames[
+                            // tmpRec.getRRType()]);
+                            // }
                             report.completeAnswerWasReceived = true;
                         }
                     }
-                    //if (report.completeAnswerWasReceived) {
-                    //    if (LogConst.DEBUG) {                            
-                    //        ProviderMgr.logger.fine("Complete answer received");
-                    //    }
-                    //}
-                }
-                else {
+                    // if (report.completeAnswerWasReceived) {
+                    // if (LogConst.DEBUG) {
+                    // ProviderMgr.logger.fine("Complete answer received");
+                    // }
+                    // }
+                } else {
                     // We have received some extra records. Let's save it for
                     // future use.
-                    
+
                     // we will treat authoritative answer as a complete answer
-                    // and in no case will perform further actions 
+                    // and in no case will perform further actions
                     if (answer.isAA()) {
                         report.completeAnswerWasReceived = true;
                     }
                     report.extraRecords.addElement(curRec);
-                    //if (LogConst.DEBUG) {                            
-                    //    ProviderMgr.logger.fine("Adding additional record " +
-                    //            ProviderConstants.rrTypeNames[
-                    //                    curRec.getRRType()]);
-                    //}
+                    // if (LogConst.DEBUG) {
+                    // ProviderMgr.logger.fine("Adding additional record " +
+                    // ProviderConstants.rrTypeNames[
+                    // curRec.getRRType()]);
+                    // }
                 }
             } else {
                 // The record from another DNS class arrived. Just ignore it.
-                //if (LogConst.DEBUG) {                            
-                //    ProviderMgr.logger.fine("Ignore records from DNS class " +
-                //            curRec.getRRClass());
-                //}
+                // if (LogConst.DEBUG) {
+                // ProviderMgr.logger.fine("Ignore records from DNS class " +
+                // curRec.getRRClass());
+                // }
             }
         }
 
         // analyze authority section
         // 1. Store all info from authority NS records; try to locate NS IPs
-        //   from additional records in case if it is not present in SLIST;
-        //   start new background lookup process if not found in additional
-        //   section
+        // from additional records in case if it is not present in SLIST;
+        // start new background lookup process if not found in additional
+        // section
         // TODO current implementation isn't effective
         while (authorityRRs.hasMoreElements()) {
             ResourceRecord curRec = authorityRRs.nextElement();
@@ -1279,8 +1269,8 @@
                 String serverName = (String) curRec.getRData();
                 SList.Server server2 = new SList.Server(serverName, null,
                         ProviderConstants.DEFAULT_DNS_PORT);
-                SList.Server server = slist.getServerByServer(
-                        curRec.getName(), server2);
+                SList.Server server = slist.getServerByServer(curRec.getName(),
+                        server2);
 
                 report.delegationArrived = true;
                 if (server == null) {
@@ -1295,24 +1285,23 @@
                     while (additionalRRs.hasMoreElements()) {
                         ResourceRecord addRec = additionalRRs.nextElement();
 
-                        if (ProviderMgr.namesAreEqual(
-                                addRec.getName(), serverName) &&
-                            addRec.getRRType() == ProviderConstants.A_TYPE)
-                        {
+                        if (ProviderMgr.namesAreEqual(addRec.getName(),
+                                serverName)
+                                && addRec.getRRType() == ProviderConstants.A_TYPE) {
                             server.setIP((String) addRec.getRData());
                         }
                     }
                     if (server.getIP() == null) {
                         // IP was not found in additional section
                         // start resolving process in the background
-                        this.startResolvingThread(server.getName(),
-                                curRec.getRRClass());
+                        this.startResolvingThread(server.getName(), curRec
+                                .getRRClass());
                     }
                 }
-                //if (LogConst.DEBUG) {                            
-                //    ProviderMgr.logger.fine("Delegation \"" + server +
-                //            "\" arrived");
-                //}
+                // if (LogConst.DEBUG) {
+                // ProviderMgr.logger.fine("Delegation \"" + server +
+                // "\" arrived");
+                // }
             } // end of NS type analysis
         } // end of authority section analysis
 
@@ -1322,17 +1311,17 @@
             ResourceRecord addRec = additionalRRs.nextElement();
 
             report.extraRecords.addElement(addRec);
-            //if (LogConst.DEBUG) {                            
-            //    ProviderMgr.logger.fine("Adding additional record " +
-            //            ProviderConstants.rrTypeNames[addRec.getRRType()]);
-            //}
+            // if (LogConst.DEBUG) {
+            // ProviderMgr.logger.fine("Adding additional record " +
+            // ProviderConstants.rrTypeNames[addRec.getRRType()]);
+            // }
         }
 
         // Fixing RRSet TTL issue.
         // If TTL fields in RRSet are not all the same then we need to set
         // all TTLs to lowest found value.
         // See RFC 2181 point 5.2
-        
+
         // checking report.records and report.extraRecords
         for (int k = 0; k < 2; k++) {
             Vector<ResourceRecord> records = null;
@@ -1352,7 +1341,7 @@
                         rr.getRRType();
                 long ttl = rr.getTtl();
                 Vector<ResourceRecord> objToUpdateTTL = new Vector<ResourceRecord>();
-                
+
                 if (processed.contains(key)) {
                     continue;
                 }
@@ -1363,12 +1352,12 @@
                     String key2 = rr2.getName() + " " + rr2.getRRClass() + " " + //$NON-NLS-1$ //$NON-NLS-2$
                             rr2.getRRType();
                     long ttl2 = rr2.getTtl();
-    
+
                     if (processed.contains(key2)) {
                         continue;
                     }
                     if (key.equals(key2)) {
-                        if (ttl > ttl2) { 
+                        if (ttl > ttl2) {
                             ttl = ttl2;
                         }
                         objToUpdateTTL.addElement(rr2);
@@ -1377,7 +1366,7 @@
                 // update TTL if necessary
                 for (int j = 0; j < objToUpdateTTL.size(); j++) {
                     ResourceRecord rr2 = objToUpdateTTL.elementAt(j);
-    
+
                     if (rr2.getTtl() != ttl) {
                         rr2.setTtl(ttl);
                     }
@@ -1392,13 +1381,12 @@
 
     /**
      * Creates a new <code>Message</code> object and fills some of it's
-     * standard fields. 
+     * standard fields.
      * 
      * @return created <code>Message</code> object
      */
-    static Message createMessageForSending(String desiredName, 
-            int recType, int recClass) throws DomainProtocolException
-    {
+    static Message createMessageForSending(String desiredName, int recType,
+            int recClass) throws DomainProtocolException {
         Message mes = new Message();
         QuestionRecord qr = new QuestionRecord();
 
@@ -1413,26 +1401,28 @@
         mes.addQuestionRecord(qr);
         return mes;
     }
-  
+
     /**
-     * Starts new resolver thread that will be searching for IP of the
-     * given hostname.
-     * @param hostname hostname to resolve
-     * @param dnsClass DNS class of host
+     * Starts new resolver thread that will be searching for IP of the given
+     * hostname.
+     * 
+     * @param hostname
+     *            hostname to resolve
+     * @param dnsClass
+     *            DNS class of host
      */
     void startResolvingThread(String hostname, int dnsClass) {
         Thread newThread;
         Resolver.ThreadListEntry newEntry;
         int classes[] = new int[1];
-        
+
         synchronized (threadListSemaphore) {
-            // check that no currently running thread looks for this hostname 
+            // check that no currently running thread looks for this hostname
             for (int i = 0; i < resolverThreads.size(); i++) {
                 Resolver.ThreadListEntry entry = resolverThreads.get(i);
                 if (ProviderMgr.namesAreEqual(hostname,
-                                              entry.serverNameToResolve) &&
-                    entry.dnsClass == dnsClass)
-                {
+                        entry.serverNameToResolve)
+                        && entry.dnsClass == dnsClass) {
                     // this hostname is already under investigation
                     // exiting
                     return;
@@ -1442,9 +1432,8 @@
             for (int i = 0; i < hostnamesToResolve.size(); i++) {
                 Resolver.ThreadListEntry entry = hostnamesToResolve.get(i);
                 if (ProviderMgr.namesAreEqual(hostname,
-                                              entry.serverNameToResolve) &&
-                    entry.dnsClass == dnsClass)
-                {
+                        entry.serverNameToResolve)
+                        && entry.dnsClass == dnsClass) {
                     // this hostname is already scheduled for resolving
                     // exiting
                     return;
@@ -1462,23 +1451,22 @@
             hostnamesToResolve.add(newEntry);
             // starting new thread that should make further updates by itself
             newThread = new Thread(this);
-            //if (LogConst.DEBUG) {                            
-            //    ProviderMgr.logger.fine("Starting new resolver thread," +
-            //            " target hostname: " + hostname);
-            //}
+            // if (LogConst.DEBUG) {
+            // ProviderMgr.logger.fine("Starting new resolver thread," +
+            // " target hostname: " + hostname);
+            // }
             newThread.start();
         }
     }
-    
+
     /**
-     * Start background search of the address of next unresolved server
-     * hostname 
+     * Start background search of the address of next unresolved server hostname
      */
     public void run() {
         SList slist = SList.getInstance();
         Enumeration<ResourceRecord> foundRecords;
         Resolver.ThreadListEntry entryToProcess;
-        int [] classes = new int[1];
+        int[] classes = new int[1];
 
         // update lists
         synchronized (threadListSemaphore) {
@@ -1488,8 +1476,8 @@
                 entryToProcess.thread = Thread.currentThread();
                 resolverThreads.add(entryToProcess);
             } else {
-                //ProviderMgr.logger.warning(
-                //        "Resolver thread: no host name to resolve");
+                // ProviderMgr.logger.warning(
+                // "Resolver thread: no host name to resolve");
                 return;
             }
         }
@@ -1497,8 +1485,7 @@
         try {
             classes[0] = entryToProcess.dnsClass;
             foundRecords = lookup(entryToProcess.serverNameToResolve,
-                    new int[] {ProviderConstants.A_TYPE},
-                    classes);
+                    new int[] { ProviderConstants.A_TYPE }, classes);
             while (foundRecords != null && foundRecords.hasMoreElements()) {
                 // we will take all A records and store all of them in SLIST
                 ResourceRecord rr = foundRecords.nextElement();
@@ -1508,8 +1495,7 @@
                             (String) rr.getRData());
                 }
             }
-        }
-        catch (NamingException e) {
+        } catch (NamingException e) {
             // just ignore it
         }
         // update resolver threads list, remove info about current thread
@@ -1519,9 +1505,8 @@
 
                 if (ProviderMgr.namesAreEqual(
                         entryToProcess.serverNameToResolve,
-                        entry.serverNameToResolve) &&
-                    entryToProcess.dnsClass == entry.dnsClass)
-                {
+                        entry.serverNameToResolve)
+                        && entryToProcess.dnsClass == entry.dnsClass) {
                     resolverThreads.remove(i);
                     break;
                 }
@@ -1529,23 +1514,30 @@
         }
         // exiting
     }
-    
-    
+
     /**
-     * Analysis report. 
-     * @author Alexei Zakharov
+     * Analysis report.
+     * 
      * @see Resolver#analyzeAnswer(Message, Message)
      */
     static class AnalysisReport {
 
         boolean completeAnswerWasReceived = false;
+
         boolean nameError = false;
+
         boolean delegationArrived = false;
+
         boolean aliasInfoWasReceived = false;
+
         boolean messageWasTruncated = false;
+
         Vector<ResourceRecord> records;
+
         Vector<String> delegationZones;
+
         String newName = null;
+
         Vector<ResourceRecord> extraRecords;
 
         AnalysisReport() {



Mime
View raw message