Example usage for java.net URLClassLoader loadClass

List of usage examples for java.net URLClassLoader loadClass

Introduction

In this page you can find the example usage for java.net URLClassLoader loadClass.

Prototype

public Class<?> loadClass(String name) throws ClassNotFoundException 

Source Link

Document

Loads the class with the specified binary name.

Usage

From source file:com.mgmtp.perfload.agent.TransformerTest.java

private Class<?> loadClass(final String fqcn)
        throws IOException, IllegalClassFormatException, MalformedURLException, ClassNotFoundException {
    String internalName = fqcn.replace('.', '/');

    byte[] classBytes = Resources.toByteArray(Resources.getResource(internalName + ".class"));
    byte[] transformedClass = transformer.transform(null, internalName, null, null, classBytes);
    File classFile = new File("tmp/" + internalName + ".class");
    writeByteArrayToFile(classFile, transformedClass);

    URLClassLoader loader = new URLClassLoader(new URL[] { new File("tmp").toURI().toURL() }) {
        /**//from  www  . ja  v  a 2s .  c o  m
         * Loads the class with the specified binary name trying to load it from the local
         * classpath first before delegating to the normal class loading mechanism.
         */
        @Override
        protected synchronized Class<?> loadClass(final String name, final boolean resolve)
                throws ClassNotFoundException {
            // Check if the class has already been loaded
            Class<?> loadedClass = findLoadedClass(name);

            if (loadedClass == null) {
                if (name.startsWith("com.mgmtp.perfload.agent.Test")) {
                    try {
                        // First try to find it locally
                        loadedClass = findClass(name);
                    } catch (ClassNotFoundException e) {
                        // Swallow exception --> the class does not exist locally
                    }
                }
                // If the class is not found locally we delegate to the normal class loading mechanism
                if (loadedClass == null) {
                    loadedClass = super.loadClass(name, resolve);
                }
            }

            if (resolve) {
                resolveClass(loadedClass);
            }
            return loadedClass;
        }
    };
    return loader.loadClass(fqcn);
}

From source file:azkaban.webapp.TriggerPluginLoader.java

public Map<String, TriggerPlugin> loadTriggerPlugins(final Context root) {
    /*/*from  w  w w.j av  a 2  s .  com*/
     * TODO spyne: TriggerPluginLoader should not have any dependency on Azkaban Web Server
     **/
    final AzkabanWebServer azkabanWebServer = SERVICE_PROVIDER.getInstance(AzkabanWebServer.class);
    final File triggerPluginPath = new File(this.pluginPath);
    if (!triggerPluginPath.exists()) {
        return new HashMap<>();
    }

    final Map<String, TriggerPlugin> installedTriggerPlugins = new HashMap<>();
    final ClassLoader parentLoader = AzkabanWebServer.class.getClassLoader();
    final File[] pluginDirs = triggerPluginPath.listFiles();
    final ArrayList<String> jarPaths = new ArrayList<>();
    for (final File pluginDir : pluginDirs) {
        if (!pluginDir.exists()) {
            log.error("Error! Trigger plugin path " + pluginDir.getPath() + " doesn't exist.");
            continue;
        }

        if (!pluginDir.isDirectory()) {
            log.error("The plugin path " + pluginDir + " is not a directory.");
            continue;
        }

        // Load the conf directory
        final File propertiesDir = new File(pluginDir, "conf");
        Props pluginProps = null;
        if (propertiesDir.exists() && propertiesDir.isDirectory()) {
            final File propertiesFile = new File(propertiesDir, "plugin.properties");
            final File propertiesOverrideFile = new File(propertiesDir, "override.properties");

            if (propertiesFile.exists()) {
                if (propertiesOverrideFile.exists()) {
                    pluginProps = PropsUtils.loadProps(null, propertiesFile, propertiesOverrideFile);
                } else {
                    pluginProps = PropsUtils.loadProps(null, propertiesFile);
                }
            } else {
                log.error("Plugin conf file " + propertiesFile + " not found.");
                continue;
            }
        } else {
            log.error("Plugin conf path " + propertiesDir + " not found.");
            continue;
        }

        final String pluginName = pluginProps.getString("trigger.name");
        final List<String> extLibClasspath = pluginProps.getStringList("trigger.external.classpaths",
                (List<String>) null);

        final String pluginClass = pluginProps.getString("trigger.class");
        if (pluginClass == null) {
            log.error("Trigger class is not set.");
        } else {
            log.error("Plugin class " + pluginClass);
        }

        URLClassLoader urlClassLoader = null;
        final File libDir = new File(pluginDir, "lib");
        if (libDir.exists() && libDir.isDirectory()) {
            final File[] files = libDir.listFiles();

            final ArrayList<URL> urls = new ArrayList<>();
            for (int i = 0; i < files.length; ++i) {
                try {
                    final URL url = files[i].toURI().toURL();
                    urls.add(url);
                } catch (final MalformedURLException e) {
                    log.error(e);
                }
            }
            if (extLibClasspath != null) {
                for (final String extLib : extLibClasspath) {
                    try {
                        final File file = new File(pluginDir, extLib);
                        final URL url = file.toURI().toURL();
                        urls.add(url);
                    } catch (final MalformedURLException e) {
                        log.error(e);
                    }
                }
            }

            urlClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), parentLoader);
        } else {
            log.error("Library path " + propertiesDir + " not found.");
            continue;
        }

        Class<?> triggerClass = null;
        try {
            triggerClass = urlClassLoader.loadClass(pluginClass);
        } catch (final ClassNotFoundException e) {
            log.error("Class " + pluginClass + " not found.");
            continue;
        }

        final String source = FileIOUtils.getSourcePathFromClass(triggerClass);
        log.info("Source jar " + source);
        jarPaths.add("jar:file:" + source);

        Constructor<?> constructor = null;
        try {
            constructor = triggerClass.getConstructor(String.class, Props.class, Context.class,
                    AzkabanWebServer.class);
        } catch (final NoSuchMethodException e) {
            log.error("Constructor not found in " + pluginClass);
            continue;
        }

        Object obj = null;
        try {
            obj = constructor.newInstance(pluginName, pluginProps, root, azkabanWebServer);
        } catch (final Exception e) {
            log.error(e);
        }

        if (!(obj instanceof TriggerPlugin)) {
            log.error("The object is not an TriggerPlugin");
            continue;
        }

        final TriggerPlugin plugin = (TriggerPlugin) obj;
        installedTriggerPlugins.put(pluginName, plugin);
    }

    // Velocity needs the jar resource paths to be set.
    final String jarResourcePath = StringUtils.join(jarPaths, ", ");
    log.info("Setting jar resource path " + jarResourcePath);
    final VelocityEngine ve = azkabanWebServer.getVelocityEngine();
    ve.addProperty("jar.resource.loader.path", jarResourcePath);

    return installedTriggerPlugins;
}

