List of usage examples for org.springframework.context.support AbstractApplicationContext getBean
@Override public <T> T getBean(Class<T> requiredType) throws BeansException
From source file:org.activiti.crystalball.simulator.OptimizeBottleneckTest.java
/** * run simulation for 30 days and generate report * /*from ww w. j ava 2s . com*/ * @param appContext * @throws Exception */ protected void runSimulation(AbstractApplicationContext appContext, String instancesGeneratedImage, String dueDateGeneratedImage) throws Exception { SimulationRun simRun = (SimulationRun) appContext.getBean(SimulationRun.class); Calendar c = Calendar.getInstance(); c.clear(); c.set(2013, 1, 1); Date startDate = c.getTime(); // add 30 days to start day c.add(Calendar.DAY_OF_YEAR, 30); Date finishDate = c.getTime(); // run simulation for 30 days @SuppressWarnings("unused") List<ResultEntity> resultEventList = simRun.execute(startDate, finishDate); RepositoryService simRepositoryService = (RepositoryService) appContext.getBean("simRepositoryService"); String processDefinitionId = simRepositoryService.createProcessDefinitionQuery() .processDefinitionKey(PROCESS_KEY).singleResult().getId(); // GENERATE REPORTS // instances report AbstractProcessEngineGraphGenerator generator = (AbstractProcessEngineGraphGenerator) appContext .getBean("reportGenerator"); generator.generateReport(processDefinitionId, startDate, finishDate, instancesGeneratedImage); // after due date report generator = (AbstractProcessEngineGraphGenerator) appContext.getBean("dueDateReportGenerator"); generator.generateReport(processDefinitionId, startDate, finishDate, dueDateGeneratedImage); }
From source file:com.googlecode.ehcache.annotations.config.EhCacheConfigBeanDefinitionParserTest.java
/** * 3 includes defined/*from w w w . ja v a 2 s.c o m*/ */ @Test public void testLoadContextTest1() { AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext( "/com/googlecode/ehcache/annotations/config/evictExpiredElementsTest1.xml"); try { ExpiredElementEvictor evictor = (ExpiredElementEvictor) applicationContext .getBean(EhCacheConfigBeanDefinitionParser.EHCACHE_CONFIG_EVICTION_TASK_BEAN_NAME); Assert.assertNotNull(evictor); // minutes from configuration gets converted into milliseconds Assert.assertEquals(10, evictor.getInterval()); Assert.assertEquals(3, evictor.getCacheNameMatchers().size()); } finally { applicationContext.destroy(); } }
From source file:com.googlecode.ehcache.annotations.config.EhCacheConfigBeanDefinitionParserTest.java
/** * 3 excludes defined (will result in IncludeAll matcher being appended to front) *///from w w w .j ava2s.c o m @Test public void testLoadContextTest2() { AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext( "/com/googlecode/ehcache/annotations/config/evictExpiredElementsTest2.xml"); try { ExpiredElementEvictor evictor = (ExpiredElementEvictor) applicationContext .getBean(EhCacheConfigBeanDefinitionParser.EHCACHE_CONFIG_EVICTION_TASK_BEAN_NAME); Assert.assertNotNull(evictor); // minutes from configuration gets converted into milliseconds Assert.assertEquals(20, evictor.getInterval()); Assert.assertEquals(4, evictor.getCacheNameMatchers().size()); } finally { applicationContext.destroy(); } }
From source file:com.googlecode.ehcache.annotations.config.EhCacheConfigBeanDefinitionParserTest.java
/** * 2 includes, 1 excludes defined/*from ww w. j ava 2 s . c om*/ */ @Test public void testLoadContextTest3() { AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext( "/com/googlecode/ehcache/annotations/config/evictExpiredElementsTest3.xml"); try { ExpiredElementEvictor evictor = (ExpiredElementEvictor) applicationContext .getBean(EhCacheConfigBeanDefinitionParser.EHCACHE_CONFIG_EVICTION_TASK_BEAN_NAME); Assert.assertNotNull(evictor); // minutes from configuration gets converted into milliseconds Assert.assertEquals(20, evictor.getInterval()); Assert.assertEquals(3, evictor.getCacheNameMatchers().size()); } finally { applicationContext.destroy(); } }
From source file:com.googlecode.ehcache.annotations.config.EhCacheConfigBeanDefinitionParserTest.java
/** * control, no includes/excludes defined *//*w w w . java 2 s .c o m*/ @Test public void testLoadControlContext() { AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext( "/com/googlecode/ehcache/annotations/config/evictExpiredElementsTestControl.xml"); try { ExpiredElementEvictor evictor = (ExpiredElementEvictor) applicationContext .getBean(EhCacheConfigBeanDefinitionParser.EHCACHE_CONFIG_EVICTION_TASK_BEAN_NAME); Assert.assertNotNull(evictor); // minutes from configuration gets converted into milliseconds Assert.assertEquals(20, evictor.getInterval()); Assert.assertEquals(1, evictor.getCacheNameMatchers().size()); } finally { applicationContext.destroy(); } }
From source file:org.trpr.platform.runtime.impl.container.spring.SpringContainerImpl.java
/** * Helper method that locates and loads all Bootstrap extensions *//*from w w w. j a v a 2 s . c o m*/ private void initializeBootstrapExtensions() { File[] bootstrapExtensionFiles = FileLocator.findFiles(RuntimeConstants.BOOTSTRAP_EXTENSIONS_FILE); // Create the Bootstrap Extension dependency manager that will load all bootstrap extensions BootstrapExtensionDependencyManager beManager = new BootstrapExtensionDependencyManager(this); for (File beFile : bootstrapExtensionFiles) { try { // add the "file:" prefix to file names to get around strange behavior of FileSystemXmlApplicationContext that converts absolute path // to relative path AbstractApplicationContext beDefinitionsContext = new FileSystemXmlApplicationContext( FILE_PREFIX + beFile.getAbsolutePath()); // All beans in the BE definitions context are expected to be of type BootstrapExtensionInfo. // We look up and load only these to BootstrapExtensionDependencyManager String[] beInfos = beDefinitionsContext.getBeanNamesForType(BootstrapExtensionInfo.class); for (String beInfo : beInfos) { beManager.addBootstrapExtensionInfo( (BootstrapExtensionInfo) beDefinitionsContext.getBean(beInfo)); } // destroy the beDefinitionsContext as we dont need it anymore beDefinitionsContext.destroy(); } catch (Exception e) { LOGGER.error("Error in loading BootStrap Extension File. Ignoring contents of : " + beFile.getAbsolutePath() + " .Error message : " + e.getMessage(), e); } } this.bootstrapExtensions = (BootstrapExtension[]) beManager.loadBootstrapExtensions() .toArray(new BootstrapExtension[0]); }
From source file:org.jahia.services.SpringContextSingleton.java
private void multicastEvent(ApplicationEvent event, AbstractApplicationContext ctx) { if (!ctx.isActive()) { return;// w ww . java 2 s .c o m } if (ctx.containsBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) { ((ApplicationEventMulticaster) ctx .getBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) .multicastEvent(event); } else { // fall back to publishEvent() ctx.publishEvent(event); } }
From source file:org.opennms.poller.remote.Main.java
private PollerFrontEnd getPollerFrontEnd(final AbstractApplicationContext context) { PollerFrontEnd frontEnd = (PollerFrontEnd) context.getBean("pollerFrontEnd"); frontEnd.addPropertyChangeListener(new ShouldExitPropertyChangeListener(context)); return frontEnd; }
From source file:org.opennms.poller.remote.Main.java
private static void shutdownContextAndExit(AbstractApplicationContext context) { int returnCode = 0; // MVR: gracefully shutdown scheduler, otherwise context.close() will raise // an exception. See #NMS-6966 for more details. if (context.isActive()) { // If there is a scheduler in the context, then shut it down Scheduler scheduler = (Scheduler) context.getBean("scheduler"); if (scheduler != null) { try { LOG.info("Shutting down PollerFrontEnd scheduler"); scheduler.shutdown();// w ww . ja v a2 s.c o m LOG.info("PollerFrontEnd scheduler shutdown complete"); } catch (SchedulerException ex) { LOG.warn("Shutting down PollerFrontEnd scheduler failed", ex); returnCode = 10; } } // Now close the application context. This will invoke // {@link DefaultPollerFrontEnd#destroy()} which will mark the // remote poller as "Stopped" during shutdown instead of letting // it remain in the "Disconnected" state. context.close(); } final int returnCodeValue = returnCode; new Thread() { public void run() { // Sleep for a couple of seconds so that the other // PropertyChangeListeners get a chance to fire try { Thread.sleep(5000); } catch (InterruptedException e) { } // Exit System.exit(returnCodeValue); } }.start(); }
From source file:org.springframework.integration.samples.advice.FileTransferDeleteAfterSuccessDemo.java
public static void main(String[] args) throws Exception { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome to Spring Integration! " + "\n " + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/expression-advice-context.xml"); context.registerShutdownHook();/* w w w. j a v a2s . co m*/ @SuppressWarnings("unchecked") SessionFactory<FTPFile> sessionFactory = context.getBean(SessionFactory.class); SourcePollingChannelAdapter fileInbound = context.getBean(SourcePollingChannelAdapter.class); @SuppressWarnings("unchecked") Session<FTPFile> session = mock(Session.class); when(sessionFactory.getSession()).thenReturn(session); fileInbound.start(); LOGGER.info("\n=========================================================" + "\n " + "\n This is the Expression Advice Sample - " + "\n " + "\n Press 'Enter' to terminate. " + "\n " + "\n Place a file in ${java.io.tmpdir}/adviceDemo ending " + "\n with .txt " + "\n The demo simulates a file transfer followed by the " + "\n Advice deleting the file; the result of the deletion " + "\n is logged. " + "\n " + "\n========================================================="); System.in.read(); System.exit(0); }