Example usage for org.springframework.context.support GenericApplicationContext GenericApplicationContext

List of usage examples for org.springframework.context.support GenericApplicationContext GenericApplicationContext

Introduction

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

Prototype

public GenericApplicationContext() 

Source Link

Document

Create a new GenericApplicationContext.

Usage

From source file:org.cloudfoundry.identity.uaa.config.HandlerAdapterFactoryBeanTests.java

@Test
public void testGetObject() throws Exception {
    factory.setApplicationContext(new GenericApplicationContext());
    assertNotNull(factory.getObject());/*from   w ww. ja v a  2  s .  co m*/
}

From source file:com.taobao.itest.spring.context.GenericXmlContextLoader.java

public ApplicationContext loadContext(String... locations) throws Exception {
    GenericApplicationContext context = new GenericApplicationContext();
    new XmlBeanDefinitionReader(context).loadBeanDefinitions(locations);
    context.refresh();/*from  w  w  w.j av a2  s . c om*/
    context.registerShutdownHook();
    return context;
}

From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java

public static GenericApplicationContext getSpringApplicationContextClassPath(ClassLoader classLoader,
        String relPath) throws AxisFault {
    GenericApplicationContext appContext = new GenericApplicationContext();
    appContext.setClassLoader(classLoader);
    ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
    try {//from  w  ww.  j av  a 2 s  . c o m
        Thread.currentThread().setContextClassLoader(classLoader);
        XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
        xbdr.setValidating(false);
        InputStream in = classLoader.getResourceAsStream(relPath);
        if (in == null) {
            throw new AxisFault("Spring context cannot be located for AxisService");
        }
        xbdr.loadBeanDefinitions(new InputStreamResource(in));
        appContext.refresh();
    } catch (Exception e) {
        throw AxisFault.makeFault(e);
    } finally {
        // Restore
        Thread.currentThread().setContextClassLoader(prevCl);
    }
    return appContext;
}

From source file:com.textocat.textokit.eval.EvaluationLauncher.java

public static void runUsingProperties(Properties configProperties) throws Exception {
    GenericApplicationContext appCtx = new GenericApplicationContext();

    appCtx.getEnvironment().getPropertySources()
            .addLast(new PropertiesPropertySource("configFile", configProperties));

    XmlBeanDefinitionReader xmlBDReader = new XmlBeanDefinitionReader(appCtx);
    xmlBDReader.loadBeanDefinitions(APP_CONTEXT_LOCATION);

    // register listeners
    Map<String, String> listenerImpls = getPrefixedKeyPairs(configProperties, PREFIX_LISTENER_ID);
    for (String listenerId : listenerImpls.keySet()) {
        String listenerClass = listenerImpls.get(listenerId);
        BeanDefinitionBuilder bb = genericBeanDefinition(listenerClass);
        Map<String, String> listenerProperties = getPrefixedKeyPairs(configProperties,
                PREFIX_LISTENER_PROPERTY + listenerId + ".");
        for (String propName : listenerProperties.keySet()) {
            bb.addPropertyValue(propName, listenerProperties.get(propName));
        }//from   ww w  .jav a2 s.co  m
        appCtx.registerBeanDefinition(listenerId, bb.getBeanDefinition());
    }

    appCtx.refresh();

    appCtx.registerShutdownHook();

    GoldStandardBasedEvaluation eval = appCtx.getBean(GoldStandardBasedEvaluation.class);
    eval.run();
}

From source file:nz.co.senanque.madura.bundle.BundleRootTest.java

@Test
@Ignore // fails because of parent bean which is undefined.
public void testGetApplicationContext() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource("/bundle-spring.xml"));
    ctx.refresh();//w  w w.j  a  va2 s.c o  m
    Object bundleName = ctx.getBean("bundleName");
    bundleName.toString();
}

From source file:org.springsource.investigation.ReproTests.java