From source file:fur.shadowdrake.minecraft.InstallPanel.java

private boolean doPostDownload() throws NetworkException {
    boolean b;// w  w w  . j a va2s.c om
    PrintStream originalOut = System.out;
    log.setIndeterminate();
    log.setStatusText("running post-download");
    System.setOut(new PrintStream(new OutputStream() {
        @Override
        public void write(int b) throws IOException {
            byte[] x = new byte[1];
            x[0] = (byte) b;
            log.print(new String(x));
        }

        @Override
        public void write(byte[] b, int off, int len) throws IOException {
            log.print(new String(b, off, len));
        }
    }));
    try {
        URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { new File(workingDir).toURI().toURL() });
        Class postDownloadClass = urlClassLoader.loadClass("PostDownload");
        Constructor constructor = postDownloadClass.getConstructor();
        Object pd = constructor.newInstance();
        Method method = postDownloadClass.getMethod("invoke", new Class[] { String.class, String.class });
        b = (boolean) method.invoke(pd, config.getInstallDir().getAbsolutePath(), workingDir);
        if (b) {
            showReadMe();
        }
        return b;
    } catch (MalformedURLException | ClassNotFoundException | NoSuchMethodException | SecurityException
            | InstantiationException | IllegalAccessException | IllegalArgumentException
            | InvocationTargetException | NoClassDefFoundError ex) {
        Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, null, ex);
        log.println("Executing post-download failed.");
    } finally {
        System.setOut(originalOut);
        log.reset();
    }
    return false;
}

From source file:azkaban.webapp.AzkabanWebServer.java

private void loadPluginCheckersAndActions(String pluginPath) {
    logger.info("Loading plug-in checker and action types");
    File triggerPluginPath = new File(pluginPath);
    if (!triggerPluginPath.exists()) {
        logger.error("plugin path " + pluginPath + " doesn't exist!");
        return;/*from   w w  w  . j  av  a2s . c  o  m*/
    }

    ClassLoader parentLoader = this.getClassLoader();
    File[] pluginDirs = triggerPluginPath.listFiles();
    ArrayList<String> jarPaths = new ArrayList<String>();
    for (File pluginDir : pluginDirs) {
        if (!pluginDir.exists()) {
            logger.error("Error! Trigger plugin path " + pluginDir.getPath() + " doesn't exist.");
            continue;
        }

        if (!pluginDir.isDirectory()) {
            logger.error("The plugin path " + pluginDir + " is not a directory.");
            continue;
        }

        // Load the conf directory
        File propertiesDir = new File(pluginDir, "conf");
        Props pluginProps = null;
        if (propertiesDir.exists() && propertiesDir.isDirectory()) {
            File propertiesFile = new File(propertiesDir, "plugin.properties");
            File propertiesOverrideFile = new File(propertiesDir, "override.properties");

            if (propertiesFile.exists()) {
                if (propertiesOverrideFile.exists()) {
                    pluginProps = PropsUtils.loadProps(null, propertiesFile, propertiesOverrideFile);
                } else {
                    pluginProps = PropsUtils.loadProps(null, propertiesFile);
                }
            } else {
                logger.error("Plugin conf file " + propertiesFile + " not found.");
                continue;
            }
        } else {
            logger.error("Plugin conf path " + propertiesDir + " not found.");
            continue;
        }

        List<String> extLibClasspath = pluginProps.getStringList("trigger.external.classpaths",
                (List<String>) null);

        String pluginClass = pluginProps.getString("trigger.class");
        if (pluginClass == null) {
            logger.error("Trigger class is not set.");
        } else {
            logger.error("Plugin class " + pluginClass);
        }

        URLClassLoader urlClassLoader = null;
        File libDir = new File(pluginDir, "lib");
        if (libDir.exists() && libDir.isDirectory()) {
            File[] files = libDir.listFiles();

            ArrayList<URL> urls = new ArrayList<URL>();
            for (int i = 0; i < files.length; ++i) {
                try {
                    URL url = files[i].toURI().toURL();
                    urls.add(url);
                } catch (MalformedURLException e) {
                    logger.error(e);
                }
            }
            if (extLibClasspath != null) {
                for (String extLib : extLibClasspath) {
                    try {
                        File file = new File(pluginDir, extLib);
                        URL url = file.toURI().toURL();
                        urls.add(url);
                    } catch (MalformedURLException e) {
                        logger.error(e);
                    }
                }
            }

            urlClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), parentLoader);
        } else {
            logger.error("Library path " + propertiesDir + " not found.");
            continue;
        }

        Class<?> triggerClass = null;
        try {
            triggerClass = urlClassLoader.loadClass(pluginClass);
        } catch (ClassNotFoundException e) {
            logger.error("Class " + pluginClass + " not found.");
            continue;
        }

        String source = FileIOUtils.getSourcePathFromClass(triggerClass);
        logger.info("Source jar " + source);
        jarPaths.add("jar:file:" + source);

        try {
            Utils.invokeStaticMethod(urlClassLoader, pluginClass, "initiateCheckerTypes", pluginProps, app);
        } catch (Exception e) {
            logger.error("Unable to initiate checker types for " + pluginClass);
            continue;
        }

        try {
            Utils.invokeStaticMethod(urlClassLoader, pluginClass, "initiateActionTypes", pluginProps, app);
        } catch (Exception e) {
            logger.error("Unable to initiate action types for " + pluginClass);
            continue;
        }

    }
}

From source file:azkaban.webapp.AzkabanWebServer.java

