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

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

Introduction

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

Prototype

public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh,
        @Nullable ApplicationContext parent) throws BeansException 

Source Link

Document

Create a new FileSystemXmlApplicationContext with the given parent, loading the definitions from the given XML files.

Usage

From source file:org.red5.server.plugin.admin.AdminPlugin.java

@Override
public void doStart() throws Exception {
    super.doStart();

    //create a handler
    handler = new AdminHandler();

    //create app context
    adminContext = new FileSystemXmlApplicationContext(new String[] { "classpath:/admin-security.xml" }, true,
            context);/*w  w  w .  j av a  2  s.  com*/

    //set the context
    handler.setContext(adminContext);

    //get a ref to the "default" global scope
    GlobalScope global = (GlobalScope) server.getGlobal("default");

    //create a scope resolver
    ScopeResolver scopeResolver = new ScopeResolver();
    scopeResolver.setGlobalScope(global);

    AuthClientRegistry registry = (AuthClientRegistry) adminContext.getBean("authClientRegistry");

    //create a context - this takes the place of the previous web context
    Context ctx = new Context(adminContext, "admin");
    ctx.setClientRegistry(registry);
    ctx.setMappingStrategy(new MappingStrategy());
    ctx.setPersistanceStore(global.getStore());
    ctx.setScopeResolver(scopeResolver);
    ctx.setServiceInvoker(new ServiceInvoker());

    //create a scope for the admin
    //      Scope scope = new Scope.Builder((IScope) global, "scope", "admin", false).build();
    //      
    //      scope.setContext(ctx);
    //      scope.setHandler(handler);
    //      
    //      //set the scope on the handler
    //      handler.setScope(scope);

    server.addMapping(hostName, "admin", "default");

    //      if (global.addChildScope(scope)) {
    //         log.info("Admin scope was added to global (default) scope");
    //         
    //      } else {
    //         log.warn("Admin scope was not added to global (default) scope");
    //      }
}

From source file:org.red5.server.plugin.oflaDemo.OflaDemoPlugin.java

@Override
public void doStart() throws Exception {
    super.doStart();

    //create a handler
    handler = new OflaDemoHandler();

    ApplicationContext commonCtx = (ApplicationContext) context.getBean("red5.common");

    if (context.containsBean("playlistSubscriberStream")) {
        //create app context
        oflaDemoContext = new FileSystemXmlApplicationContext(new String[] { "classpath:/oflaDemo.xml" }, true,
                context);/* w  ww. j a  va2  s  .c o  m*/
    } else if (commonCtx.containsBean("playlistSubscriberStream")) {
        //create app context
        oflaDemoContext = new FileSystemXmlApplicationContext(new String[] { "classpath:/oflaDemo.xml" }, true,
                commonCtx);
    } else {
        log.error("Playlist subscriber stream bean could not be located");
    }

    //set the context
    handler.setContext(oflaDemoContext);

    //get a ref to the "default" global scope
    GlobalScope global = (GlobalScope) server.getGlobal("default");

    //create a scope resolver
    ScopeResolver scopeResolver = new ScopeResolver();
    scopeResolver.setGlobalScope(global);

    //create a context - this takes the place of the previous web context
    Context ctx = new Context(oflaDemoContext, "oflaDemo");
    ctx.setClientRegistry(new ClientRegistry());
    ctx.setMappingStrategy(new MappingStrategy());
    ctx.setPersistanceStore(global.getStore());
    ctx.setScopeResolver(scopeResolver);
    ctx.setServiceInvoker(new ServiceInvoker());

    //create a scope for the admin
    Scope scope = new Scope.Builder((IScope) global, ScopeType.APPLICATION, "oflaDemo", false).build();
    scope.setContext(ctx);
    scope.setHandler(handler);

    //set the scope on the handler
    handler.setScope(scope);

    server.addMapping(hostName, "oflaDemo", "default");

    if (global.addChildScope(scope)) {
        log.info("oflaDemo scope was added to global (default) scope");

    } else {
        log.warn("oflaDemo scope was not added to global (default) scope");
    }
}

From source file:org.red5.server.plugin.definst.DefinstPlugin.java

