Search in sources :

Example 1 with PluginBeanException

use of org.pentaho.platform.api.engine.PluginBeanException in project pentaho-platform by pentaho.

the class PojoComponent method validateAction.

@Override
protected boolean validateAction() {
    boolean ok = false;
    if (pojo == null && isDefinedInput("class")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        String className = getInputStringValue("class");
        // try to load the class from a plugin
        IPluginManager pluginMgr = PentahoSystem.get(IPluginManager.class, getSession());
        if (pluginMgr != null && pluginMgr.isBeanRegistered(className)) {
            try {
                // "className" is actually the plugin bean id in this case
                pojo = pluginMgr.getBean(className);
            } catch (PluginBeanException e) {
                // $NON-NLS-1$
                error("Could not load bean class from plugin", e);
                return false;
            }
        }
        // the bean class was not found in a plugin, so try the default classloader
        if (pojo == null) {
            try {
                // TODO support loading classes from the solution repository
                Class<?> aClass = getClass().getClassLoader().loadClass(className);
                pojo = aClass.newInstance();
            } catch (Exception ex) {
                // $NON-NLS-1$
                error("Could not load bean class", ex);
                return false;
            }
        }
    }
    if (pojo != null) {
        // By the time we get here, we've got our class
        try {
            Method[] methods = pojo.getClass().getMethods();
            // create a method map
            for (Method method : methods) {
                String name = method.getName();
                Class<?>[] paramTypes = method.getParameterTypes();
                if (name.equals("getOutputs")) {
                    // $NON-NLS-1$
                    runtimeOutputsMethod = method;
                } else if (name.equals("setInputs")) {
                    // $NON-NLS-1$
                    runtimeInputsMethod = method;
                } else if (name.equals("setResources")) {
                    // $NON-NLS-1$
                    resourcesMethod = method;
                } else if (name.equals("setLogger")) {
                    // $NON-NLS-1$
                    if (paramTypes.length == 1 && paramTypes[0] == Log.class) {
                        loggerMethod = method;
                    }
                } else if (name.equals("setSession")) {
                    // $NON-NLS-1$
                    if (paramTypes.length == 1 && paramTypes[0] == IPentahoSession.class) {
                        sessionMethod = method;
                    }
                } else if (name.equalsIgnoreCase("configure")) {
                    // $NON-NLS-1$
                    configureMethod = method;
                } else if (name.startsWith("set")) {
                    // $NON-NLS-1$
                    name = name.substring(3).toUpperCase();
                    if (name.equals("CLASS")) {
                        // $NON-NLS-1$
                        // $NON-NLS-1$
                        warn(Messages.getInstance().getString("PojoComponent.CANNOT_USE_SETCLASS"));
                    } else {
                        if (!setMethods.containsKey(name)) {
                            setMethods.put(name, new ArrayList<Method>());
                        }
                        setMethods.get(name).add(method);
                    }
                } else if (name.startsWith("get")) {
                    // $NON-NLS-1$
                    name = name.substring(3).toUpperCase();
                    getMethods.put(name, method);
                } else if (name.equalsIgnoreCase("execute")) {
                    // $NON-NLS-1$
                    executeMethod = method;
                } else if (name.equalsIgnoreCase("validate")) {
                    // $NON-NLS-1$
                    validateMethod = method;
                } else if (name.equalsIgnoreCase("done")) {
                    // $NON-NLS-1$
                    doneMethod = method;
                }
            }
            ok = true;
        } catch (Throwable ex) {
            // $NON-NLS-1$
            error("Could not load object class", ex);
        }
    }
    return ok;
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Method(java.lang.reflect.Method) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) IPluginManager(org.pentaho.platform.api.engine.IPluginManager)

Example 2 with PluginBeanException

use of org.pentaho.platform.api.engine.PluginBeanException in project pentaho-platform by pentaho.

the class DefaultPluginManager method createServiceConfigs.

/*
   * A utility method to convert plugin version of webservice definition to the official engine version consumable by an
   * IServiceManager
   */