private Map<String, Alerter> loadPluginAlerters(String pluginPath) {
    File alerterPluginPath = new File(pluginPath);
    if (!alerterPluginPath.exists()) {
        return Collections.<String, Alerter>emptyMap();
    }/*from www .  j  a v  a2s.c  o m*/

    Map<String, Alerter> installedAlerterPlugins = new HashMap<String, Alerter>();
    ClassLoader parentLoader = getClass().getClassLoader();
    File[] pluginDirs = alerterPluginPath.listFiles();
    ArrayList<String> jarPaths = new ArrayList<String>();
    for (File pluginDir : pluginDirs) {
        if (!pluginDir.isDirectory()) {
            logger.error("The plugin path " + pluginDir + " is not a directory.");
            continue;
        }

        // Load the conf directory
        File propertiesDir = new File(pluginDir, "conf");
        Props pluginProps = null;
        if (propertiesDir.exists() && propertiesDir.isDirectory()) {
            File propertiesFile = new File(propertiesDir, "plugin.properties");
            File propertiesOverrideFile = new File(propertiesDir, "override.properties");

            if (propertiesFile.exists()) {
                if (propertiesOverrideFile.exists()) {
                    pluginProps = PropsUtils.loadProps(null, propertiesFile, propertiesOverrideFile);
                } else {
                    pluginProps = PropsUtils.loadProps(null, propertiesFile);
                }
            } else {
                logger.error("Plugin conf file " + propertiesFile + " not found.");
                continue;
            }
        } else {
            logger.error("Plugin conf path " + propertiesDir + " not found.");
            continue;
        }

        String pluginName = pluginProps.getString("alerter.name");
        List<String> extLibClasspath = pluginProps.getStringList("alerter.external.classpaths",
                (List<String>) null);

        String pluginClass = pluginProps.getString("alerter.class");
        if (pluginClass == null) {
            logger.error("Alerter class is not set.");
        } else {
            logger.info("Plugin class " + pluginClass);
        }

        URLClassLoader urlClassLoader = null;
        File libDir = new File(pluginDir, "lib");
        if (libDir.exists() && libDir.isDirectory()) {
            File[] files = libDir.listFiles();

            ArrayList<URL> urls = new ArrayList<URL>();
            for (int i = 0; i < files.length; ++i) {
                try {
                    URL url = files[i].toURI().toURL();
                    urls.add(url);
                } catch (MalformedURLException e) {
                    logger.error(e);
                }
            }
            if (extLibClasspath != null) {
                for (String extLib : extLibClasspath) {
                    try {
                        File file = new File(pluginDir, extLib);
                        URL url = file.toURI().toURL();
                        urls.add(url);
                    } catch (MalformedURLException e) {
                        logger.error(e);
                    }
                }
            }

            urlClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), parentLoader);
        } else {
            logger.error("Library path " + propertiesDir + " not found.");
            continue;
        }

        Class<?> alerterClass = null;
        try {
            alerterClass = urlClassLoader.loadClass(pluginClass);
        } catch (ClassNotFoundException e) {
            logger.error("Class " + pluginClass + " not found.");
            continue;
        }

        String source = FileIOUtils.getSourcePathFromClass(alerterClass);
        logger.info("Source jar " + source);
        jarPaths.add("jar:file:" + source);

        Constructor<?> constructor = null;
        try {
            constructor = alerterClass.getConstructor(Props.class);
        } catch (NoSuchMethodException e) {
            logger.error("Constructor not found in " + pluginClass);
            continue;
        }

        Object obj = null;
        try {
            obj = constructor.newInstance(pluginProps);
        } catch (Exception e) {
            logger.error(e);
        }

        if (!(obj instanceof Alerter)) {
            logger.error("The object is not an Alerter");
            continue;
        }

        Alerter plugin = (Alerter) obj;
        installedAlerterPlugins.put(pluginName, plugin);
    }

    return installedAlerterPlugins;

}

From source file:azkaban.webapp.AzkabanWebServer.java

