KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > dns > DNSLookup


1 package org.jacorb.orb.dns;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import java.net.InetAddress JavaDoc;
24
25 import org.jacorb.util.ObjectUtil;
26
27 import org.apache.avalon.framework.configuration.*;
28 import org.apache.avalon.framework.logger.Logger;
29
30 public class DNSLookup
31     implements Configurable
32 {
33     private DNSLookupDelegate delegate = null;
34     private boolean enabled = false;
35
36     public void configure(Configuration configuration)
37         throws ConfigurationException
38     {
39         enabled = configuration.getAttribute("jacorb.dns.enable","off").equals("on");
40         if (enabled)
41         {
42             delegate =
43                 new JdkDelegateImpl(((org.jacorb.config.Configuration)configuration).getNamedLogger("org.jacorb.dns"));
44         }
45     }
46
47     /**
48      * Returns true if this is a post-1.4 DNS implementation.
49      */

50     private static boolean jdk_DNS_Usable()
51     {
52         try
53         {
54             java.lang.reflect.Method JavaDoc m = java.net.InetAddress JavaDoc.class.getMethod
55             (
56                 "getCanonicalHostName",
57                 new Class JavaDoc[] {}
58             );
59             return m != null;
60         }
61         catch (NoSuchMethodException JavaDoc ex)
62         {
63             return false;
64         }
65     }
66
67     public String JavaDoc inverseLookup(String JavaDoc ip)
68     {
69         return ((delegate == null) ? null : delegate.inverseLookup(ip));
70     }
71
72     public String JavaDoc inverseLookup(InetAddress JavaDoc addr)
73     {
74         return ((delegate == null) ? null : delegate.inverseLookup(addr));
75     }
76             
77 } // DNSLookup
78
Popular Tags