All pastes #773569 Raw Edit

Kumar

public java v1 · immutable
·published 2007-11-14 17:15 UTC
rendered paste body
// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 11/14/2007 3:58:04 AM// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!// Decompiler options: packimports(3) // Source File Name:   Main.javapackage org.netvita.start;import java.io.*;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.net.InetAddress;import java.net.Socket;import java.security.Policy;import java.util.*;// Referenced classes of package org.mortbay.start://            Classpath, Version, Monitorpublic class Main{    public Main()    {        _classname = null;        _classpath = new Classpath();        _config = System.getProperty("START", "org/mortbay/start/start.config");        _xml = new ArrayList();        _version = false;    }    public static void main(String args[])    {        try        {            if(args.length > 0 && args[0].equalsIgnoreCase("--help"))            {                System.err.println("Usage: java [-DDEBUG] [-DSTART=start.config] [-Dmain.class=org.MyMain] -jar start.jar [--help|--stop|--version] [config ...]");                System.exit(1);            } else            if(args.length > 0 && args[0].equalsIgnoreCase("--stop"))                (new Main()).stop();            else            if(args.length > 0 && args[0].equalsIgnoreCase("--version"))            {                String nargs[] = new String[args.length - 1];                System.arraycopy(args, 1, nargs, 0, nargs.length);                Main main = new Main();                main._version = true;                main.start(nargs);            } else            {                (new Main()).start(args);            }        }        catch(Exception e)        {            e.printStackTrace();        }    }    static File getDirectory(String name)    {        File dir;        if(name == null)            break MISSING_BLOCK_LABEL_29;        dir = (new File(name)).getCanonicalFile();        if(dir.isDirectory())            return dir;        break MISSING_BLOCK_LABEL_29;        IOException e;        e;        return null;    }    boolean isAvailable(String classname)    {        Class.forName(classname);        return true;        NoClassDefFoundError e;        //e;        break MISSING_BLOCK_LABEL_12;       // e;        ClassLoader loader = _classpath.getClassLoader();        loader.loadClass(classname);        return true;        NoClassDefFoundError e;        //e;        break MISSING_BLOCK_LABEL_33;        //e;        return false;    }    public void invokeMain(ClassLoader classloader, String classname, String args[])        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException    {        Class invoked_class = null;        invoked_class = classloader.loadClass(classname);        if(_version)        {            System.err.println(invoked_class.getPackage().getImplementationTitle() + " " + invoked_class.getPackage().getImplementationVersion());            System.exit(0);        }        Class method_param_types[] = new Class[1];        method_param_types[0] = args.getClass();        Method main = null;        main = invoked_class.getDeclaredMethod("main", method_param_types);        Object method_params[] = new Object[1];        method_params[0] = args;        main.invoke(null, method_params);    }    String expand(String s)    {        int i1 = 0;        int i2 = 0;        do        {            if(s == null)                break;            i1 = s.indexOf("$(", i2);            if(i1 < 0)                break;            i2 = s.indexOf(")", i1 + 2);            if(i2 < 0)                break;            String property = System.getProperty(s.substring(i1 + 2, i2), "");            s = s.substring(0, i1) + property + s.substring(i2 + 1);        } while(true);        return s;    }    void configure(InputStream config, int nargs)        throws Exception    {        BufferedReader cfg;        Version java_version;        Version ver;        Hashtable done;        String line;        cfg = new BufferedReader(new InputStreamReader(config, "ISO-8859-1"));        java_version = new Version(System.getProperty("java.version"));        ver = new Version();        done = new Hashtable();        String classpath = System.getProperty("CLASSPATH");        if(classpath != null)        {            for(StringTokenizer tok = new StringTokenizer(classpath, File.pathSeparator); tok.hasMoreTokens(); _classpath.addComponent(tok.nextToken()));        }        line = null;_L2:        line = cfg.readLine();        if(line == null)            break; /* Loop/switch isn't completed */        if(line.length() == 0 || line.startsWith("#"))            continue; /* Loop/switch isn't completed */        StringTokenizer st = new StringTokenizer(line);        String subject = st.nextToken();        boolean expression = true;        boolean not = false;        String condition = null;        do        {            if(!st.hasMoreTokens())                break;            condition = st.nextToken();            if(condition.equalsIgnoreCase("!"))            {                not = true;                continue;            }            if(condition.equalsIgnoreCase("OR"))            {                if(expression)                    break;                expression = true;                continue;            }            if(condition.equalsIgnoreCase("AND"))            {                if(!expression)                    break;            } else            {                boolean eval = true;                if(condition.equals("true") || condition.equals("always"))                    eval = true;                else                if(condition.equals("false") || condition.equals("never"))                    eval = false;                else                if(condition.equals("available"))                {                    String class_to_check = st.nextToken();                    eval = isAvailable(class_to_check);                } else                if(condition.equals("exists"))                    try                    {                        eval = false;                        File file = new File(expand(st.nextToken()));                        eval = file.exists();                    }                    catch(Exception e)                    {                        if(_debug)                            e.printStackTrace();                    }                else                if(condition.equals("property"))                {                    String property = System.getProperty(st.nextToken());                    eval = property != null && property.length() > 0;                } else                if(condition.equals("java"))                {                    String operator = st.nextToken();                    String version = st.nextToken();                    ver.parse(version);                    eval = operator.equals("<") && java_version.compare(ver) < 0 || operator.equals(">") && java_version.compare(ver) > 0 || operator.equals("<=") && java_version.compare(ver) <= 0 || operator.equals("=<") && java_version.compare(ver) <= 0 || operator.equals("=>") && java_version.compare(ver) >= 0 || operator.equals(">=") && java_version.compare(ver) >= 0 || operator.equals("==") && java_version.compare(ver) == 0 || operator.equals("!=") && java_version.compare(ver) != 0;                } else                if(condition.equals("nargs"))                {                    String operator = st.nextToken();                    int number = Integer.parseInt(st.nextToken());                    eval = operator.equals("<") && nargs < number || operator.equals(">") && nargs > number || operator.equals("<=") && nargs <= number || operator.equals("=<") && nargs <= number || operator.equals("=>") && nargs >= number || operator.equals(">=") && nargs >= number || operator.equals("==") && nargs == number || operator.equals("!=") && nargs != number;                } else                {                    System.err.println("ERROR: Unknown condition: " + condition);                    eval = false;                }                expression &= not ? !eval : eval;                not = false;            }        } while(true);        String file = expand(subject).replace('/', File.separatorChar);        if(_debug)            System.err.println((expression ? "T " : "F ") + line);        if(!expression)        {            done.put(file, file);            continue; /* Loop/switch isn't completed */        }        try        {            if(subject.indexOf("=") > 0)            {                int i = file.indexOf("=");                String property = file.substring(0, i);                String value = file.substring(i + 1);                if(_debug)                    System.err.println("  " + property + "=" + value);                System.setProperty(property, value);            } else            if(subject.endsWith("/*"))            {                File dir = new File(file.substring(0, file.length() - 1));                addJars(dir, done, false);            } else            if(subject.endsWith("/**"))            {                File dir = new File(file.substring(0, file.length() - 2));                addJars(dir, done, true);            } else            if(subject.endsWith("/"))            {                File cd = new File(file);                String d = cd.getCanonicalPath();                if(!done.containsKey(d))                {                    done.put(d, d);                    boolean added = _classpath.addComponent(d);                    if(_debug)                        System.err.println((added ? "  CLASSPATH+=" : "  !") + d);                }            } else            if(subject.toLowerCase().endsWith(".xml"))            {                File f = new File(file);                if(f.exists())                    _xml.add(f.getCanonicalPath());                if(_debug)                    System.err.println("  ARGS+=" + f);            } else            if(subject.toLowerCase().endsWith(".class"))            {                String cn = expand(subject.substring(0, subject.length() - 6));                if(cn != null && cn.length() > 0)                {                    if(_debug)                        System.err.println("  CLASS=" + cn);                    _classname = cn;                }            } else            {                File f = new File(file);                String d = f.getCanonicalPath();                if(!done.containsKey(d))                {                    done.put(d, d);                    boolean added = _classpath.addComponent(d);                    if(!added)                    {                        added = _classpath.addClasspath(expand(subject));                        if(_debug)                            System.err.println((added ? "  CLASSPATH+=" : "  !") + d);                    } else                    if(_debug)                        System.err.println((added ? "  CLASSPATH+=" : "  !") + d);                }            }        }        catch(Exception e)        {            System.err.println("on line: '" + line + "'");            e.printStackTrace();        }        if(true) goto _L2; else goto _L1_L1:    }    public void start(String args[])    {        InputStream cpcfg;        ArrayList al = new ArrayList();        for(int i = 0; i < args.length; i++)            if(args[i] != null)                al.add(args[i]);        args = (String[])(String[])al.toArray(new String[al.size()]);        cpcfg = null;        Monitor.monitor();        cpcfg = getClass().getClassLoader().getResourceAsStream(_config);        if(_debug)            System.err.println("config=" + _config);        if(cpcfg == null)            cpcfg = new FileInputStream(_config);        configure(cpcfg, args.length);        File file = new File(System.getProperty("jetty.home"));        String canonical = file.getCanonicalPath();        System.setProperty("jetty.home", canonical);        Exception e;        try        {            cpcfg.close();        }        // Misplaced declaration of an exception variable        catch(Exception e)        {            e.printStackTrace();        }        break MISSING_BLOCK_LABEL_227;        e;        e.printStackTrace();        System.exit(1);        try        {            cpcfg.close();        }        // Misplaced declaration of an exception variable        catch(Exception e)        {            e.printStackTrace();        }        break MISSING_BLOCK_LABEL_227;        Exception exception;        exception;        try        {            cpcfg.close();        }        catch(Exception e)        {            e.printStackTrace();        }        throw exception;        System.setProperty("java.class.path", _classpath.toString());        ClassLoader cl = _classpath.getClassLoader();        if(_debug)        {            System.err.println("java.class.path=" + System.getProperty("java.class.path"));            System.err.println("jetty.home=" + System.getProperty("jetty.home"));            System.err.println("java.io.tmpdir=" + System.getProperty("java.io.tmpdir"));            System.err.println("java.class.path=" + _classpath);            System.err.println("classloader=" + cl);            System.err.println("classloader.parent=" + cl.getParent());        }        Thread.currentThread().setContextClassLoader(cl);        try        {            Policy policy = Policy.getPolicy();            if(policy != null)                policy.refresh();        }        catch(Exception e)        {            e.printStackTrace();        }        try        {            for(int i = 0; i < args.length; i++)                if(args[i] != null)                    _xml.add(args[i]);            args = (String[])(String[])_xml.toArray(args);            String mainClass = System.getProperty("jetty.server");            if(mainClass != null)                _classname = mainClass;            mainClass = System.getProperty("main.class");            if(mainClass != null)                _classname = mainClass;            if(_debug)                System.err.println("main.class=" + _classname);            invokeMain(cl, _classname, args);        }        catch(Exception e)        {            e.printStackTrace();        }        return;    }    public void stop()    {        int _port = Integer.getInteger("STOP.PORT", -1).intValue();        String _key = System.getProperty("STOP.KEY", null);        try        {            if(_port <= 0)                System.err.println("STOP.PORT system property must be specified");            if(_key == null)            {                _key = "";                System.err.println("STOP.KEY system property must be specified");                System.err.println("Using empty key");            }            Socket s = new Socket(InetAddress.getByName("127.0.0.1"), _port);            OutputStream out = s.getOutputStream();            out.write((_key + "\r\nstop\r\n").getBytes());            out.flush();            s.close();        }        catch(Exception e)        {            e.printStackTrace();        }    }    private void addJars(File dir, Hashtable table, boolean recurse)        throws IOException    {        File entries[] = dir.listFiles();        for(int i = 0; entries != null && i < entries.length; i++)        {            File entry = entries[i];            if(entry.isDirectory() && recurse)            {                addJars(entry, table, recurse);                continue;            }            String name = entry.getName().toLowerCase();            if(!name.endsWith(".jar") && !name.endsWith(".zip"))                continue;            String jar = entry.getCanonicalPath();            if(table.containsKey(jar))                continue;            table.put(jar, jar);            boolean added = _classpath.addComponent(jar);            if(_debug)                System.err.println((added ? "  CLASSPATH+=" : "  !") + jar);        }    }    static boolean _debug = System.getProperty("DEBUG", null) != null;    private String _classname;    private Classpath _classpath;    private String _config;    private ArrayList _xml;    private boolean _version;}