private static void loadViewerPlugins(Context root, String pluginPath, VelocityEngine ve) {
    File viewerPluginPath = new File(pluginPath);
    if (!viewerPluginPath.exists()) {
        return;//from   ww  w  .ja v a 2 s . c  o  m
    }

    ClassLoader parentLoader = AzkabanWebServer.class.getClassLoader();
    File[] pluginDirs = viewerPluginPath.listFiles();
    ArrayList<String> jarPaths = new ArrayList<String>();
    for (File pluginDir : pluginDirs) {
        if (!pluginDir.exists()) {
            logger.error("Error viewer plugin path " + pluginDir.getPath() + " doesn't exist.");
            continue;
        }

        if (!pluginDir.isDirectory()) {
            logger.error("The plugin path " + pluginDir + " is not a directory.");
            continue;
        }

        // Load the conf directory
        File propertiesDir = new File(pluginDir, "conf");
        Props pluginProps = null;
        if (propertiesDir.exists() && propertiesDir.isDirectory()) {
            File propertiesFile = new File(propertiesDir, "plugin.properties");
            File propertiesOverrideFile = new File(propertiesDir, "override.properties");

            if (propertiesFile.exists()) {
                if (propertiesOverrideFile.exists()) {
                    pluginProps = PropsUtils.loadProps(null, propertiesFile, propertiesOverrideFile);
                } else {
                    pluginProps = PropsUtils.loadProps(null, propertiesFile);
                }
            } else {
                logger.error("Plugin conf file " + propertiesFile + " not found.");
                continue;
            }
        } else {
            logger.error("Plugin conf path " + propertiesDir + " not found.");
            continue;
        }

        String pluginName = pluginProps.getString("viewer.name");
        String pluginWebPath = pluginProps.getString("viewer.path");
        String pluginJobTypes = pluginProps.getString("viewer.jobtypes", null);
        int pluginOrder = pluginProps.getInt("viewer.order", 0);
        boolean pluginHidden = pluginProps.getBoolean("viewer.hidden", false);
        List<String> extLibClasspath = pluginProps.getStringList("viewer.external.classpaths",
                (List<String>) null);

        String pluginClass = pluginProps.getString("viewer.servlet.class");
        if (pluginClass == null) {
            logger.error("Viewer class is not set.");
        } else {
            logger.error("Plugin class " + pluginClass);
        }

        URLClassLoader urlClassLoader = null;
        File libDir = new File(pluginDir, "lib");
        if (libDir.exists() && libDir.isDirectory()) {
            File[] files = libDir.listFiles();

            ArrayList<URL> urls = new ArrayList<URL>();
            for (int i = 0; i < files.length; ++i) {
                try {
                    URL url = files[i].toURI().toURL();
                    urls.add(url);
                } catch (MalformedURLException e) {
                    logger.error(e);
                }
            }

            // Load any external libraries.
            if (extLibClasspath != null) {
                for (String extLib : extLibClasspath) {
                    File extLibFile = new File(pluginDir, extLib);
                    if (extLibFile.exists()) {
                        if (extLibFile.isDirectory()) {
                            // extLibFile is a directory; load all the files in the
                            // directory.
                            File[] extLibFiles = extLibFile.listFiles();
                            for (int i = 0; i < extLibFiles.length; ++i) {
                                try {
                                    URL url = extLibFiles[i].toURI().toURL();
                                    urls.add(url);
                                } catch (MalformedURLException e) {
                                    logger.error(e);
                                }
                            }
                        } else { // extLibFile is a file
                            try {
                                URL url = extLibFile.toURI().toURL();
                                urls.add(url);
                            } catch (MalformedURLException e) {
                                logger.error(e);
                            }
                        }
                    } else {
                        logger.error("External library path " + extLibFile.getAbsolutePath() + " not found.");
                        continue;
                    }
                }
            }

            urlClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), parentLoader);
        } else {
            logger.error("Library path " + libDir.getAbsolutePath() + " not found.");
            continue;
        }

        Class<?> viewerClass = null;
        try {
            viewerClass = urlClassLoader.loadClass(pluginClass);
        } catch (ClassNotFoundException e) {
            logger.error("Class " + pluginClass + " not found.");
            continue;
        }

        String source = FileIOUtils.getSourcePathFromClass(viewerClass);
        logger.info("Source jar " + source);
        jarPaths.add("jar:file:" + source);

        Constructor<?> constructor = null;
        try {
            constructor = viewerClass.getConstructor(Props.class);
        } catch (NoSuchMethodException e) {
            logger.error("Constructor not found in " + pluginClass);
            continue;
        }

        Object obj = null;
        try {
            obj = constructor.newInstance(pluginProps);
        } catch (Exception e) {
            logger.error(e);
            logger.error(e.getCause());
        }

        if (!(obj instanceof AbstractAzkabanServlet)) {
            logger.error("The object is not an AbstractAzkabanServlet");
            continue;
        }

        AbstractAzkabanServlet avServlet = (AbstractAzkabanServlet) obj;
        root.addServlet(new ServletHolder(avServlet), "/" + pluginWebPath + "/*");
        PluginRegistry.getRegistry().register(
                new ViewerPlugin(pluginName, pluginWebPath, pluginOrder, pluginHidden, pluginJobTypes));
    }

    // Velocity needs the jar resource paths to be set.
    String jarResourcePath = StringUtils.join(jarPaths, ", ");
    logger.info("Setting jar resource path " + jarResourcePath);
    ve.addProperty("jar.resource.loader.path", jarResourcePath);
}

From source file:gov.anl.cue.arcane.engine.matrix.MatrixModel.java

/**
 * Run the matrix model.// ww w  .j av a2s .co  m
 *
 * @return the double
 */
public Double runMatrixModel() {

    // Create a results holder.
    Double results = Double.NaN;

    // Attempt to run the model.
    try {

        // Setup a temporary class loader.
        URL[] urls = new URL[] { new File(Util.TEMP_DIR).toURI().toURL() };
        URLClassLoader classLoader = new URLClassLoader(urls, null, null);

        // Attempt to load the compiled file.
        @SuppressWarnings("rawtypes")
        Constructor constructor = classLoader
                .loadClass(MatrixModel.PACKAGE_NAME + "." + MatrixModel.CONCRETE_CLASS_NAME)
                .getDeclaredConstructor(double.class);
        constructor.setAccessible(true);
        Object object = constructor.newInstance(this.stepSize);

        // Call "matrixFormulation.step(steps)".
        Method method = object.getClass().getSuperclass().getMethod("step", int.class);
        method.invoke(object, this.stepCount);

        // Call matrixFormulation.calculateFitnessValue();
        method = object.getClass().getSuperclass().getMethod("calculateFitnessValue");
        results = (Double) method.invoke(object);

        // Clear the given class loader, which should not be
        // a child of another class loader.
        object = null;
        method = null;
        classLoader.close();
        ResourceBundle.clearCache(classLoader);
        classLoader = null;
        Introspector.flushCaches();
        System.runFinalization();
        System.gc();

        // Catch exceptions.
    } catch (Exception e) {

        // Return the default result.
        results = Double.NaN;

    }

    // Return the results.
    return results;

}

From source file:org.infoglue.deliver.invokers.ComponentBasedHTMLPageInvoker.java

/**
 * This method renders the base component and all it's children.
 *//*from w  ww.jav  a  2  s . com*/

