Search in sources :

Example 1 with IContentGeneratorInfo

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

the class PentahoSystemPluginManager method registerContentGenerators.

private void registerContentGenerators(IPlatformPlugin plugin, ClassLoader loader, final GenericApplicationContext beanFactory) throws PlatformPluginRegistrationException {
    // register the content generators
    for (final IContentGeneratorInfo cgInfo : plugin.getContentGenerators()) {
        // define the bean in the factory
        BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(cgInfo.getClassname()).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
        // register bean with alias of content generator id (old way)
        beanFactory.registerBeanDefinition(cgInfo.getId(), beanDef);
        // register bean with alias of type (with default perspective) as well (new way)
        beanFactory.registerAlias(cgInfo.getId(), cgInfo.getType());
        PluginMessageLogger.add(Messages.getInstance().getString("PluginManager.USER_CONTENT_GENERATOR_REGISTERED", cgInfo.getId(), plugin.getId()));
        final HashMap<String, Object> attributes = new HashMap<String, Object>();
        attributes.put(PLUGIN_ID, plugin.getId());
        attributes.put(CONTENT_TYPE, cgInfo.getType());
        final IPentahoObjectRegistration referenceHandle = PentahoSystem.registerReference(new PrototypePentahoObjectReference.Builder<IContentGenerator>(IContentGenerator.class).creator(new IObjectCreator<IContentGenerator>() {

            @Override
            public IContentGenerator create(IPentahoSession session) {
                return (IContentGenerator) beanFactory.getBean(cgInfo.getId());
            }
        }).attributes(attributes).build(), IContentGenerator.class);
        registerReference(plugin.getId(), referenceHandle);
    }
    // The remaining operations require a beanFactory
    if (beanFactory == null) {
        return;
    }
    String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory.getBeanFactory(), IContentGenerator.class);
    ArrayList<String> ids = new ArrayList<String>();
    for (String beanName : names) {
        ids.add(beanName);
        Collections.addAll(ids, beanFactory.getAliases(beanName));
    }
    for (final String beanName : ids) {
        final HashMap<String, Object> attributes = new HashMap<String, Object>();
        attributes.put(PLUGIN_ID, plugin.getId());
        attributes.put(CONTENT_TYPE, beanName);
        final IPentahoObjectRegistration referenceHandle = PentahoSystem.registerReference(new PrototypePentahoObjectReference.Builder<IContentGenerator>(IContentGenerator.class).creator(new IObjectCreator<IContentGenerator>() {

            @Override
            public IContentGenerator create(IPentahoSession session) {
                return (IContentGenerator) beanFactory.getBean(beanName);
            }
        }).attributes(attributes).build(), IContentGenerator.class);
        registerReference(plugin.getId(), referenceHandle);
    }
}
Also used : IContentGeneratorInfo(org.pentaho.platform.api.engine.IContentGeneratorInfo) IObjectCreator(org.pentaho.platform.api.engine.IObjectCreator) HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ArrayList(java.util.ArrayList) PluginBeanDefinition(org.pentaho.platform.api.engine.PluginBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) IContentGenerator(org.pentaho.platform.api.engine.IContentGenerator) IPentahoObjectRegistration(org.pentaho.platform.api.engine.IPentahoObjectRegistration)

Example 2 with IContentGeneratorInfo

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

the class DefaultPluginManager method registerContentGenerators.

