Search in sources :

Example 1 with ResourceApplicationContext

use of org.apache.cloudstack.spring.module.context.ResourceApplicationContext in project cloudstack by apache.

the class DefaultModuleDefinitionSet method loadContext.

protected ApplicationContext loadContext(ModuleDefinition def, ApplicationContext parent) {
    ResourceApplicationContext context = new ResourceApplicationContext();
    context.setApplicationName("/" + def.getName());
    Resource[] resources = getConfigResources(def.getName());
    context.setConfigResources(resources);
    context.setParent(parent);
    context.setClassLoader(def.getClassLoader());
    long start = System.currentTimeMillis();
    if (log.isInfoEnabled()) {
        for (Resource resource : resources) {
            log.info("Loading module context [{}] from {}", def.getName(), resource);
        }
    }
    context.refresh();
    log.info("Loaded module context [{}] in {} ms", def.getName(), (System.currentTimeMillis() - start));
    contexts.put(def.getName(), context);
    return context;
}
Also used : UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) ResourceApplicationContext(org.apache.cloudstack.spring.module.context.ResourceApplicationContext)

Example 2 with ResourceApplicationContext

use of org.apache.cloudstack.spring.module.context.ResourceApplicationContext in project cloudstack by apache.

the class DefaultModuleDefinitionSet method getDefaultsContext.

protected ApplicationContext getDefaultsContext() {
    URL config = DefaultModuleDefinitionSet.class.getResource(DEFAULT_CONFIG_XML);
    ResourceApplicationContext context = new ResourceApplicationContext(new UrlResource(config));
    context.setApplicationName("/defaults");
    context.refresh();
    @SuppressWarnings("unchecked") final List<Resource> resources = (List<Resource>) context.getBean(DEFAULT_CONFIG_RESOURCES);
    withModule(new WithModule() {

        @Override
        public void with(ModuleDefinition def, Stack<ModuleDefinition> parents) {
            for (Resource defaults : def.getConfigLocations()) {
                resources.add(defaults);
            }
        }
    });
    configProperties = (Properties) context.getBean(DEFAULT_CONFIG_PROPERTIES);
    for (Resource resource : resources) {
        load(resource, configProperties);
    }
    for (Resource resource : (Resource[]) context.getBean(MODULE_PROPERITES)) {
        load(resource, configProperties);
    }
    parseExcludes();
    return context;
}
Also used : ModuleDefinition(org.apache.cloudstack.spring.module.model.ModuleDefinition) UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) ResourceApplicationContext(org.apache.cloudstack.spring.module.context.ResourceApplicationContext) ArrayList(java.util.ArrayList) List(java.util.List) URL(java.net.URL)

Aggregations

ResourceApplicationContext (org.apache.cloudstack.spring.module.context.ResourceApplicationContext)2 Resource (org.springframework.core.io.Resource)2 UrlResource (org.springframework.core.io.UrlResource)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ModuleDefinition (org.apache.cloudstack.spring.module.model.ModuleDefinition)1