FileDocCategorySizeDatePackage
NetMatcher.javaAPI DocApache James 2.3.18855Fri Jan 12 12:56:34 GMT 2007org.apache.james.util

NetMatcher

public class NetMatcher extends Object
Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. *

Fields Summary
private ArrayList
networks
Constructors Summary
public NetMatcher()

    
public NetMatcher(String[] nets)

        initInetNetworks(nets);
    
public NetMatcher(Collection nets)

        initInetNetworks(nets);
    
Methods Summary
public voidinitInetNetworks(java.util.Collection nets)

        networks = new ArrayList();
        for (Iterator iter = nets.iterator(); iter.hasNext(); ) try
        {
            InetNetwork net = InetNetwork.getFromString((String) iter.next());
            if (!networks.contains(net)) networks.add(net);
        }
        catch (java.net.UnknownHostException uhe)
        {
            log("Cannot resolve address: " + uhe.getMessage());
        }
        networks.trimToSize();
    
public voidinitInetNetworks(java.lang.String[] nets)

        networks = new ArrayList();
        for (int i = 0; i < nets.length; i++) try
        {
            InetNetwork net = InetNetwork.getFromString(nets[i]);
            if (!networks.contains(net)) networks.add(net);
        }
        catch (java.net.UnknownHostException uhe)
        {
            log("Cannot resolve address: " + uhe.getMessage());
        }
        networks.trimToSize();
    
protected voidlog(java.lang.String s)

 
public booleanmatchInetNetwork(java.lang.String hostIP)

        InetAddress ip = null;

        try
        {
            ip = org.apache.james.dnsserver.DNSServer.getByName(hostIP);
        }
        catch (java.net.UnknownHostException uhe)
        {
            log("Cannot resolve address for " + hostIP + ": " + uhe.getMessage());
        }

        boolean sameNet = false;

        if (ip != null) for (Iterator iter = networks.iterator(); (!sameNet) && iter.hasNext(); )
        {
            InetNetwork network = (InetNetwork) iter.next();
            sameNet = network.contains(ip);
        }
        return sameNet;
    
public booleanmatchInetNetwork(java.net.InetAddress ip)

        boolean sameNet = false;

        for (Iterator iter = networks.iterator(); (!sameNet) && iter.hasNext(); )
        {
            InetNetwork network = (InetNetwork) iter.next();
            sameNet = network.contains(ip);
        }
        return sameNet;
    
public java.lang.StringtoString()

        return networks.toString();