use of org.pentaho.platform.engine.core.system.objfac.spring.PentahoBeanScopeValidatorPostProcessor in project pentaho-platform by pentaho.
the class StandaloneSpringPentahoObjectFactory method init.
/**
* Initializes this object factory by creating a self-contained Spring {@link ApplicationContext} if one is not passed
* in.
*
* @param configFile the Spring bean definition XML file
* @param context the {@link ApplicationContext} object, if null, then this method will create one
*/
public void init(String configFile, Object context) {
if (context == null) {
// beanFactory = new FileSystemXmlApplicationContext(configFile);
FileSystemXmlApplicationContext appCtx = new FileSystemXmlApplicationContext(configFile);
appCtx.refresh();
appCtx.addBeanFactoryPostProcessor(new PentahoBeanScopeValidatorPostProcessor());
Scope requestScope = new ThreadLocalScope();
appCtx.getBeanFactory().registerScope("request", requestScope);
Scope sessionScope = new ThreadLocalScope();
appCtx.getBeanFactory().registerScope("session", sessionScope);
beanFactory = appCtx;
} else {
if (!(context instanceof ConfigurableApplicationContext)) {
String msg = Messages.getInstance().getErrorString(// $NON-NLS-1$
"StandalonePentahoObjectFactory.ERROR_0001_CONTEXT_NOT_SUPPORTED", getClass().getSimpleName(), "GenericApplicationContext", // $NON-NLS-1$
context.getClass().getName());
throw new IllegalArgumentException(msg);
}
ConfigurableApplicationContext configAppCtx = (ConfigurableApplicationContext) context;
if (configAppCtx.getBeanFactory().getRegisteredScope("request") == null) {
Scope requestScope = new ThreadLocalScope();
configAppCtx.getBeanFactory().registerScope("request", requestScope);
}
if (configAppCtx.getBeanFactory().getRegisteredScope("session") == null) {
Scope sessionScope = new ThreadLocalScope();
configAppCtx.getBeanFactory().registerScope("session", sessionScope);
}
setBeanFactory(configAppCtx);
}
}
use of org.pentaho.platform.engine.core.system.objfac.spring.PentahoBeanScopeValidatorPostProcessor in project pentaho-platform by pentaho.
the class DefaultPluginManager method initializeBeanFactory.
/**
* Initializes a bean factory for serving up instance of plugin classes.
*
* @return an instance of the factory that allows callers to continue to define more beans on it programmatically
*/
protected void initializeBeanFactory(final IPlatformPlugin plugin, final ClassLoader loader) throws PlatformPluginRegistrationException {
if (!(loader instanceof PluginClassLoader)) {
logger.warn("Can't determine plugin dir to load spring file because classloader is not of type PluginClassLoader. " + // $NON-NLS-1$
"This is since we are probably in a unit test");
// $NON-NLS-1$
return;
}
//
// Get the native factory (the factory that comes preconfigured via either Spring bean files or via JUnit test
//
BeanFactory nativeBeanFactory = getNativeBeanFactory(plugin, loader);
//
// Now create the definable factory for accepting old style bean definitions from IPluginProvider
//
GenericApplicationContext beanFactory = null;
if (nativeBeanFactory != null && nativeBeanFactory instanceof GenericApplicationContext) {
beanFactory = (GenericApplicationContext) nativeBeanFactory;
} else {
beanFactory = new GenericApplicationContext();
beanFactory.setClassLoader(loader);
beanFactory.getBeanFactory().setBeanClassLoader(loader);
if (nativeBeanFactory != null) {
beanFactory.getBeanFactory().setParentBeanFactory(nativeBeanFactory);
}
}
beanFactory.addBeanFactoryPostProcessor(new PentahoBeanScopeValidatorPostProcessor());
beanFactoryMap.put(plugin.getId(), beanFactory);
// been made available to the plugin manager
for (PluginBeanDefinition def : plugin.getBeans()) {
// register by classname if id is null
def.setBeanId((def.getBeanId() == null) ? def.getClassname() : def.getBeanId());
assertUnique(plugin.getId(), def.getBeanId());
// defining plugin beans the old way through the plugin provider ifc supports only prototype scope
BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(def.getClassname()).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
beanFactory.registerBeanDefinition(def.getBeanId(), beanDef);
}
StandaloneSpringPentahoObjectFactory pentahoFactory = new StandaloneSpringPentahoObjectFactory("Plugin Factory ( " + plugin.getId() + " )");
pentahoFactory.init(null, beanFactory);
}
use of org.pentaho.platform.engine.core.system.objfac.spring.PentahoBeanScopeValidatorPostProcessor in project pentaho-platform by pentaho.
the class JAXRSServlet method getAppContext.
protected ApplicationContext getAppContext() {
ConfigurableWebApplicationContext wac = new XmlWebApplicationContext() {
@Override
protected Resource getResourceByPath(String path) {
return new FileSystemResource(new File(path));
}
};
wac.setServletContext(getServletContext());
wac.setServletConfig(getServletConfig());
wac.setNamespace(getServletName());
String springFile = PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$ //$NON-NLS-2$
"system" + File.separator + "pentahoServices.spring.xml");
wac.setConfigLocations(new String[] { springFile });
wac.addBeanFactoryPostProcessor(new PentahoBeanScopeValidatorPostProcessor());
wac.refresh();
return wac;
}
use of org.pentaho.platform.engine.core.system.objfac.spring.PentahoBeanScopeValidatorPostProcessor in project pentaho-platform by pentaho.
the class PentahoSystemPluginManager method createBeanFactory.
private GenericApplicationContext createBeanFactory(IPlatformPlugin plugin, ClassLoader classloader) throws PlatformPluginRegistrationException {
if (!(classloader instanceof PluginClassLoader)) {
throw new PlatformPluginRegistrationException("Can't determine plugin dir to load spring file because classloader is not of type PluginClassLoader. " + "This is since we are probably in a unit test");
}
//
// Get the native factory (the factory that comes preconfigured via either Spring bean files or via JUnit test
//
BeanFactory nativeBeanFactory = getNativeBeanFactory(plugin, classloader);
//
// Now create the definable factory for accepting old style bean definitions from IPluginProvider
//
GenericApplicationContext beanFactory = null;
if (nativeBeanFactory != null && nativeBeanFactory instanceof GenericApplicationContext) {
beanFactory = (GenericApplicationContext) nativeBeanFactory;
} else {
beanFactory = new GenericApplicationContext();
beanFactory.setClassLoader(classloader);
beanFactory.getBeanFactory().setBeanClassLoader(classloader);
if (nativeBeanFactory != null) {
beanFactory.getBeanFactory().setParentBeanFactory(nativeBeanFactory);
}
}
beanFactory.addBeanFactoryPostProcessor(new PentahoBeanScopeValidatorPostProcessor());
// been made available to the plugin manager
for (PluginBeanDefinition def : plugin.getBeans()) {
// register by classname if id is null
def.setBeanId((def.getBeanId() == null) ? def.getClassname() : def.getBeanId());
try {
assertUnique(beanFactory, plugin.getId(), def.getBeanId());
} catch (PlatformPluginRegistrationException e) {
logger.error(MessageFormat.format("Unable to register plugin bean, a bean by the id {0} is already defined in plugin: {1}", def.getBeanId(), plugin.getId()));
continue;
}
// defining plugin beans the old way through the plugin provider ifc supports only prototype scope
BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(def.getClassname()).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
beanFactory.registerBeanDefinition(def.getBeanId(), beanDef);
}
return beanFactory;
}
Aggregations