Example usage for org.springframework.context.support AbstractApplicationContext getBean

List of usage examples for org.springframework.context.support AbstractApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context.support AbstractApplicationContext getBean.

Prototype

@Override
    public <T> T getBean(Class<T> requiredType) throws BeansException 

Source Link

Usage

From source file:de.uzk.hki.da.at.AcceptanceTest.java

private static void instantiateRepository(Properties properties) {

    String repImplBeanName = properties.getProperty("cb.implementation.repository");
    if (repImplBeanName == null)
        repImplBeanName = "fakeRepositoryFacade";

    AbstractApplicationContext context = new FileSystemXmlApplicationContext("conf/beans.xml");
    repositoryFacade = (RepositoryFacade) context.getBean(repImplBeanName);
    context.close();/*from  w w w  .  j ava 2 s  .c  o m*/
}

From source file:org.ehcache.myapp.Main.java

public static void testHarness(AbstractApplicationContext context) throws Exception {

    context.registerShutdownHook();//from  w  w w  .j av a 2 s . c o  m
    CacheManager mgr = CacheManager.getCacheManager("TestCache");
    Iterator<String> airportCodes = org.ehcache.myapp.util.Airport.getAirportCodes(mgr).iterator();

    final CacheCaller service = (CacheCaller) context.getBean("cacheAsideGateway");
    final CacheCaller getService = (CacheCaller) context.getBean("getGateway");
    final CacheCaller putService = (CacheCaller) context.getBean("putGateway");

    while (airportCodes.hasNext()) {

        final String input = airportCodes.next();

        try {
            Element element = new Element(input, null);
            System.out.println("Calling Gateway: " + service.putData(element));
            System.out.println(
                    "Test Cache Get ******" + ((Element) getService.getData(element)).getObjectValue());
        } catch (Exception e) {
            LOGGER.error("An exception was caught: " + e);
        }

    }
    checkUpdates();
}

From source file:de.uzk.hki.da.grid.CTIrodsFacade.java

/**
 * Sets up /*w  ww.  java2s . c o  m*/
 * <li>node
 * <li>irodsGridConnector
 * <li>gridFacade
 * @param properties
 */
private static void setUpGridInfrastructure(Properties properties) {

    AbstractApplicationContext context = new ClassPathXmlApplicationContext(BEANS_DIAGNOSTICS_IRODS);
    isc = (IrodsSystemConnector) context.getBean(BEAN_NAME_IRODS_SYSTEM_CONNECTOR);
    ig = (IrodsGridFacade) context.getBean(properties.getProperty(BEAN_NAME_IRODS_GRID_FACADE));

    ig.setIrodsSystemConnector(isc);

    sp = new StoragePolicy();
    sp.setWorkingResource("ciWorkingResource");
    sp.setGridCacheAreaRootPath(Path.make(properties.getProperty(PROP_GRID_CACHE_AREA_ROOT_PATH)).toString());
    sp.setWorkAreaRootPath(Path.make(properties.getProperty(PROP_WORK_AREA_ROOT_PATH)).toString());
    sp.setReplDestinations("ciArchiveResourceGroup");

    context.close();
}

From source file:com.artivisi.biller.simulator.service.impl.PpobSimulatorServiceImplTest.java

@BeforeClass
public static void init() {
    AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
            "classpath*:com/artivisi/**/applicationContext.xml");
    ctx.registerShutdownHook();//from  w w  w  . j  a  va 2 s. c o m

    billerService = ctx.getBean(BillerSimulatorService.class);
    plnService = ctx.getBean(PlnSimulatorService.class);
    dataSource = ctx.getBean(DataSource.class);
}

From source file:org.jodconverter.cli.Convert.java

