Package com.atolsystems.atolutilities

Examples of com.atolsystems.atolutilities.PlugInLoader


    public String getAboutMsg() {
        return "NimpSmartCard sample code: GetRandomData";
    }

    public static void invokeMain(String[] classFiles, String mainClassName, String[] classNames, String[] args) throws Throwable {
        PlugInLoader pl = new PlugInLoader(GetRandomData.class, "packageLocator");
        //System.out.println(AFileUtilities.getPackageUrl(GetRandomData.class, "packageLocator"));
        String here = AFileUtilities.getPackageUrl(GetRandomData.class, "packageLocator");
        String jarPrefix = "jar:file:/";
        int lastMarkPos=here.lastIndexOf("!");
        if(lastMarkPos!=-1){
            String jarFilePath = here.substring(jarPrefix.length(), lastMarkPos);
            //System.out.println("jar path:" + jarFilePath);
            pl.addJarFile(new File(jarFilePath));
        }else{
            //target class is not in a jar file, just assume the class is already known then
        }
        URL[] classUrls = new URL[classFiles.length];
        for (int i = 0; i < classFiles.length; i++) {
            classUrls[i] = ClassLoader.getSystemResource(classFiles[i]);
            //System.out.println("URL " + classUrls[i] + " added to classpath");
        }
        URLClassLoader ucl = new URLClassLoader(classUrls);
        for (int i = 0; i < classNames.length; i++) {
            //System.out.print("Loading " + classNames[i] + ": ");
            Class miscClass = null;
            try {
                miscClass = ucl.loadClass(classNames[i]);
            } catch (Throwable e) {
                //System.out.println("Class loading failed. Look in jar file: ");
                miscClass = pl.getPlugInClass(classNames[i]);
            }
            //System.out.println(miscClass + " loaded");
        }
        //System.out.print("Loading " + mainClassName + " as main class: ");
        Class c = null;
        try {
            c = ucl.loadClass(mainClassName);
        } catch (Throwable e) {
            //System.out.println("Class loading failed. Look in jar file: ");
            c = pl.getPlugInClass(mainClassName);
        }

        Method main = c.getDeclaredMethod("main", args.getClass());
        Object[] arguments = new Object[1];
        arguments[0] = args;
View Full Code Here

TOP

Related Classes of com.atolsystems.atolutilities.PlugInLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.