@SuppressWarnings("unchecked")
@Test/* www  .  jav  a2 s . c o m*/
public void repro() {
    ConfigurableApplicationContext parent = new GenericApplicationContext();
    parent.refresh();

    AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
    child.setParent(parent);
    child.refresh();

    ConfigurableEnvironment env = child.getBean(ConfigurableEnvironment.class);
    assertThat("UNKNOWN ENV", env,
            anyOf(sameInstance(parent.getEnvironment()), sameInstance(child.getEnvironment())));
    assertThat("EXPECTED CHILD CTX ENV", env, sameInstance(child.getEnvironment()));
}

From source file:com.wavemaker.commons.util.SpringUtils.java

private static GenericApplicationContext initSpringConfig(boolean refresh) {
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource("config.xml"));

    if (refresh) {
        ctx.refresh();//  w ww .j  a v  a  2 s  .  co  m
    }

    return ctx;
}

From source file:com.graphaware.server.foundation.context.FoundationRootContextCreator.java

@Override
public AbstractApplicationContext createContext(NeoServer neoServer, StatsCollector statsCollector) {
    GenericApplicationContext parent = new GenericApplicationContext();
    parent.registerShutdownHook();/*from w w w. jav a  2  s . com*/
    parent.getBeanFactory().registerSingleton("database", neoServer.getDatabase().getGraph());
    parent.getBeanFactory().registerSingleton("procedures",
            neoServer.getDatabase().getGraph().getDependencyResolver().resolveDependency(Procedures.class));

    parent.getBeanFactory().registerSingleton("getStatsCollector", statsCollector);

    GraphAwareRuntime runtime = RuntimeRegistry.getRuntime(neoServer.getDatabase().getGraph());
    if (runtime != null) {
        runtime.waitUntilStarted();
        parent.getBeanFactory().registerSingleton("databaseWriter", runtime.getDatabaseWriter());
    }

    parent.refresh();

    return parent;
}

From source file:org.megam.deccanplato.provider.crm.test.MaluubaAdapterTest.java

@Test
public void maluubaTest() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource("applicationContext.xml"));
    ctx.refresh();//from  w w  w  . j av  a2  s .c om
    ProviderRegistry registry = (ProviderRegistry) ctx.getBean("registry");
    List<String> busiMethod = new ArrayList<String>();
    busiMethod.add("normalize");
    //busiMethod.add("interpret");
    List<String> busiActivity = new ArrayList<String>();
    busiActivity.add("norm");

    for (String function : busiMethod) {
        for (String activity : busiActivity) {
            CommonTest ctest = new CommonTest();
            RequestData reqData;
            reqData = ctest.commonTest(function, activity, MALUUBA);

            testAdapterAccess(reqData);

            ctest.testBusinessImpl();
        }
    }
}

From source file:org.megam.deccanplato.provider.crm.test.XeroAdapterTest.java

@Test
public void xeroTest() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource("applicationContext.xml"));
    ctx.refresh();/*from w ww  .j av a2s  .c o m*/
    ProviderRegistry registry = (ProviderRegistry) ctx.getBean("registry");

    List<String> oauth = new ArrayList<String>();
    //oauth.add("invoice");
    //oauth.add("account");
    //oauth.add("payment");
    //oauth.add("contact");
    //oauth.add("item");
    //oauth.add("user");
    //oauth.add("receipt");
    oauth.add("employee");
    List<String> oauthList = new ArrayList<String>();
    //oauthList.add("list");
    //oauthList.add("view");
    //oauthList.add("create");
    oauthList.add("update");
    for (String activity : oauth) {
        for (String function : oauthList) {

            CommonTest ctest = new CommonTest();
            RequestData reqData;
            reqData = ctest.commonTest(activity, function, XERO);
            if (function.equalsIgnoreCase("list") && activity.equalsIgnoreCase("invoice")) {
                testAdapterAccess(reqData);
            }
            ctest.testBusinessImpl();

        }
    }
}