List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getAutowireCapableBeanFactory
@Override public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException
From source file:org.easyrec.plugin.container.PluginRegistry.java
private void installGenerator(final URI pluginId, final Version version, final PluginVO plugin, final ClassPathXmlApplicationContext cax, final Generator<GeneratorConfiguration, GeneratorStatistics> generator) { cax.getAutowireCapableBeanFactory().autowireBeanProperties(generator, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); if (generator.getConfiguration() == null) { GeneratorConfiguration generatorConfiguration = generator.newConfiguration(); generator.setConfiguration(generatorConfiguration); }//from w w w . j a v a 2s. c o m if (LifecyclePhase.NOT_INSTALLED.toString().equals(plugin.getState())) generator.install(true); else generator.install(false); pluginDAO.updatePluginState(pluginId, version, LifecyclePhase.INSTALLED.toString()); generator.initialize(); generators.put(generator.getId(), generator); contexts.put(generator.getId(), cax); logger.info("registered plugin " + generator.getSourceType()); pluginDAO.updatePluginState(pluginId, version, LifecyclePhase.INITIALIZED.toString()); }
From source file:org.easyrec.plugin.container.PluginRegistry.java
@SuppressWarnings({ "unchecked" }) public PluginVO checkPlugin(byte[] file) throws Exception { PluginVO plugin;//from w w w. jav a 2s. c om FileOutputStream fos = null; URLClassLoader ucl; ClassPathXmlApplicationContext cax = null; File tmpFile = null; try { if (file == null) throw new IllegalArgumentException("Passed file must not be null!"); tmpFile = File.createTempFile("plugin", null); tmpFile.deleteOnExit(); fos = new FileOutputStream(tmpFile); fos.write(file); fos.close(); // check if plugin is valid ucl = new URLClassLoader(new URL[] { tmpFile.toURI().toURL() }, this.getClass().getClassLoader()); if (ucl.getResourceAsStream(DEFAULT_PLUGIN_CONFIG_FILE) != null) { cax = new ClassPathXmlApplicationContext(new String[] { DEFAULT_PLUGIN_CONFIG_FILE }, false, appContext); cax.setClassLoader(ucl); logger.info("Classloader: " + cax.getClassLoader()); cax.refresh(); Map<String, GeneratorPluginSupport> beans = cax.getBeansOfType(GeneratorPluginSupport.class); if (beans.isEmpty()) { logger.debug("No class implementing a generator could be found. Plugin rejected!"); throw new Exception("No class implementing a generator could be found. Plugin rejected!"); } Generator<GeneratorConfiguration, GeneratorStatistics> generator = beans.values().iterator().next(); logger.info(String.format("Plugin successfully validated! class: %s name: %s, id: %s", generator.getClass(), generator.getDisplayName(), generator.getId())); cax.getAutowireCapableBeanFactory().autowireBeanProperties(generator, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); plugin = new PluginVO(generator.getDisplayName(), generator.getId().getUri(), generator.getId().getVersion(), LifecyclePhase.NOT_INSTALLED.toString(), file, null); if (tmpFile.delete()) logger.info("tmpFile deleted successfully"); return plugin; } else { // config file not found logger.debug("No valid config file found in the supplied .jar file. Plugin rejected!"); throw new Exception("No valid config file found in the supplied .jar file. Plugin rejected!"); } } catch (Exception e) { logger.error("An Exception occurred while checking the plugin!", e); throw e; } finally { if (fos != null) fos.close(); if ((cax != null) && (!cax.isActive())) cax.close(); if (tmpFile != null) try { if (!tmpFile.delete()) logger.warn("could not delete tmpFile"); } catch (SecurityException se) { logger.error("Could not delete temporary file! Please check permissions!", se); } } }
From source file:org.springframework.integration.monitor.HandlerMonitoringIntegrationTests.java
private ClassPathXmlApplicationContext createContext(String config, String channelName) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config, getClass()); context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); channel = context.getBean(channelName, MessageChannel.class); return context; }