private void registerContentGenerators(IPlatformPlugin plugin, ClassLoader loader) throws PlatformPluginRegistrationException {
    // register the content generators
    for (IContentGeneratorInfo cgInfo : plugin.getContentGenerators()) {
        // define the bean in the factory
        BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(cgInfo.getClassname()).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
        GenericApplicationContext factory = beanFactoryMap.get(plugin.getId());
        // register bean with alias of content generator id (old way)
        factory.registerBeanDefinition(cgInfo.getId(), beanDef);
        // register bean with alias of type (with default perspective) as well (new way)
        factory.registerAlias(cgInfo.getId(), cgInfo.getType());
        PluginMessageLogger.add(Messages.getInstance().getString("PluginManager.USER_CONTENT_GENERATOR_REGISTERED", cgInfo.getId(), // $NON-NLS-1$
        plugin.getId()));
    }
}
Also used : IContentGeneratorInfo(org.pentaho.platform.api.engine.IContentGeneratorInfo) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) PluginBeanDefinition(org.pentaho.platform.api.engine.PluginBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 3 with IContentGeneratorInfo

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

the class SystemPathXmlPluginProvider method processContentGenerators.

protected void processContentGenerators(PlatformPlugin plugin, Document doc, IPentahoSession session, String folder, boolean hasLib) {
    // look for content generators
    // $NON-NLS-1$
    List<?> nodes = doc.selectNodes("//content-generator");
    for (Object obj : nodes) {
        Element node = (Element) obj;
        // $NON-NLS-1$
        String className = getProperty(node, "class");
        if (className == null) {
            // $NON-NLS-1$
            className = XmlDom4JHelper.getNodeText("classname", node, null);
        }
        // $NON-NLS-1$
        String id = node.attributeValue("id");
        // $NON-NLS-1$
        String type = node.attributeValue("type");
        // $NON-NLS-1$
        String url = node.attributeValue("url");
        // $NON-NLS-1$
        String title = getProperty(node, "title");
        // $NON-NLS-1$
        String description = getProperty(node, "description");
        try {
            if (id != null && type != null && className != null && title != null) {
                try {
                    IContentGeneratorInfo info = createContentGenerator(plugin, id, title, description, type, url, className, session, folder);
                    plugin.addContentGenerator(info);
                } catch (Exception e) {
                    PluginMessageLogger.add(Messages.getInstance().getString("PluginManager.USER_CONTENT_GENERATOR_NOT_REGISTERED", id, // $NON-NLS-1$
                    folder));
                }
            } else {
                PluginMessageLogger.add(Messages.getInstance().getString("PluginManager.USER_CONTENT_GENERATOR_NOT_REGISTERED", id, // $NON-NLS-1$
                folder));
            }
        } catch (Exception e) {
            PluginMessageLogger.add(Messages.getInstance().getString("PluginManager.USER_CONTENT_GENERATOR_NOT_REGISTERED", id, // $NON-NLS-1$
            folder));
            Logger.error(getClass().toString(), Messages.getInstance().getErrorString("PluginManager.ERROR_0006_CANNOT_CREATE_CONTENT_GENERATOR_FACTORY", folder), // $NON-NLS-1$
            e);
        }
    }
}
Also used : IContentGeneratorInfo(org.pentaho.platform.api.engine.IContentGeneratorInfo) Element(org.dom4j.Element) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Example 4 with IContentGeneratorInfo

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

the class SystemPathXmlPluginProvider method createContentGenerator.

private static IContentGeneratorInfo createContentGenerator(PlatformPlugin plugin, String id, String title, String description, String type, String url, String className, IPentahoSession session, String location) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    ContentGeneratorInfo info = new ContentGeneratorInfo();
    info.setId(id);
    info.setTitle(title);
    info.setDescription(description);
    // $NON-NLS-1$
    info.setUrl((url != null) ? url : "");
    info.setType(type);
    info.setClassname(className);
    return info;
}
Also used : ContentGeneratorInfo(org.pentaho.platform.engine.core.solution.ContentGeneratorInfo) IContentGeneratorInfo(org.pentaho.platform.api.engine.IContentGeneratorInfo)

Aggregations

IContentGeneratorInfo (org.pentaho.platform.api.engine.IContentGeneratorInfo)4 PluginBeanDefinition (org.pentaho.platform.api.engine.PluginBeanDefinition)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Element (org.dom4j.Element)1 IContentGenerator (org.pentaho.platform.api.engine.IContentGenerator)1 IObjectCreator (org.pentaho.platform.api.engine.IObjectCreator)1 IPentahoObjectRegistration (org.pentaho.platform.api.engine.IPentahoObjectRegistration)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 PlatformPluginRegistrationException (org.pentaho.platform.api.engine.PlatformPluginRegistrationException)1 ContentGeneratorInfo (org.pentaho.platform.engine.core.solution.ContentGeneratorInfo)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1