Search in sources :

Example 1 with ModuleDefinition

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

the class CloudStackSpringContext method getConfigLocationsForWeb.

public String[] getConfigLocationsForWeb(String name, String[] configured) {
    if (configured == null)
        configured = new String[] {};
    ModuleDefinition def = getModuleDefinitionForWeb(name);
    List<Resource> inherited = new ArrayList<Resource>();
    while (def != null) {
        inherited.addAll(def.getInheritableContextLocations());
        def = moduleDefinitionSet.getModuleDefinition(def.getParentName());
    }
    List<String> urlList = new ArrayList<String>();
    for (Resource r : inherited) {
        try {
            String urlString = r.getURL().toExternalForm();
            urlList.add(urlString);
        } catch (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(org.apache.cloudstack.spring.module.model.ModuleDefinition) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 2 with ModuleDefinition

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

the class CloudStackSpringContext method getModuleDefinitionForWeb.

public ModuleDefinition getModuleDefinitionForWeb(String name) {
    ModuleDefinition def = moduleDefinitionSet.getModuleDefinition(name);
    if (def != null) {
        return def;
    }
    /* Grab farthest descendant that is deterministic */
    def = moduleDefinitionSet.getModuleDefinition(baseName);
    if (def == null) {
        throw new RuntimeException("Failed to find base spring module to extend for web");
    }
    while (def.getChildren().size() == 1) {
        def = def.getChildren().iterator().next();
    }
    return def;
}
Also used : ModuleDefinition(org.apache.cloudstack.spring.module.model.ModuleDefinition)

Example 3 with ModuleDefinition

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

the class DefaultModuleDefinitionSet method getConfigResources.

@Override
public Resource[] getConfigResources(String name) {
    Set<Resource> resources = new LinkedHashSet<Resource>();
    ModuleDefinition original = null;
    ModuleDefinition def = original = modules.get(name);
    if (def == null)
        return new Resource[] {};
    resources.addAll(def.getContextLocations());
    while (def != null) {
        resources.addAll(def.getInheritableContextLocations());
        def = modules.get(def.getParentName());
    }
    resources.addAll(original.getOverrideContextLocations());
    return resources.toArray(new Resource[resources.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModuleDefinition(org.apache.cloudstack.spring.module.model.ModuleDefinition) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource)

Example 4 with ModuleDefinition

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

the class DefaultModuleDefinitionSet method withModule.

protected void withModule(WithModule with) {
    ModuleDefinition rootDef = modules.get(root);
    withModule(rootDef, new Stack<ModuleDefinition>(), with);
}
Also used : ModuleDefinition(org.apache.cloudstack.spring.module.model.ModuleDefinition)

Example 5 with ModuleDefinition

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

the class ModuleBasedContextFactory method wireUpModules.

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

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