private Collection<ServiceConfig> createServiceConfigs(PluginServiceDefinition pws, IPlatformPlugin plugin, ClassLoader loader) throws PlatformPluginRegistrationException {
    Collection<ServiceConfig> services = new ArrayList<ServiceConfig>();
    // 
    if (pws.getTypes() == null || pws.getTypes().length < 1) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0023_SERVICE_TYPE_UNSPECIFIED", // $NON-NLS-1$
        pws.getId()));
    }
    for (String type : pws.getTypes()) {
        ServiceConfig ws = new ServiceConfig();
        ws.setServiceType(type);
        ws.setTitle(pws.getTitle());
        ws.setDescription(pws.getDescription());
        String serviceClassName = (StringUtils.isEmpty(pws.getServiceClass())) ? pws.getServiceBeanId() : pws.getServiceClass();
        String serviceId;
        if (!StringUtils.isEmpty(pws.getId())) {
            serviceId = pws.getId();
        } else {
            serviceId = serviceClassName;
            if (serviceClassName.indexOf('.') > 0) {
                serviceId = serviceClassName.substring(serviceClassName.lastIndexOf('.') + 1);
            }
        }
        ws.setId(serviceId);
        // Register the service class
        // 
        final String serviceClassKey = // $NON-NLS-1$ //$NON-NLS-2$
        ws.getServiceType() + "-" + ws.getId() + "/" + serviceClassName;
        assertUnique(plugin.getId(), serviceClassKey);
        // defining plugin beans the old way through the plugin provider ifc supports only prototype scope
        BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(serviceClassName).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
        beanFactoryMap.get(plugin.getId()).registerBeanDefinition(serviceClassKey, beanDef);
        if (!this.isBeanRegistered(serviceClassKey)) {
            throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0020_NO_SERVICE_CLASS_REGISTERED", // $NON-NLS-1$
            serviceClassKey));
        }
        // 
        try {
            ws.setServiceClass(loadClass(serviceClassKey));
            ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
            if (pws.getExtraClasses() != null) {
                for (String extraClass : pws.getExtraClasses()) {
                    classes.add(loadClass(extraClass));
                }
            }
            ws.setExtraClasses(classes);
        } catch (PluginBeanException e) {
            throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0021_SERVICE_CLASS_LOAD_FAILED", serviceClassKey), // $NON-NLS-1$
            e);
        }
        services.add(ws);
    }
    return services;
}
Also used : PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) ServiceConfig(org.pentaho.platform.plugin.services.pluginmgr.servicemgr.ServiceConfig) ArrayList(java.util.ArrayList) PluginBeanDefinition(org.pentaho.platform.api.engine.PluginBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Example 3 with PluginBeanException

use of org.pentaho.platform.api.engine.PluginBeanException in project pentaho-platform by pentaho.

the class PentahoSystemPluginManager method createServiceConfigs.

/*
 * A utility method to convert plugin version of webservice definition to the official engine version consumable by an
 * IServiceManager
 */
private Collection<ServiceConfig> createServiceConfigs(PluginServiceDefinition pws, IPlatformPlugin plugin, ClassLoader loader, GenericApplicationContext beanFactory) throws PlatformPluginRegistrationException {
    Collection<ServiceConfig> services = new ArrayList<ServiceConfig>();
    // 
    if (pws.getTypes() == null || pws.getTypes().length < 1) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0023_SERVICE_TYPE_UNSPECIFIED", pws.getId()));
    }
    for (String type : pws.getTypes()) {
        ServiceConfig ws = new ServiceConfig();
        ws.setServiceType(type);
        ws.setTitle(pws.getTitle());
        ws.setDescription(pws.getDescription());
        String serviceClassName = (StringUtils.isEmpty(pws.getServiceClass())) ? pws.getServiceBeanId() : pws.getServiceClass();
        String serviceId;
        if (!StringUtils.isEmpty(pws.getId())) {
            serviceId = pws.getId();
        } else {
            serviceId = serviceClassName;
            if (serviceClassName.indexOf('.') > 0) {
                serviceId = serviceClassName.substring(serviceClassName.lastIndexOf('.') + 1);
            }
        }
        ws.setId(serviceId);
        // Register the service class
        // 
        final String serviceClassKey = ws.getServiceType() + "-" + ws.getId() + "/" + serviceClassName;
        assertUnique(beanFactory, plugin.getId(), serviceClassKey);
        // defining plugin beans the old way through the plugin provider ifc supports only prototype scope
        BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(serviceClassName).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
        beanFactory.registerBeanDefinition(serviceClassKey, beanDef);
        if (!this.isBeanRegistered(serviceClassKey)) {
            throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0020_NO_SERVICE_CLASS_REGISTERED", serviceClassKey));
        }
        // 
        try {
            ws.setServiceClass(loadClass(serviceClassKey));
            ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
            if (pws.getExtraClasses() != null) {
                for (String extraClass : pws.getExtraClasses()) {
                    classes.add(loadClass(extraClass));
                }
            }
            ws.setExtraClasses(classes);
        } catch (PluginBeanException e) {
            throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0021_SERVICE_CLASS_LOAD_FAILED", serviceClassKey), e);
        }
        services.add(ws);
    }
    return services;
}
Also used : PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) ServiceConfig(org.pentaho.platform.plugin.services.pluginmgr.servicemgr.ServiceConfig) ArrayList(java.util.ArrayList) PluginBeanDefinition(org.pentaho.platform.api.engine.PluginBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Example 4 with PluginBeanException

use of org.pentaho.platform.api.engine.PluginBeanException in project pentaho-platform by pentaho.

the class ChartBeansSystemListener method initPlugins.

/**
 * This methods looks in the chartbeans configuration file, and retrieves the prescribed list of chart plugins
 * (renderers). For each defined renderer, the method then looks to the PluginManager to see if that renderer has been
 * overridden. If it has, then the class defined in the PluginManager will be loaded IN PLACE OF the configuration
 * file's class.
 *
 * @return list of available chart "plugin" (renderer) instances.
 * @throws Exception
 *           if no chart plugins (renderers) are found.
 */
@SuppressWarnings("unchecked")
private List<IChartPlugin> initPlugins() throws Exception {
    ArrayList<IChartPlugin> plugins = new ArrayList<IChartPlugin>();
    HashMap<String, Object> pluginMap = new HashMap<String, Object>();
    // $NON-NLS-1$
    List<Element> nodes = PentahoSystem.getSystemSettings().getSystemSettings(configFile, "bean");
    if (nodes == null || nodes.size() == 0) {
        // $NON-NLS-1$
        String msg = Messages.getInstance().getString("ChartBeansSystemListener.ERROR_0001_CONFIG_MISSING");
        Logger.warn(ChartBeansSystemListener.class.getName(), msg);
        throw new ChartSystemInitializationException(msg);
    }
    Element node;
    String id;
    Object plugin;
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
    for (int i = 0; i < nodes.size(); i++) {
        node = nodes.get(i);
        // $NON-NLS-1$
        id = node.attribute("id").getText();
        // $NON-NLS-1$
        pluginMap.put(id, node.attribute("class").getText());
        // Now let's see if there is a plugin overriding this engine...
        if ((null != pluginManager) && (pluginManager.isBeanRegistered(id))) {
            try {
                plugin = pluginManager.getBean(id);
                pluginMap.put(id, plugin);
            } catch (PluginBeanException e) {
                Logger.warn(ChartBeansSystemListener.class.getName(), Messages.getInstance().getString("ChartBeansSystemListener.ERROR_0002_PLUGINMANAGER_BEAN_MISSING", // $NON-NLS-1$
                id), e);
            }
        }
    }
    for (Object clazz : pluginMap.values()) {
        try {
            if (clazz instanceof String) {
                plugins.add((IChartPlugin) Class.forName(clazz.toString()).newInstance());
            } else {
                plugins.add((IChartPlugin) clazz);
            }
        } catch (Exception ex) {
            Logger.warn(ChartBeansSystemListener.class.getName(), Messages.getInstance().getString("ChartBeansSystemListener.ERROR_0003_CLASS_CREATION_PROBLEM") + clazz, // $NON-NLS-1$
            ex);
        }
    }
    return plugins;
}
Also used : IChartPlugin(org.pentaho.chart.plugin.IChartPlugin) HashMap(java.util.HashMap) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) IPluginManager(org.pentaho.platform.api.engine.IPluginManager)

Aggregations

PluginBeanException (org.pentaho.platform.api.engine.PluginBeanException)4 ArrayList (java.util.ArrayList)3 IPluginManager (org.pentaho.platform.api.engine.IPluginManager)2 PlatformPluginRegistrationException (org.pentaho.platform.api.engine.PlatformPluginRegistrationException)2 PluginBeanDefinition (org.pentaho.platform.api.engine.PluginBeanDefinition)2 ServiceConfig (org.pentaho.platform.plugin.services.pluginmgr.servicemgr.ServiceConfig)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Element (org.dom4j.Element)1 IChartPlugin (org.pentaho.chart.plugin.IChartPlugin)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1