// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.net.URLConnection;

public class WhatConnection {
    private static final String INDENT = "  ";
    private static String getType(Class<?> clz) {
        if(clz.isInterface()) {
            return "interface";
        } else if(clz.isEnum()) {
            return "enum";
        } else {
            if((clz.getModifiers() & Modifier.ABSTRACT) !=  0) {
                return "abstract class";
            } else {
                return "class";
            }
        }
    }
    public static void dumpClassInfo(String indent, Class<?> clz) {
        System.out.println(indent + getType(clz) + " " + clz.getName());
        if(clz.getSuperclass() != null) dumpClassInfo(indent + INDENT, clz.getSuperclass());
        for(Class<?> intf : clz.getInterfaces()) {
            dumpClassInfo(indent + INDENT, intf);
        }
    }
    public static void test(String urlstr) throws IOException {
        System.out.println(urlstr + ":");
        URL url = new URL(urlstr);
        URLConnection con = url.openConnection();
        dumpClassInfo(INDENT, con.getClass());
    }
    public static void main(String[] args) throws Exception {
        test("http://www.oracle.com/");
        test("ftp://ftp.oracle.com/");
    }
}