private static OfficeManager createOfficeManager(final CommandLine commandLine,
        final AbstractApplicationContext context) {

    // If the URL is present, we will use the online office manager and thus,
    // an office installation won't be required locally.
    if (commandLine.hasOption(OPT_CONNECTION_URL.getOpt())) {
        final String connectionUrl = getStringOption(commandLine, OPT_CONNECTION_URL.getOpt());
        return OnlineOfficeManager.builder().urlConnection(connectionUrl)
                .sslConfig(context == null ? null : context.getBean(SslConfig.class)).build();
    }/*from  w ww  .ja  v a  2  s .co  m*/

    // Not online conversion...

    final LocalOfficeManager.Builder builder = LocalOfficeManager.builder();

    if (commandLine.hasOption(OPT_OFFICE_HOME.getOpt())) {
        builder.officeHome(commandLine.getOptionValue(OPT_OFFICE_HOME.getOpt()));
    }

    builder.killExistingProcess(commandLine.hasOption(OPT_KILL_EXISTING_PROCESS.getOpt()));

    builder.disableOpengl(commandLine.hasOption(OPT_DISABLE_OPENGL.getOpt()));

    if (commandLine.hasOption(OPT_PROCESS_MANAGER.getOpt())) {
        builder.processManager(commandLine.getOptionValue(OPT_PROCESS_MANAGER.getOpt()));
    }

    if (commandLine.hasOption(OPT_PORT.getOpt())) {
        builder.portNumbers(Integer.parseInt(commandLine.getOptionValue(OPT_PORT.getOpt())));
    }

    if (commandLine.hasOption(OPT_TIMEOUT.getOpt())) {
        builder.taskExecutionTimeout(Long.parseLong(commandLine.getOptionValue(OPT_TIMEOUT.getOpt())) * 1000L);
    }

    if (commandLine.hasOption(OPT_USER_PROFILE.getOpt())) {
        builder.templateProfileDir(new File(commandLine.getOptionValue(OPT_USER_PROFILE.getOpt())));
    }

    return builder.install().build();
}

From source file:com.liferay.arkadiko.test.util.BaseTest.java

public BundleContext getBundleContext(AbstractApplicationContext context) {
    return (BundleContext) context.getBean("bundleContext");
}

From source file:io.gravitee.gateway.handlers.api.ApiContextHandlerFactoryTest.java

@Test
public void shouldCreateContext() {
    apiContextHandlerFactory = spy(apiContextHandlerFactory);

    AbstractApplicationContext ctx = mock(AbstractApplicationContext.class);
    when(api.isEnabled()).thenReturn(true);
    when(ctx.getBean(ApiReactorHandler.class)).thenReturn(mock(ApiReactorHandler.class));
    doReturn(ctx).when(apiContextHandlerFactory).createApplicationContext(api);

    ReactorHandler handler = apiContextHandlerFactory.create(api);

    assertNotNull(handler);//  w  w w .  ja  v a  2 s  .co m
    assertTrue(ApiReactorHandler.class.isAssignableFrom(handler.getClass()));
}

From source file:io.gravitee.gateway.handlers.api.ApiContextHandlerFactory.java

@Override
public ReactorHandler create(Api api) {
    if (api.isEnabled()) {
        AbstractApplicationContext internalApplicationContext = createApplicationContext(api);
        ApiReactorHandler handler = internalApplicationContext.getBean(ApiReactorHandler.class);
        handler.setClassLoader(internalApplicationContext.getClassLoader());
        return handler;
    } else {//from ww w.  ja v  a 2s.co  m
        logger.warn("Api is disabled !");
        return null;
    }
}

From source file:org.activiti.crystalball.simulator.SimulateBottleneckTest.java

/**
 * run simulation for 30 days and generate report
 * /*  w w  w . j a  va2 s  .c om*/
 * @param appContext
 * @throws Exception 
 */
protected void runSimulation(AbstractApplicationContext appContext, String generatedImage) throws Exception {

    SimulationRun simRun = (SimulationRun) appContext.getBean(SimulationRun.class);

    Calendar c = Calendar.getInstance();
    c.clear();
    c.set(2013, 1, 1);
    Date startDate = c.getTime();
    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);

    AbstractProcessEngineGraphGenerator generator = (AbstractProcessEngineGraphGenerator) appContext
            .getBean("reportGenerator");

    RepositoryService simRepositoryService = (RepositoryService) appContext.getBean("simRepositoryService");

    String processDefinitionId = simRepositoryService.createProcessDefinitionQuery()
            .processDefinitionKey(PROCESS_KEY).singleResult().getId();

    generator.generateReport(processDefinitionId, startDate, finishDate, generatedImage);

}