@Override
public void doStart() throws Exception {
    super.doStart();

    // add the context to the parent, this will be red5.xml
    ConfigurableBeanFactory factory = ((ConfigurableApplicationContext) context).getBeanFactory();
    // if parent context was not set then lookup red5.common
    log.debug("Lookup common - bean:{} local:{} singleton:{}",
            new Object[] { factory.containsBean("red5.common"), factory.containsLocalBean("red5.common"),
                    factory.containsSingleton("red5.common"), });
    parentContext = (ApplicationContext) factory.getBean("red5.common");

    //create app context
    appContext = new FileSystemXmlApplicationContext(new String[] { "classpath:/definst.xml" }, true,
            parentContext);/*from  ww w . jav a 2 s  . co  m*/

    //get a ref to the "default" global scope
    GlobalScope global = (GlobalScope) server.getGlobal("default");

    //create a scope resolver
    ScopeResolver scopeResolver = new ScopeResolver();
    scopeResolver.setGlobalScope(global);

    //create a context - this takes the place of the previous web context
    Context ctx = new Context(appContext, appName);
    ctx.setClientRegistry(new ClientRegistry());
    ctx.setMappingStrategy(new MappingStrategy());
    ctx.setPersistanceStore(global.getStore());
    ctx.setScopeResolver(scopeResolver);
    ctx.setServiceInvoker(new ServiceInvoker());

    //create a handler
    handler = new DefinstHandler();

    //create a scope for the admin
    //      Scope scope = new Scope.Builder((IScope) global, "scope", appName, false).build();
    //      scope.setContext(ctx);
    //      scope.setHandler(handler);

    server.addMapping(hostName, appName, "default");

    //      if (global.addChildScope(scope)) {
    //         log.info("Scope was added to global (default) scope");
    //      } else {
    //         log.warn("Scope was not added to global (default) scope");
    //      }
    //      
    //      //start the scope
    //      scope.start();

}

From source file:org.exoplatform.container.spring.FileSystemXmlApplicationContextProvider.java

/**
 * {@inheritDoc}/*  www . j  a v  a2 s.c o  m*/
 */
public ApplicationContext getApplicationContext(ApplicationContext parent) {
    try {
        String[] paths = new String[params.getValues().size()];
        int i = 0;
        for (String value : params.getValues()) {
            URL url = cm.getResource(value);
            paths[i++] = url.toURI().toString();
        }
        return new FileSystemXmlApplicationContext(paths, true, parent);
    } catch (Exception e) {
        throw new RuntimeException("Could not create the ApplicationContext", e);
    }
}

From source file:net.frontlinesms.FrontlineSMS.java

/** Initialise {@link #applicationContext}. */
public void initApplicationContext() throws DataAccessResourceFailureException {
    // Load the data mode from the app.properties file
    AppProperties appProperties = AppProperties.getInstance();

    LOG.info("Load Spring/Hibernate application context to initialise DAOs");

    // Create a base ApplicationContext defining the hibernate config file we need to import
    StaticApplicationContext baseApplicationContext = new StaticApplicationContext();
    baseApplicationContext.registerBeanDefinition("hibernateConfigLocations",
            createHibernateConfigLocationsBeanDefinition());

    // Get the spring config locations
    String databaseExternalConfigPath = ResourceUtils.getConfigDirectoryPath()
            + ResourceUtils.PROPERTIES_DIRECTORY_NAME + File.separatorChar
            + appProperties.getDatabaseConfigPath();
    String[] configLocations = getSpringConfigLocations(databaseExternalConfigPath);
    baseApplicationContext.refresh();/*from  w w  w. j  a  v a2  s.  c  o  m*/

    FileSystemXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext(configLocations,
            false, baseApplicationContext);
    this.applicationContext = applicationContext;

    // Add post-processor to handle substituted database properties
    PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
    String databasePropertiesPath = ResourceUtils.getConfigDirectoryPath()
            + ResourceUtils.PROPERTIES_DIRECTORY_NAME + File.separatorChar
            + appProperties.getDatabaseConfigPath() + ".properties";
    propertyPlaceholderConfigurer.setLocation(new FileSystemResource(new File(databasePropertiesPath)));
    propertyPlaceholderConfigurer.setIgnoreResourceNotFound(true);
    applicationContext.addBeanFactoryPostProcessor(propertyPlaceholderConfigurer);
    applicationContext.refresh();

    LOG.info("Context loaded successfully.");

    this.pluginManager = new PluginManager(this, applicationContext);

    LOG.info("Getting DAOs from application context...");
    groupDao = (GroupDao) applicationContext.getBean("groupDao");
    groupMembershipDao = (GroupMembershipDao) applicationContext.getBean("groupMembershipDao");
    contactDao = (ContactDao) applicationContext.getBean("contactDao");
    keywordDao = (KeywordDao) applicationContext.getBean("keywordDao");
    keywordActionDao = (KeywordActionDao) applicationContext.getBean("keywordActionDao");
    messageDao = (MessageDao) applicationContext.getBean("messageDao");
    emailDao = (EmailDao) applicationContext.getBean("emailDao");
    emailAccountDao = (EmailAccountDao) applicationContext.getBean("emailAccountDao");
    smsInternetServiceSettingsDao = (SmsInternetServiceSettingsDao) applicationContext
            .getBean("smsInternetServiceSettingsDao");
    smsModemSettingsDao = (SmsModemSettingsDao) applicationContext.getBean("smsModemSettingsDao");
    eventBus = (EventBus) applicationContext.getBean("eventBus");
}