Search in sources :

Example 6 with ModuleDefinition

use of com.cloud.spring.module.model.ModuleDefinition in project cosmic by MissionCriticalCloud.

the class CloudStackSpringContext method getConfigLocationsForWeb.

public String[] getConfigLocationsForWeb(final String name, String[] configured) {
    if (configured == null) {
        configured = new String[] {};
    }
    ModuleDefinition def = getModuleDefinitionForWeb(name);
    final List<Resource> inherited = new ArrayList<>();
    while (def != null) {
        inherited.addAll(def.getInheritableContextLocations());
        def = moduleDefinitionSet.getModuleDefinition(def.getParentName());
    }
    final List<String> urlList = new ArrayList<>();
    for (final Resource r : inherited) {
        try {
            final String urlString = r.getURL().toExternalForm();
            urlList.add(urlString);
        } catch (final IOException e) {
            log.error("Failed to create URL for {}", r.getDescription(), e);
        }
    }
    String[] result = new String[urlList.size() + configured.length];
    result = urlList.toArray(result);
    System.arraycopy(configured, 0, result, urlList.size(), configured.length);
    return result;
}
Also used : ModuleDefinition(com.cloud.spring.module.model.ModuleDefinition) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 7 with ModuleDefinition

use of com.cloud.spring.module.model.ModuleDefinition in project cosmic by MissionCriticalCloud.

the class ModuleBasedContextFactory method loadModules.

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

Example 8 with ModuleDefinition

use of com.cloud.spring.module.model.ModuleDefinition in project cosmic by MissionCriticalCloud.

the class ModuleBasedContextFactory method wireUpModules.

protected Map<String, ModuleDefinition> wireUpModules(final String root, final Collection<ModuleDefinition> defs) throws IOException {
    final Map<String, ModuleDefinition> modules = new HashMap<>();
    for (final ModuleDefinition def : defs) {
        modules.put(def.getName(), def);
    }
    ModuleDefinition rootDef = null;
    final Map<String, ModuleDefinition> result = new HashMap<>();
    for (final ModuleDefinition def : modules.values()) {
        if (def.getName().equals(root)) {
            rootDef = def;
        }
        if (def.getParentName() != null) {
            final ModuleDefinition parentDef = modules.get(def.getParentName());
            if (parentDef != null) {
                parentDef.addChild(def);
            }
        }
    }
    return traverse(rootDef, result);
}
Also used : ModuleDefinition(com.cloud.spring.module.model.ModuleDefinition) HashMap(java.util.HashMap)

Example 9 with ModuleDefinition

use of com.cloud.spring.module.model.ModuleDefinition in project cosmic by MissionCriticalCloud.

the class ClasspathModuleDefinitionLocator method locateModules.

@Override
public Collection<ModuleDefinition> locateModules(final String context) throws IOException {
    final ResourcePatternResolver resolver = getResolver();
    final Map<String, ModuleDefinition> allModules = discoverModules(context, resolver);
    return allModules.values();
}
Also used : DefaultModuleDefinition(com.cloud.spring.module.model.impl.DefaultModuleDefinition) ModuleDefinition(com.cloud.spring.module.model.ModuleDefinition) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver)

Example 10 with ModuleDefinition

use of com.cloud.spring.module.model.ModuleDefinition in project cosmic by MissionCriticalCloud.

the class ClasspathModuleDefinitionLocator method discoverModules.

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

Aggregations

ModuleDefinition (com.cloud.spring.module.model.ModuleDefinition)10 Resource (org.springframework.core.io.Resource)3 DefaultModuleDefinition (com.cloud.spring.module.model.impl.DefaultModuleDefinition)2 HashMap (java.util.HashMap)2 ResourceApplicationContext (com.cloud.spring.module.context.ResourceApplicationContext)1 DefaultModuleDefinitionSet (com.cloud.spring.module.model.impl.DefaultModuleDefinitionSet)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 ApplicationContext (org.springframework.context.ApplicationContext)1 UrlResource (org.springframework.core.io.UrlResource)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)1