james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r684752 - in /james/server/trunk: core-library/src/main/java/org/apache/james/domain/ domain-api/src/main/java/org/apache/james/api/domainlist/ user-library/src/main/java/org/apache/james/impl/vut/
Date Mon, 11 Aug 2008 14:02:35 GMT
Author: bago
Date: Mon Aug 11 07:02:32 2008
New Revision: 684752

URL: http://svn.apache.org/viewvc?rev=684752&view=rev
Log:
DomainListUtil was introducing a dependency on avalon-framework in our api-layer.
It simply had 2 uses in libraries. I decided to clone the content in the 2 user classes.
A minor code duplication is better than having avalon the api-layer.

Removed:
    james/server/trunk/domain-api/src/main/java/org/apache/james/api/domainlist/DomainListUtil.java
Modified:
    james/server/trunk/core-library/src/main/java/org/apache/james/domain/AbstractDomainList.java
    james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/domain/AbstractDomainList.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/domain/AbstractDomainList.java?rev=684752&r1=684751&r2=684752&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/domain/AbstractDomainList.java
(original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/domain/AbstractDomainList.java
Mon Aug 11 07:02:32 2008
@@ -21,17 +21,19 @@
 
 package org.apache.james.domain;
 
+import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.james.api.dnsservice.DNSService;
-import org.apache.james.api.domainlist.DomainListUtil;
 import org.apache.james.services.ManageableDomainList;
 
 /**
@@ -72,7 +74,7 @@
 
             
             if (autoDetectIP == true) {
-                domains.addAll(DomainListUtil.getDomainsIP(domains,dns,getLogger()));
+                domains.addAll(getDomainsIP(domains,dns,getLogger()));
             }
        
             if (getLogger().isInfoEnabled()) {
@@ -86,6 +88,48 @@
         }
     }
     
+    
+    /**
+     * Return a List which holds all ipAddress of the domains in the given List
+     * 
+     * @param domains List of domains
+     * @return domainIP List of ipaddress for domains
+     */
+    private static List getDomainsIP(List domains,DNSService dns,Logger log) {
+        List domainIP = new ArrayList();
+        if (domains.size() > 0 ) {
+            for (int i = 0; i < domains.size(); i++) {
+                List domList = getDomainIP(domains.get(i).toString(),dns,log);
+                
+                for(int i2 = 0; i2 < domList.size();i2++) {
+                    if(domainIP.contains(domList.get(i2)) == false) {
+                        domainIP.add(domList.get(i2));
+                    }
+                }
+            }
+        }
+        return domainIP;    
+    }
+    
+    /**
+     * @see #getDomainsIP(List, DNSService, Logger)
+     */
+    private static List getDomainIP(String domain, DNSService dns, Logger log) {
+        List domainIP = new ArrayList();
+        try {
+            InetAddress[]  addrs = dns.getAllByName(domain);
+            for (int j = 0; j < addrs.length ; j++) {
+                String ip = addrs[j].getHostAddress();
+                if (domainIP.contains(ip) == false) {
+                    domainIP.add(ip);
+                }
+            }
+        } catch (UnknownHostException e) {
+            log.error("Cannot get IP address(es) for " + domain);
+        }
+        return domainIP;
+    }
+    
     /**
      * @see org.apache.james.services.ManageableDomainList#addDomain(java.lang.String)
      */

Modified: james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java?rev=684752&r1=684751&r2=684752&view=diff
==============================================================================
--- james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java
(original)
+++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java
Mon Aug 11 07:02:32 2008
@@ -21,6 +21,7 @@
 
 package org.apache.james.impl.vut;
 
+import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -35,12 +36,12 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.domainlist.DomainList;
-import org.apache.james.api.domainlist.DomainListUtil;
 import org.apache.james.api.vut.ErrorMappingException;
 import org.apache.james.api.vut.VirtualUserTable;
 import org.apache.james.api.vut.management.InvalidMappingException;
@@ -360,7 +361,7 @@
             }
            
             if (autoDetectIP == true) {
-                List ipList = DomainListUtil.getDomainsIP(domains,dns,getLogger());
+                List ipList = getDomainsIP(domains,dns,getLogger());
                 for(int i = 0; i < ipList.size(); i++) {
                     if (domains.contains(ipList.get(i)) == false) {
                         domains.add(ipList.get(i));
@@ -378,8 +379,49 @@
             return null;
         }
     }
+
+    /**
+     * Return a List which holds all ipAddress of the domains in the given List
+     * 
+     * @param domains List of domains
+     * @return domainIP List of ipaddress for domains
+     */
+    private static List getDomainsIP(List domains,DNSService dns,Logger log) {
+        List domainIP = new ArrayList();
+        if (domains.size() > 0 ) {
+            for (int i = 0; i < domains.size(); i++) {
+                List domList = getDomainIP(domains.get(i).toString(),dns,log);
+                
+                for(int i2 = 0; i2 < domList.size();i2++) {
+                    if(domainIP.contains(domList.get(i2)) == false) {
+                        domainIP.add(domList.get(i2));
+                    }
+                }
+            }
+        }
+        return domainIP;    
+    }
     
     /**
+     * @see #getDomainsIP(List, DNSService, Logger)
+     */
+    private static List getDomainIP(String domain, DNSService dns, Logger log) {
+        List domainIP = new ArrayList();
+        try {
+            InetAddress[]  addrs = dns.getAllByName(domain);
+            for (int j = 0; j < addrs.length ; j++) {
+                String ip = addrs[j].getHostAddress();
+                if (domainIP.contains(ip) == false) {
+                    domainIP.add(ip);
+                }
+            }
+        } catch (UnknownHostException e) {
+            log.error("Cannot get IP address(es) for " + domain);
+        }
+        return domainIP;
+    }
+
+    /**
      * @see org.apache.james.api.vut.management.VirtualUserTableManagement#getUserDomainMappings(java.lang.String,
java.lang.String)
      */
     public Collection getUserDomainMappings(String user, String domain) {



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message