Search in sources :

Example 1 with ComponentDefinitionsFactory

use of org.apache.struts.tiles.ComponentDefinitionsFactory in project sonar-java by SonarSource.

the class ReloadableDefinitionsFactory method reload.

/**
 * Reload underlying factory.
 * Reload is done by creating a new factory instance, and replacing the old instance
 * with the new one.
 * @param servletContext Current servlet context.
 * @throws DefinitionsFactoryException If factory creation fails.
 */
public void reload(ServletContext servletContext) throws DefinitionsFactoryException {
    ComponentDefinitionsFactory newInstance = createFactory(servletContext, properties);
    factory = newInstance;
}
Also used : ComponentDefinitionsFactory(org.apache.struts.tiles.ComponentDefinitionsFactory)

Example 2 with ComponentDefinitionsFactory

use of org.apache.struts.tiles.ComponentDefinitionsFactory in project sonar-java by SonarSource.

the class ReloadableDefinitionsFactory method createFactoryFromClassname.

/**
 * Create Definition factory from provided classname.
 * If a factory class name is provided, a factory of this class is created. Otherwise,
 * a default factory is created.
 * Factory must have a constructor taking ServletContext and Map as parameter.
 * @param classname Class name of the factory to create.
 * @param servletContext Servlet Context passed to newly created factory.
 * @param properties Map of name/property passed to newly created factory.
 * @return newly created factory.
 * @throws DefinitionsFactoryException If an error occur while initializing factory
 */
public ComponentDefinitionsFactory createFactoryFromClassname(ServletContext servletContext, Map properties, String classname) throws DefinitionsFactoryException {
    if (classname == null) {
        return createFactory(servletContext, properties);
    }
    // Try to create from classname
    try {
        Class factoryClass = RequestUtils.applicationClass(classname);
        ComponentDefinitionsFactory factory = (ComponentDefinitionsFactory) factoryClass.newInstance();
        factory.initFactory(servletContext, properties);
        return factory;
    } catch (ClassCastException ex) {
        // Bad classname
        throw new DefinitionsFactoryException("Error - createDefinitionsFactory : Factory class '" + classname + " must implements 'ComponentDefinitionsFactory'.", ex);
    } catch (ClassNotFoundException ex) {
        // Bad classname
        throw new DefinitionsFactoryException("Error - createDefinitionsFactory : Bad class name '" + classname + "'.", ex);
    } catch (InstantiationException ex) {
        // Bad constructor or error
        throw new DefinitionsFactoryException(ex);
    } catch (IllegalAccessException ex) {
        throw new DefinitionsFactoryException(ex);
    }
}
Also used : ComponentDefinitionsFactory(org.apache.struts.tiles.ComponentDefinitionsFactory) DefinitionsFactoryException(org.apache.struts.tiles.DefinitionsFactoryException)

Example 3 with ComponentDefinitionsFactory

use of org.apache.struts.tiles.ComponentDefinitionsFactory in project sonar-java by SonarSource.

the class ComponentDefinitionsFactoryWrapper method setConfig.

/**
 * Set underlying factory configuration.
 * @param config DefinitionsFactoryConfig to use.
 * @param servletContext Our servlet context.
 */
public void setConfig(DefinitionsFactoryConfig config, ServletContext servletContext) throws DefinitionsFactoryException {
    ComponentDefinitionsFactory newFactory = createFactoryInstance(config.getFactoryClassname());
    newFactory.initFactory(servletContext, createConfigMap(config));
    factory = newFactory;
}
Also used : ComponentDefinitionsFactory(org.apache.struts.tiles.ComponentDefinitionsFactory)

Example 4 with ComponentDefinitionsFactory

use of org.apache.struts.tiles.ComponentDefinitionsFactory in project sonar-java by SonarSource.

the class ComponentDefinitionsFactoryWrapper method createFactoryInstance.

/**
 * Create Definition factory from provided classname which must implement {@link ComponentDefinitionsFactory}.
 * Factory class must extend {@link DefinitionsFactory}.
 * @param classname Class name of the factory to create.
 * @return newly created factory.
 * @throws DefinitionsFactoryException If an error occur while initializing factory
 */
protected ComponentDefinitionsFactory createFactoryInstance(String classname) throws DefinitionsFactoryException {
    try {
        Class factoryClass = RequestUtils.applicationClass(classname);
        Object factory = factoryClass.newInstance();
        return (ComponentDefinitionsFactory) factory;
    } catch (ClassCastException ex) {
        // Bad classname
        throw new DefinitionsFactoryException("Error - createDefinitionsFactory : Factory class '" + classname + " must implement 'DefinitionsFactory'.", ex);
    } catch (ClassNotFoundException ex) {
        // Bad classname
        throw new DefinitionsFactoryException("Error - createDefinitionsFactory : Bad class name '" + classname + "'.", ex);
    } catch (InstantiationException ex) {
        // Bad constructor or error
        throw new DefinitionsFactoryException(ex);
    } catch (IllegalAccessException ex) {
        throw new DefinitionsFactoryException(ex);
    }
}
Also used : ComponentDefinitionsFactory(org.apache.struts.tiles.ComponentDefinitionsFactory) DefinitionsFactoryException(org.apache.struts.tiles.DefinitionsFactoryException)

Aggregations

ComponentDefinitionsFactory (org.apache.struts.tiles.ComponentDefinitionsFactory)4 DefinitionsFactoryException (org.apache.struts.tiles.DefinitionsFactoryException)2