Search in sources :

Example 6 with ModuleDefinition

use of org.apache.cloudstack.spring.module.model.ModuleDefinition in project cloudstack by apache.

the class DefaultModuleDefinitionSet method loadRootContext.

protected boolean loadRootContext() {
    ModuleDefinition def = modules.get(root);
    if (def == null)
        return false;
    ApplicationContext defaultsContext = getDefaultsContext();
    rootContext = loadContext(def, defaultsContext);
    return true;
}
Also used : ModuleDefinition(org.apache.cloudstack.spring.module.model.ModuleDefinition) ResourceApplicationContext(org.apache.cloudstack.spring.module.context.ResourceApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext)

Example 7 with ModuleDefinition

use of org.apache.cloudstack.spring.module.model.ModuleDefinition in project cloudstack by apache.

the class DefaultModuleDefinitionSet method withModule.

protected void withModule(ModuleDefinition def, Stack<ModuleDefinition> parents, WithModule with) {
    if (def == null)
        return;
    if (!shouldLoad(def)) {
        log.info("Excluding context [{}] based on configuration", def.getName());
        return;
    }
    with.with(def, parents);
    parents.push(def);
    for (ModuleDefinition child : def.getChildren()) {
        withModule(child, parents, with);
    }
    parents.pop();
}
Also used : ModuleDefinition(org.apache.cloudstack.spring.module.model.ModuleDefinition)

Example 8 with ModuleDefinition

use of org.apache.cloudstack.spring.module.model.ModuleDefinition 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)

Example 9 with ModuleDefinition

use of org.apache.cloudstack.spring.module.model.ModuleDefinition in project cloudstack by apache.

the class ModuleBasedContextFactory method loadModules.

public ModuleDefinitionSet loadModules(Collection<ModuleDefinition> defs, String root) throws IOException {
    Map<String, ModuleDefinition> modules = wireUpModules(root, defs);
    DefaultModuleDefinitionSet moduleSet = new DefaultModuleDefinitionSet(modules, root);
    moduleSet.load();
    return moduleSet;
}
Also used : ModuleDefinition(org.apache.cloudstack.spring.module.model.ModuleDefinition) DefaultModuleDefinitionSet(org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet)

Example 10 with ModuleDefinition

use of org.apache.cloudstack.spring.module.model.ModuleDefinition in project cloudstack by apache.

the class ClasspathModuleDefinitionLocator method discoverModules.

protected Map<String, ModuleDefinition> discoverModules(String baseDir, ResourcePatternResolver resolver) throws IOException {
    Map<String, ModuleDefinition> result = new HashMap<String, ModuleDefinition>();
    for (Resource r : resolver.getResources(ModuleLocationUtils.getModulesLocation(baseDir))) {
        DefaultModuleDefinition def = new DefaultModuleDefinition(baseDir, r, resolver);
        def.init();
        if (def.isValid())
            result.put(def.getName(), def);
    }
    return result;
}
Also used : DefaultModuleDefinition(org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinition) ModuleDefinition(org.apache.cloudstack.spring.module.model.ModuleDefinition) DefaultModuleDefinition(org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinition) HashMap(java.util.HashMap) Resource(org.springframework.core.io.Resource)

Aggregations

ModuleDefinition (org.apache.cloudstack.spring.module.model.ModuleDefinition)11 Resource (org.springframework.core.io.Resource)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ResourceApplicationContext (org.apache.cloudstack.spring.module.context.ResourceApplicationContext)2 DefaultModuleDefinition (org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinition)2 UrlResource (org.springframework.core.io.UrlResource)2 IOException (java.io.IOException)1 URL (java.net.URL)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 DefaultModuleDefinitionSet (org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinitionSet)1 ApplicationContext (org.springframework.context.ApplicationContext)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)1