Search in sources :

Example 1 with IPlugin

use of org.meteoinfo.ui.plugin.IPlugin in project MeteoInfo by meteoinfo.

the class FrmMain method loadApplication.

/**
 * Load an application
 *
 * @param plugin Application
 */
public void loadApplication(Application plugin) {
    this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    try {
        PythonInterpreter interp = this.getConsoleDockable().getInterpreter();
        String path = plugin.getPath();
        interp.exec("import " + path);
        interp.exec("from " + path + ".loadApp import LoadApp");
        PyObject loadClass = interp.get("LoadApp");
        PyObject loadObj = loadClass.__call__();
        IPlugin instance = (IPlugin) loadObj.__tojava__(IPlugin.class);
        instance.setApplication(FrmMain.this);
        instance.setName(plugin.getName());
        plugin.setPluginObject(instance);
        plugin.setLoad(true);
        instance.load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    this.setCursor(Cursor.getDefaultCursor());
}
Also used : PythonInterpreter(org.python.util.PythonInterpreter) PyObject(org.python.core.PyObject) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) IPlugin(org.meteoinfo.ui.plugin.IPlugin)

Example 2 with IPlugin

use of org.meteoinfo.ui.plugin.IPlugin in project MeteoInfo by meteoinfo.

the class FrmAppsManager method readPyApp.

// GEN-LAST:event_formWindowClosed
public Application readPyApp(String path, String fileName) {
    try {
        Application plugin = new Application();
        plugin.setPath(path);
        plugin.setClassName("LoadApp");
        PythonInterpreter interp = this.parent.getConsoleDockable().getInterpreter();
        interp.exec("import " + path);
        interp.exec("from " + path + ".loadApp import LoadApp");
        PyObject loadClass = interp.get("LoadApp");
        PyObject loadObj = loadClass.__call__();
        IPlugin instance = (IPlugin) loadObj.__tojava__(IPlugin.class);
        plugin.setPluginObject(instance);
        return plugin;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : PythonInterpreter(org.python.util.PythonInterpreter) Application(org.meteoinfo.lab.application.Application) PyObject(org.python.core.PyObject) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IPlugin(org.meteoinfo.ui.plugin.IPlugin)

Example 3 with IPlugin

use of org.meteoinfo.ui.plugin.IPlugin in project MeteoInfo by meteoinfo.

the class FrmAppsManager method readApplication.

public Application readApplication(String jarFileName) {
    try {
        Application plugin = new Application();
        plugin.setPath(jarFileName);
        String className = GlobalUtil.getPluginClassName(jarFileName);
        if (className == null) {
            return null;
        } else {
            plugin.setClassName(className);
            URL url = new URL("file:" + plugin.getPath());
            URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { url });
            Class<?> clazz = urlClassLoader.loadClass(plugin.getClassName());
            IPlugin instance = (IPlugin) clazz.newInstance();
            plugin.setPluginObject(instance);
            return plugin;
        }
    } catch (MalformedURLException ex) {
        Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
Also used : MalformedURLException(java.net.MalformedURLException) URLClassLoader(java.net.URLClassLoader) Application(org.meteoinfo.lab.application.Application) URL(java.net.URL) IPlugin(org.meteoinfo.ui.plugin.IPlugin)

Aggregations

MalformedURLException (java.net.MalformedURLException)3 IPlugin (org.meteoinfo.ui.plugin.IPlugin)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Application (org.meteoinfo.lab.application.Application)2 PyObject (org.python.core.PyObject)2 PythonInterpreter (org.python.util.PythonInterpreter)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 SAXException (org.xml.sax.SAXException)1