private String preProcessComponent(InfoGlueComponent component, TemplateController templateController,
        Integer repositoryId, Integer siteNodeId, Integer languageId, Integer contentId,
        Integer metainfoContentId, List sortedPageComponents) throws Exception {
    if (logger.isDebugEnabled()) {
        logger.debug("\n\n**** Pre processing component ****");
        logger.debug("id: " + component.getId());
        logger.debug("contentId: " + component.getContentId());
        logger.debug("name: " + component.getName());
        logger.debug("slotName: " + component.getSlotName());
    }

    StringBuilder decoratedComponent = new StringBuilder();

    templateController.setComponentLogic(new ComponentLogic(templateController, component));
    templateController.getDeliveryContext().getUsageListeners()
            .add(templateController.getComponentLogic().getComponentDeliveryContext());

    try {
        String componentString = getComponentPreProcessingTemplateString(templateController,
                component.getContentId(), component);
        if (logger.isDebugEnabled())
            logger.debug("componentString:" + componentString);

        String componentModelClassName = getComponentModelClassName(templateController,
                component.getContentId(), component);
        if (logger.isDebugEnabled())
            logger.debug("componentModelClassName:" + componentModelClassName);

        if (componentModelClassName != null && !componentModelClassName.equals("")) {
            templateController.getDeliveryContext().getUsageListeners()
                    .add(templateController.getComponentLogic().getComponentDeliveryContext());
            try {
                Timer t = new Timer();
                DigitalAssetVO asset = templateController.getAsset(component.getContentId(), "jar");

                String path = templateController.getAssetFilePathForAssetWithId(asset.getId());
                if (logger.isDebugEnabled())
                    logger.debug("path: " + path);
                if (path != null && !path.equals("")) {
                    try {
                        File jarFile = new File(path);
                        if (logger.isDebugEnabled())
                            logger.debug("jarFile:" + jarFile.exists());
                        URL url = jarFile.toURL();
                        URLClassLoader child = new URLClassLoader(new URL[] { url },
                                this.getClass().getClassLoader());

                        Class c = child.loadClass(componentModelClassName);
                        boolean isOk = ComponentModel.class.isAssignableFrom(c);
                        if (logger.isDebugEnabled())
                            logger.debug("isOk:" + isOk + " for " + componentModelClassName);
                        if (isOk) {
                            if (logger.isDebugEnabled())
                                logger.debug("Calling prepare on '" + componentModelClassName + "'");
                            ComponentModel componentModel = (ComponentModel) c.newInstance();
                            componentModel.prepare(componentString, templateController, component.getModel());
                        }
                    } catch (Exception e) {
                        logger.error(
                                "Failed loading custom class from asset JAR. Trying normal class loader. Error:"
                                        + e.getMessage());
                        ComponentModel componentModel = (ComponentModel) Thread.currentThread()
                                .getContextClassLoader().loadClass(componentModelClassName).newInstance();
                        componentModel.prepare(componentString, templateController, component.getModel());
                    }
                } else {
                    ComponentModel componentModel = (ComponentModel) Thread.currentThread()
                            .getContextClassLoader().loadClass(componentModelClassName).newInstance();
                    componentModel.prepare(componentString, templateController, component.getModel());
                }
                if (logger.isDebugEnabled())
                    t.printElapsedTime("Invoking custome class took");
            } catch (Exception e) {
                logger.error("The component '" + component.getName() + "' stated that class: "
                        + componentModelClassName
                        + " should be used as model. An exception was thrown when it was invoked: "
                        + e.getMessage(), e);
            }
            templateController.getDeliveryContext().getUsageListeners()
                    .remove(templateController.getComponentLogic().getComponentDeliveryContext());
        }

        if (componentString != null && !componentString.equals("")) {
            templateController.getDeliveryContext().getUsageListeners()
                    .add(templateController.getComponentLogic().getComponentDeliveryContext());

            Map context = getDefaultContext();
            context.put("templateLogic", templateController);
            context.put("model", component.getModel());
            StringWriter cacheString = new StringWriter();
            PrintWriter cachedStream = new PrintWriter(cacheString);
            //Timer t = new Timer();
            new VelocityTemplateProcessor().renderTemplate(context, cachedStream, componentString, false,
                    component, " - PreTemplate");
            //t.printElapsedTime("Rendering of " + component.getName() + " took ");
            componentString = cacheString.toString();

            if (logger.isDebugEnabled())
                logger.debug("componentString:" + componentString);

            templateController.getDeliveryContext().getUsageListeners()
                    .remove(templateController.getComponentLogic().getComponentDeliveryContext());
        }

        String templateComponentString = getComponentString(templateController, component.getContentId(),
                component);
        if (logger.isDebugEnabled())
            logger.debug("templateComponentString:" + templateComponentString);

        int offset = 0;
        int slotStartIndex = templateComponentString.indexOf("<ig:slot", offset);
        int slotStopIndex = 0;

        while (slotStartIndex > -1) {
            slotStopIndex = templateComponentString.indexOf("</ig:slot>", slotStartIndex);

            String slot = templateComponentString.substring(slotStartIndex, slotStopIndex + 10);
            String id = slot.substring(slot.indexOf("id") + 4, slot.indexOf("\"", slot.indexOf("id") + 4));

            boolean inherit = true;
            int inheritIndex = slot.indexOf("inherit");
            if (inheritIndex > -1) {
                String inheritString = slot.substring(inheritIndex + 9, slot.indexOf("\"", inheritIndex + 9));
                inherit = Boolean.parseBoolean(inheritString);
            }

            List subComponents = getInheritedComponents(templateController.getDatabase(), templateController,
                    component, templateController.getSiteNodeId(), id, inherit);
            Iterator subComponentsIterator = subComponents.iterator();
            while (subComponentsIterator.hasNext()) {
                InfoGlueComponent subComponent = (InfoGlueComponent) subComponentsIterator.next();
                if (subComponent.getIsInherited()) {
                    String subComponentString = preProcessComponent(subComponent, templateController,
                            repositoryId, siteNodeId, languageId, contentId, metainfoContentId,
                            sortedPageComponents);
                }
            }

            offset = slotStopIndex;
            slotStartIndex = templateComponentString.indexOf("<ig:slot", offset);
        }
    } catch (Exception e) {
        logger.warn(
                "An component with either an empty template or with no template in the sitelanguages was found:"
                        + e.getMessage(),
                e);
    }

    templateController.getDeliveryContext().getUsageListeners()
            .remove(templateController.getComponentLogic().getComponentDeliveryContext());

    if (logger.isDebugEnabled())
        logger.debug("decoratedComponent:" + decoratedComponent.toString());

    return decoratedComponent.toString();
}

From source file:com.threerings.getdown.data.Application.java

/**
 * Runs this application directly in the current VM.
 *//*from w  ww  .j av a 2s .  c o m*/
