1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
5 package org.ibex.jinetd;
6 import org.ibex.util.*;
10 import java.lang.reflect.*;
12 public class Host extends TreeClassLoader {
14 public final String hostname;
15 public final String path;
17 private static final Hashtable hosts = new Hashtable();
18 private static boolean initted = false;
20 public static Host getHost(String hostname) { return (Host)hosts.get(hostname); }
21 public static Enumeration enumerateHosts() { return hosts.elements(); }
23 public Host(String path, String hostname, ClassLoader pcl) {
24 super(new File(path + File.separatorChar + "WEB-INF"), pcl);
25 this.hostname = hostname;
29 public static void init() {
32 init(org.ibex.jinetd.Main.ROOT + "/host", "", 0, Main.getRootClassLoader());
34 public static void init(String path, String host, int depth, ClassLoader pcl) {
35 if (!new File(path).exists() || !new File(path).isDirectory()) return;
37 Log.warn(Host.class, "resolving " + host);
38 InetAddress ia = InetAddress.getByName(host);
40 while(pad.length() + host.length() < 30) pad += " ";
41 if (ia.equals(InetAddress.getLocalHost())) {
42 Log.info(Main.class, pad + host + " => " + path);
43 hosts.put(host, pcl = new Host(path, host, pcl));
45 } catch (UnknownHostException e) {
46 if (depth >= 3) return;
48 String[] subdirs = new File(path).list();
50 for(int i=0; i<subdirs.length; i++)
51 init(path + File.separatorChar + subdirs[i], host.equals("") ? subdirs[i] : subdirs[i]+"."+host, depth+1, pcl);