All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.freedomotic.plugins.impl.BoundleLoaderEvents Maven / Gradle / Ivy

/**
 *
 * Copyright (c) 2009-2014 Freedomotic team
 * http://freedomotic.com
 *
 * This file is part of Freedomotic
 *
 * This Program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This Program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Freedomotic; see the file COPYING.  If not, see
 * .
 */
package com.freedomotic.plugins.impl;

import com.freedomotic.api.Client;
import com.freedomotic.app.Freedomotic;
import com.freedomotic.exceptions.PluginLoadingException;
import com.freedomotic.plugins.impl.BoundleLoader;
import com.freedomotic.util.JarFilter;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
 *
 * @author enrico
 */
class BoundleLoaderEvents implements BoundleLoader {

    private File path;

    BoundleLoaderEvents(File path) {
        this.path = path;
    }

    @Override
    public List loadBoundle()
            throws PluginLoadingException {
        File dir = new File(path.getAbsolutePath());
        List results = new ArrayList();

        if (dir.isFile()) {
            //return an empty list
            return results;
        }

        //the list of jars in the current folder
        File[] jarList = dir.listFiles(new JarFilter());

        if (jarList != null) {
            //the list of files in the jar
            for (File jar : jarList) {
                if (jar.isFile()) {
                    List classNames = null;

                    try {
                        classNames = BoundleLoaderFactory.getClassesInside(jar.getAbsolutePath());

                        for (String className : classNames) {
                            String name = className.substring(0, className.length() - 6);
                            Class clazz = BoundleLoaderFactory.getClass(jar, name);
                            Class superclass = clazz.getSuperclass();

                            try {
                                Client plugin = (Client) clazz.newInstance();
                                results.add(plugin);
                            } catch (Exception exception) {
                                LOG.info("Exception raised while loading this event. Skip it.");
                                LOG.severe(Freedomotic.getStackTraceInfo(exception));
                            }
                        }
                    } catch (Exception ex) {
                        LOG.severe(Freedomotic.getStackTraceInfo(ex));
                    }
                }
            }
        }

        return results;
    }

    @Override
    public File getPath() {
        return path;
    }
    private static final Logger LOG = Logger.getLogger(BoundleLoaderEvents.class.getName());
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy