use of org.springframework.context.support.GenericApplicationContext in project pentaho-platform by pentaho.
the class PentahoSystemPluginManager method unloadPlugins.
private void unloadPlugins() {
// is called within the synchronized block in reload
for (IPlatformPlugin plugin : PentahoSystem.getAll(IPlatformPlugin.class)) {
try {
plugin.unLoaded();
// if a spring app context was registered for this plugin, remove and close it
final GenericApplicationContext appContext = PentahoSystem.get(GenericApplicationContext.class, null, Collections.singletonMap(PLUGIN_ID, plugin.getId()));
if (appContext != null) {
final StandaloneSpringPentahoObjectFactory pentahoObjectFactory = StandaloneSpringPentahoObjectFactory.getInstance(appContext);
if (pentahoObjectFactory != null) {
PentahoSystem.deregisterObjectFactory(pentahoObjectFactory);
}
appContext.close();
}
} catch (Throwable t) {
// we do not want any type of exception to leak out and cause a problem here
// A plugin unload should not adversely affect anything downstream, it should
// log an error and otherwise fail silently
String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0014_PLUGIN_FAILED_TO_PROPERLY_UNLOAD", // $NON-NLS-1$
plugin.getId());
logger.error(getClass().toString(), msg, t);
PluginMessageLogger.add(msg);
}
final ClassLoader classLoader = PentahoSystem.get(ClassLoader.class, null, Collections.singletonMap(PLUGIN_ID, plugin.getId()));
if (classLoader != null) {
try {
((PluginClassLoader) classLoader).close();
} catch (IOException e) {
logger.error("errror closing plugin clasloader", e);
}
}
}
for (Map.Entry<String, IPentahoObjectRegistration> entry : handleRegistry.entries()) {
entry.getValue().remove();
}
handleRegistry.clear();
}
use of org.springframework.context.support.GenericApplicationContext in project pentaho-platform by pentaho.
the class StandaloneSpringPentahoObjectFactoryTest method testInitFromObject.
public void testInitFromObject() throws Exception {
StandaloneSession session = new StandaloneSession();
StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
File f = new File("src/test/resources/solution/system/pentahoObjects.spring.xml");
FileSystemResource fsr = new FileSystemResource(f);
GenericApplicationContext appCtx = new GenericApplicationContext();
appCtx.refresh();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx);
xmlReader.loadBeanDefinitions(fsr);
factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", appCtx);
GoodObject obj = factory.get(GoodObject.class, session);
assertNotNull(obj);
}
use of org.springframework.context.support.GenericApplicationContext in project wso2-synapse by wso2.
the class SpringMediator method buildAppContext.
private synchronized void buildAppContext(MessageContext synCtx, SynapseLog synLog) {
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Creating Spring ApplicationContext from key : " + configKey);
}
GenericApplicationContext appContext = new GenericApplicationContext();
XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
xbdr.setValidating(false);
Object springConfig = synCtx.getEntry(configKey);
if (springConfig == null) {
String errorMessage = "Cannot look up Spring configuration " + configKey;
log.error(errorMessage);
// throw new SynapseException(errorMessage);
return;
}
xbdr.loadBeanDefinitions(new InputStreamResource(SynapseConfigUtils.getStreamSource(springConfig).getInputStream()));
appContext.refresh();
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Spring ApplicationContext from key : " + configKey + " created");
}
this.appContext = appContext;
}
use of org.springframework.context.support.GenericApplicationContext in project pentaho-platform by pentaho.
the class SystemResourceIT method getSpringApplicationContext.
/**
* Make spring configs available for test
*
* @return ApplicationContext
*/
private ApplicationContext getSpringApplicationContext() {
String[] fns = { "pentahoObjects.spring.xml", "adminPlugins.xml", "sessionStartupActions.xml", "systemListeners.xml", "pentahoSystemConfig.xml", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"repository.spring.xml" };
GenericApplicationContext appCtx = new GenericApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx);
for (String fn : fns) {
// $NON-NLS-1$
File f = new File(getSolutionPath() + SYSTEM_FOLDER + "/" + fn);
if (f.exists()) {
FileSystemResource fsr = new FileSystemResource(f);
xmlReader.loadBeanDefinitions(fsr);
}
}
return appCtx;
}
use of org.springframework.context.support.GenericApplicationContext in project wildfly-camel by wildfly-extras.
the class SpringCamelContextBootstrap method loadBeanDefinitions.
private void loadBeanDefinitions(Resource resource, ClassLoader classLoader) {
applicationContext = new GenericApplicationContext();
applicationContext.setClassLoader(classLoader);
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext) {
@Override
protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() {
NamespaceHandlerResolver defaultResolver = super.createDefaultNamespaceHandlerResolver();
return new SpringCamelContextBootstrap.CamelNamespaceHandlerResolver(defaultResolver);
}
};
xmlReader.loadBeanDefinitions(resource);
}
Aggregations