public void invokeDirect(JApplet applet) throws IOException {
    ClassPath classPath = ClassPaths.buildClassPath(this);
    URL[] jarUrls = classPath.asUrls();

    // create custom class loader
    URLClassLoader loader = new URLClassLoader(jarUrls, ClassLoader.getSystemClassLoader()) {
        @Override
        protected PermissionCollection getPermissions(CodeSource code) {
            Permissions perms = new Permissions();
            perms.add(new AllPermission());
            return perms;
        }
    };
    Thread.currentThread().setContextClassLoader(loader);

    log.info("Configured URL class loader:");
    for (URL url : jarUrls)
        log.info("  " + url);

    // configure any system properties that we can
    for (String jvmarg : _jvmargs) {
        if (jvmarg.startsWith("-D")) {
            jvmarg = processArg(jvmarg.substring(2));
            int eqidx = jvmarg.indexOf("=");
            if (eqidx == -1) {
                log.warning("Bogus system property: '" + jvmarg + "'?");
            } else {
                System.setProperty(jvmarg.substring(0, eqidx), jvmarg.substring(eqidx + 1));
            }
        }
    }

    // pass along any pass-through arguments
    Map<String, String> passProps = new HashMap<String, String>();
    for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
        String key = (String) entry.getKey();
        if (key.startsWith(PROP_PASSTHROUGH_PREFIX)) {
            key = key.substring(PROP_PASSTHROUGH_PREFIX.length());
            passProps.put(key, (String) entry.getValue());
        }
    }
    // we can't set these in the above loop lest we get a ConcurrentModificationException
    for (Map.Entry<String, String> entry : passProps.entrySet()) {
        System.setProperty(entry.getKey(), entry.getValue());
    }

    // make a note that we're running in "applet" mode
    System.setProperty("applet", "true");

    // prepare our app arguments
    String[] args = new String[_appargs.size()];
    for (int ii = 0; ii < args.length; ii++)
        args[ii] = processArg(_appargs.get(ii));

    try {
        log.info("Loading " + _class);
        Class<?> appclass = loader.loadClass(_class);
        Method main;
        try {
            // first see if the class has a special applet-aware main
            main = appclass.getMethod("main", JApplet.class, SA_PROTO.getClass());
            log.info("Invoking main(JApplet, {" + StringUtil.join(args, ", ") + "})");
            main.invoke(null, new Object[] { applet, args });
        } catch (NoSuchMethodException nsme) {
            main = appclass.getMethod("main", SA_PROTO.getClass());
            log.info("Invoking main({" + StringUtil.join(args, ", ") + "})");
            main.invoke(null, new Object[] { args });
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}

From source file:com.gele.tools.wow.wdbearmanager.WDBearManager.java

public void init(String[] args) {

    // copy ARGs//  w  w  w  . j  av a2 s . c  o m
    this.parseCommandLine(args);

    // Usefull for debugging
    this.myLogger.debug("java.version: " + System.getProperty("java.version"));
    this.myLogger.debug("java.vendor: " + System.getProperty("java.vendor"));
    this.myLogger.debug("java.vendor.url: " + System.getProperty("java.vendor.url"));
    this.myLogger.debug("os.name: " + System.getProperty("os.name"));
    this.myLogger.debug("os.arch: " + System.getProperty("os.arch"));
    this.myLogger.debug("os.version: " + System.getProperty("os.version"));

    if (this.paramDBconfig.length() != 0) {
        this.WDB_DB_CONFIG_FILE = this.paramDBconfig;
    }

    WDBearManager_API myAPI = new WDBearManager_API(this.WDB_DB_CONFIG_FILE);

    // Create all tables
    // -> Needed for the updata script <-
    // -> Otherwise it may crash with an empty database
    try {
        myAPI.getCountOfTable("creaturecache");
        myAPI.getCountOfTable("gameobjectcache");
        myAPI.getCountOfTable("itemcache");
        myAPI.getCountOfTable("itemnamecache");
        myAPI.getCountOfTable("itemtextchaxhe");
        myAPI.getCountOfTable("npccache");
        myAPI.getCountOfTable("pagetextcache");
        myAPI.getCountOfTable("questcache");
    } catch (Exception ex) {
        // ignore
        ex.printStackTrace();
        System.exit(0);
    }

    // Check, if database must be re-newed
    DBUpdater myDBU = new DBUpdater();
    myDBU.checkForUpdate(myAPI);

    WDBearManager_I myWoWWDBearManager_API = myAPI;

    //
    // print out some statistics
    //

    if (this.useGUI == false) {

        boolean paramSpec = false;
        // ASSERT
        DTO_Interface myDTO = null;

        if (this.paramWdbfile.length() != 0) {
            paramSpec = true;
            // Open WDB
            try {
                this.items = myWoWWDBearManager_API.readWDBfile(this.paramWdbfile);
            } catch (Exception ex) {
                this.myLogger.error("Error reading the WDB file");
                return;
            }
            // first dto -> to identify the data
            Iterator itWDBS = this.items.iterator();
            if (itWDBS.hasNext()) {
                myDTO = (DTO_Interface) itWDBS.next();
            }
        }
        // Create CSV?
        if (this.paramCSVFolder.length() != 0) {
            if (myDTO == null) {
                // NO WDB specified -> exit
                this.myLogger.error("Error: You did not specify -" + this.PARAM_WDBFILE + "\n");
                usage(this.options);
                return;
            }
            File csvFile = new File(this.paramCSVFolder, myDTO.getTableName() + ".csv");
            if (this.useVerbose) {
                this.myLogger.info("Creating CSV file: " + csvFile.getAbsolutePath());
            }
            try {
                WriteCSV.writeCSV(new File(this.paramCSVFolder), this.items);
                this.myLogger.info("CSV file written: " + csvFile.getAbsolutePath());
            } catch (Exception ex) {
                ex.printStackTrace();
                this.myLogger.error("Error writing the CSV file");
                return;
            }
        }
        // Create TXT?
        if (this.paramTXTFolder.length() != 0) {
            if (myDTO == null) {
                // NO WDB specified -> exit
                this.myLogger.error("Error: You did not specify -" + this.PARAM_WDBFILE + "\n");
                usage(this.options);
                return;
            }
            if (this.useVerbose) {
                String table = myDTO.getTableName();
                File txtFile = new File(this.paramTXTFolder, table + ".txt");
                this.myLogger.info("Creating TXT file: " + txtFile.getAbsolutePath());
            }
            try {
                WriteTXT.writeTXT(new File(this.paramTXTFolder), this.items);
            } catch (Exception ex) {
                //ex.printStackTrace();
                this.myLogger.error("Error writing the TXT file: " + ex.getMessage());
                return;
            }
        }
        // Store inside SQL database?
        if (this.writeSQL == true) {
            paramSpec = true;
            if (myDTO == null) {
                // NO WDB specified -> exit
                this.myLogger.error("Error: You did not specify -" + this.PARAM_WDBFILE + "\n");
                usage(this.options);
                return;
            }
            if (this.useVerbose) {
                this.myLogger.info("Storing data inside SQL database");
            }
            SQLManager myWriteSQL = null;
            try {
                myWriteSQL = new SQLManager(this.WDB_DB_CONFIG_FILE);
                ObjectsWritten myOWr = myWriteSQL.insertOrUpdateToSQLDB(this.items, this.doUpdate);
                this.myLogger.info("Operation successfull");
                if (this.useVerbose) {
                    this.myLogger.info("DB statistics");
                    this.myLogger.info("INSERT: " + myOWr.getNumInsert());
                    this.myLogger.info("UPDATE: " + myOWr.getNumUpdate());
                    this.myLogger.info("Error INSERT: " + myOWr.getNumErrorInsert());
                    this.myLogger.info("Error UPDATE: " + myOWr.getNumErrorUpdate());
                    if (this.doUpdate == false) {
                        this.myLogger.info("Objects skipped: " + myOWr.getNumSkipped());
                        System.out.println("If you want to overwrite/update objects, use 'update' param");
                    }
                    this.myLogger.info(WDBearManager.VERSION_INFO);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                this.myLogger.error("Error importing to database");
                this.myLogger.error(ex.getMessage());
                return;
            }
        } // writeSQL

        // Patch *.SCP with contents of database
        if (this.paramSCPname.length() != 0) {
            if (this.paramPatchSCP.length() == 0) {
                this.myLogger.error("Error: You did not specify -" + WDBearManager.PATCH_SCP + "\n");
                usage(this.options);
                return;
            }

            paramSpec = true;
            this.myLogger.info("Patch scp file with the contents of the database");
            try {

                SCPWritten mySCPW = myWoWWDBearManager_API.patchSCP(this.paramSCPname, this.paramPatchSCP,
                        this.patchUTF8, this.paramLocale);
                if (this.useVerbose) {
                    this.myLogger.info("Merge statistics");
                    System.out.println("Entries in database:    " + mySCPW.getNumInDB());
                    this.myLogger.info("Merged with SCP: " + mySCPW.getNumPatched());
                    this.myLogger.info("Patched IDs:      " + mySCPW.getPatchedIDs());
                }
                this.myLogger.info("Patched file: " + this.paramSCPname + "_patch");
            } catch (WDBMgr_IOException ex) {
                this.myLogger.error("The destination SCP file could not be created");
                this.myLogger.error(ex.getMessage());
                return;
            } catch (WDBMgr_NoDataAvailableException ex) {
                this.myLogger.info("Merging impossible");
                this.myLogger.info("There are no entries inside the database");
            } catch (Exception ex) {
                this.myLogger.error("Error while merging quests.scp with database");
                this.myLogger.error(ex.getMessage());
                return;
            }
        } // PatchSCP

        // Call jython script?
        if (this.paramScript.length() != 0) {
            paramSpec = true;
            this.myLogger.info("Calling Jython script");
            this.myLogger.info("---");
            PythonInterpreter interp = new PythonInterpreter();

            interp.set("wdbmgrapi", myWoWWDBearManager_API);
            // set parameters
            Set setKeys = this.paramJython.keySet();
            Iterator itKeys = setKeys.iterator();
            String jyParam = "";
            while (itKeys.hasNext()) {
                jyParam = (String) itKeys.next();
                interp.set(jyParam, (String) this.paramJython.get(jyParam));
            }
            interp.execfile(this.paramScript);

            this.myLogger.info("---");
            System.out.println("Jython script executed, " + WDBearManager.VERSION_INFO);
            return;
        } // paramScript

        if (paramSpec == false) {
            usage(this.options);
            return;
        }

        // Exit
        return;
    } // Command Line Version

    //
    // GUI
    //
    PlasticLookAndFeel.setMyCurrentTheme(new DesertBlue());
    try {
        UIManager.put("ClassLoader", LookUtils.class.getClassLoader());
        UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
    } catch (Exception e) {
    }
    //    try {
    //      com.incors.plaf.kunststoff.KunststoffLookAndFeel kunststoffLnF = new com.incors.plaf.kunststoff.KunststoffLookAndFeel();
    //      KunststoffLookAndFeel
    //          .setCurrentTheme(new com.incors.plaf.kunststoff.KunststoffTheme());
    //      UIManager.setLookAndFeel(kunststoffLnF);
    //    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    //      // handle exception or not, whatever you prefer
    //    }
    //     this line needs to be implemented in order to make JWS work properly
    UIManager.getLookAndFeelDefaults().put("ClassLoader", getClass().getClassLoader());

    this.setTitle(WDBearManager.VERSION_INFO);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.getContentPane().setLayout(new BorderLayout());

    // construct GUI to display the stuff
    // Menu
    //  Where the GUI is created:
    JMenuBar menuBar;
    JMenu menu; //, submenu;
    JMenuItem menuItem;
    //JRadioButtonMenuItem rbMenuItem;
    //JCheckBoxMenuItem cbMenuItem;

    //    Create the menu bar.
    menuBar = new JMenuBar();

    //    Build the first menu.
    menu = new JMenu("File");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("Process WDB files");
    menuBar.add(menu);

    // Exit
    menuItem = new JMenuItem(MENU_EXIT, KeyEvent.VK_T);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Exit program");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //    Build the first menu.
    menu = new JMenu("About");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("Whassup?");
    menuBar.add(menu);
    // Help
    menuItem = new JMenuItem(MENU_HELP, KeyEvent.VK_H);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Help me...");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    // JavaDocs
    menuItem = new JMenuItem(MENU_JDOCS, KeyEvent.VK_J);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Show API docs...");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    // separator
    menu.addSeparator();
    // CheckForUpdate
    menuItem = new JMenuItem(MENU_CHECKUPDATE, KeyEvent.VK_U);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Check for update...");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    // separator
    menu.addSeparator();
    // ABOUT
    menuItem = new JMenuItem(MENU_ABOUT, KeyEvent.VK_T);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Ueber...");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    this.setJMenuBar(menuBar);

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayout(0, 1));

    JTabbedPane tabbedPane = new JTabbedPane();
    ImageIcon wowIcon = createImageIcon("images/fromdisk.gif");

    JComponent panel1 = new WDB_Panel(myWoWWDBearManager_API);
    tabbedPane.addTab("WDB-Module", wowIcon, panel1, "Handle WDB files");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

    ImageIcon panelIcon = createImageIcon("images/hsql.gif");
    JComponent panel2 = null;
    try {
        panel2 = new SQL_Panel(myWoWWDBearManager_API);
    } catch (Throwable ex) {
        System.err.println("Error while instantiating SQL Panel: ");
        System.err.println(ex.getMessage());
        ex.printStackTrace();
        System.exit(0);
    }
    tabbedPane.addTab("DB-Module", panelIcon, panel2, "Handle database");
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

    panelIcon = createImageIcon("images/pythonpoweredsmall.gif");
    JComponent panel3 = new Python_Panel(myWoWWDBearManager_API);
    tabbedPane.addTab("Scripts", panelIcon, panel3, "Scripting");
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);

    // maybe user PLUGIN availabe
    // -> check for folders below "plugins"
    File filUserPanels = new File("plugins");
    // 1) find user plugins (scan for directories)
    // 2) scan for <name>.properties, where <name> is the name of the directory
    // 3) load the properties file and get the plugin running
    String[] strUserPlugins = filUserPanels.list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return (new File(dir, name).isDirectory());
        }
    });
    if (strUserPlugins != null) {
        ArrayList urlJars = new ArrayList();

        //URL[] urlJars = new URL[strUserPlugins.length];
        String strCurrJar = "";
        String strPlugins[] = new String[strUserPlugins.length];
        try {
            for (int i = 0; i < strUserPlugins.length; i++) {
                File baseFile = new File("plugins", strUserPlugins[i]);
                File filProperties = new File(baseFile, strUserPlugins[i] + ".properties");
                if (filProperties.exists()) {
                    // set plugin folder and .properties name
                    strPlugins[i] = strUserPlugins[i];
                    this.myLogger.info("Found 'plugin' : " + baseFile.getAbsolutePath());
                    this.myLogger.info("                 Trying to load .jar file");

                    // Scan for JAR files and include them
                    //System.out.println(baseFile.getAbsolutePath());
                    String[] strJars = baseFile.list(new FilenameFilter() {
                        public boolean accept(File dir, String name) {
                            return name.endsWith(".jar");
                        }
                    });
                    for (int j = 0; j < strJars.length; j++) {
                        File filJAR = new File(baseFile, strJars[j]);
                        strCurrJar = filJAR.getAbsolutePath();

                        this.myLogger.info("Loading external 'plugin' JAR: " + strCurrJar);
                        URL jarfile = new URL("jar", "", "file:" + strCurrJar + "!/");
                        urlJars.add(jarfile);
                    }

                } else {
                    // print warning - a directory inside plugins, but there is no plugin
                    this.myLogger.warn("Found directory inside plugins folder, but no .properties file");
                    this.myLogger.warn("      Name of directory: " + strUserPlugins[i]);
                    this.myLogger.warn("      Please review the directory!");
                }
            } // for... all user plugins
        } catch (Exception ex) {
            this.myLogger.error("Plugin: Error loading " + strCurrJar);
            this.myLogger.error("Please check your 'plugin' folder");
        }
        URLClassLoader cl = null;
        try {
            //      File file = new File("plugins", strUserJars[i]);
            //      this.myLogger.info("Lade externes JAR: " + file.getAbsolutePath());
            //      URL jarfile = new URL("jar", "", "file:" + file.getAbsolutePath() + "!/");
            URL[] loadURLs = new URL[urlJars.toArray().length];
            for (int j = 0; j < urlJars.toArray().length; j++) {
                loadURLs[j] = (URL) urlJars.get(j);
            }
            cl = URLClassLoader.newInstance(loadURLs);

            Thread.currentThread().setContextClassLoader(cl);

            //      String lcStr = "Test";
            //      Class loadedClass = cl.loadClass(lcStr);
            //      this.myLogger.info("Smooth...");

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // 2) load properties and instantiate the plugin
        //      String[] strPlugins = filUserPanels.list(new FilenameFilter() {
        //        public boolean accept(File dir, String name) {
        //          return (name.endsWith("_plugin.properties"));
        //        }
        //      });
        String strPluginName = "";
        String strPluginClass = "";
        String strPluginImage = "";
        WDBearPlugin pluginPanel = null;
        for (int i = 0; i < strPlugins.length; i++) {
            //this.myLogger.info(strPlugins[i]);
            Properties prpPlugin = null;
            try {
                prpPlugin = ReadPropertiesFile.readProperties(
                        new File("plugins", strPlugins[i] + "/" + strPlugins[i]).getAbsolutePath()
                                + ".properties");
            } catch (Exception ex) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Could not load properties file");
                continue;
            }
            if ((strPluginClass = prpPlugin.getProperty(this.PLUGIN_CLASS)) == null) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Property '" + this.PLUGIN_CLASS + "' not found");
                continue;
            }
            if ((strPluginName = prpPlugin.getProperty(this.PLUGIN_NAME)) == null) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Property '" + this.PLUGIN_NAME + "' not found");
                continue;
            }
            if ((strPluginImage = prpPlugin.getProperty(this.PLUGIN_IMAGE)) == null) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Property '" + this.PLUGIN_IMAGE + "' not found");
                continue;
            }

            File filPlgImg = new File("plugins", strPlugins[i] + "/" + strPluginImage);
            panelIcon = createImageIcon(filPlgImg.getAbsolutePath());
            if (panelIcon == null) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Could not read image '" + strPluginImage + "'");
                continue;
            }
            try {
                pluginPanel = (WDBearPlugin) (cl.loadClass(strPluginClass).newInstance());
                pluginPanel.runPlugin(myAPI);
            } catch (Exception ex) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Could not instantiate '" + strPluginClass + "'");
                ex.printStackTrace();
                continue;
            }
            tabbedPane.addTab(strPluginName, panelIcon, pluginPanel, strPluginName);
        } // Plugins
    } // plugins folder found

    mainPanel.add(tabbedPane);

    this.getContentPane().add(mainPanel, BorderLayout.CENTER);

    this.setSize(1024, 768);
    //this.pack();
    this.show();

}