Example usage for java.lang Module getName

List of usage examples for java.lang Module getName

Introduction

In this page you can find the example usage for java.lang Module getName.

Prototype

public String getName() 

Source Link

Document

Returns the module name or null if this module is an unnamed module.

Usage

From source file:org.cruxframework.crux.core.rebind.module.Modules.java

/**
 * @param module//  ww w . ja v  a2s  . com
 * @return
 */
public String[] searchModulePages(Module module) {
    String[] pages = null;
    try {
        Set<String> allScreenIDs = ScreenResourceResolverInitializer.getScreenResourceResolver()
                .getAllScreenIDs(module.getName());
        if (allScreenIDs != null) {
            URL location = module.getLocation();
            pages = new String[allScreenIDs.size()];
            int i = 0;
            for (String screenID : allScreenIDs) {
                screenID = getRelativeScreenId(module, screenID, location);
                pages[i++] = screenID;
            }
        } else {
            pages = new String[0];
        }
    } catch (ScreenConfigException e) {
        throw new ModuleException("Error searching for module pages. Module Name [" + module.getName() + "]",
                e);
    }
    return pages;
}

From source file:uk.codingbadgers.SurvivalPlus.SurvivalPlus.java

/**
 * Reloads a specific module//from   w  w  w . j av a  2s. c  om
 *
 * @param module the module to reload
 */
public void reloadModule(Module module) {
    Validate.notNull(module, "Moudule cannot be null");

    m_moduleLoader.unload(module);
    m_moduleLoader.load(module.getFile());
    m_moduleLoader.getModule(module.getName()).onEnable();
}

From source file:com.espertech.esper.core.deploy.EPDeploymentAdminImpl.java

private DeploymentActionException buildException(String msg, Module module,
        List<DeploymentItemException> exceptions) {
    String message = msg;//from w w w  .ja va 2  s .  c  o  m
    if (module.getName() != null) {
        message += " in module '" + module.getName() + "'";
    }
    if (module.getUri() != null) {
        message += " in module url '" + module.getUri() + "'";
    }
    if (exceptions.size() > 0) {
        message += " in expression '" + getAbbreviated(exceptions.get(0).getExpression()) + "' : "
                + exceptions.get(0).getMessage();
    }
    return new DeploymentActionException(message, exceptions);
}

From source file:architecture.common.license.License.java

public String toXML() {
    DocumentFactory factory = DocumentFactory.getInstance();
    Document document = factory.createDocument();
    Element root = document.addElement("license");

    root.addAttribute("id", String.valueOf(getLicenseId()));
    root.addAttribute("name", getName());
    if (edition != null)
        root.addAttribute("edition", getEdition());
    root.addAttribute("creationDate", formatDate(getCreationDate()));
    root.addAttribute("version", getVersion().getVersionString());
    root.addAttribute("type", getType().name());
    if (getClient() != null) {
        Element client = root.addElement("client");
        if (getClient().getName() != null)
            client.addAttribute("name", getClient().getName());
        if (getClient().getCompany() != null)
            client.addAttribute("company", getClient().getCompany());
    }/*from ww w . ja  v  a 2 s  .co  m*/

    for (Module m : getModules()) {
        Element me = root.addElement("module");
        me.addAttribute("name", m.getName());
    }

    for (java.util.Map.Entry<String, String> entry : getProperties().entrySet()) {
        Element prop = root.addElement("property");
        prop.addAttribute("name", (String) entry.getKey());
        prop.setText((String) entry.getValue());
    }
    return document.asXML();
}

From source file:org.openmrs.module.ModuleFactory.java

/**
 * Add a module to the list of openmrs modules
 * /*from   w ww. j  a  v a2  s .  c o m*/
 * @param module
 * @param replaceIfExists unload a module that has the same moduleId if one is loaded already
 * @return module the module that was loaded or if the module exists already with the same
 *         version, the old module
 */
public static Module loadModule(Module module, Boolean replaceIfExists) throws ModuleException {

    if (log.isDebugEnabled()) {
        log.debug("Adding module " + module.getName() + " to the module queue");
    }

    Module oldModule = getLoadedModulesMap().get(module.getModuleId());
    if (oldModule != null) {
        int versionComparison = ModuleUtil.compareVersion(oldModule.getVersion(), module.getVersion());
        if (versionComparison < 0) {
            // if oldModule version is lower, unload it and use the new
            unloadModule(oldModule);
        } else if (versionComparison == 0) {
            if (replaceIfExists) {
                // if the versions are the same and we're told to replaceIfExists, use the new
                unloadModule(oldModule);
            } else {
                // if the versions are equal and we're not told to replaceIfExists, jump out of here in a bad way
                throw new ModuleException("A module with the same id and version already exists",
                        module.getModuleId());
            }
        } else {
            // if the older (already loaded) module is newer, keep that original one that was loaded. return that one.
            return oldModule;
        }
    }

    getLoadedModulesMap().put(module.getModuleId(), module);

    return module;
}

From source file:com.espertech.esper.core.deploy.EPDeploymentAdminImpl.java

public synchronized DeploymentOrder getDeploymentOrder(Collection<Module> modules,
        DeploymentOrderOptions options) throws DeploymentOrderException {
    if (options == null) {
        options = new DeploymentOrderOptions();
    }/*from  www .  ja  va2s. com*/
    String[] deployments = deploymentStateService.getDeployments();

    List<Module> proposedModules = new ArrayList<Module>();
    proposedModules.addAll(modules);

    Set<String> availableModuleNames = new HashSet<String>();
    for (Module proposedModule : proposedModules) {
        if (proposedModule.getName() != null) {
            availableModuleNames.add(proposedModule.getName());
        }
    }

    // Collect all uses-dependencies of existing modules
    Map<String, Set<String>> usesPerModuleName = new HashMap<String, Set<String>>();
    for (String deployment : deployments) {
        DeploymentInformation info = deploymentStateService.getDeployment(deployment);
        if (info == null) {
            continue;
        }
        if ((info.getModule().getName() == null) || (info.getModule().getUses() == null)) {
            continue;
        }
        Set<String> usesSet = usesPerModuleName.get(info.getModule().getName());
        if (usesSet == null) {
            usesSet = new HashSet<String>();
            usesPerModuleName.put(info.getModule().getName(), usesSet);
        }
        usesSet.addAll(info.getModule().getUses());
    }

    // Collect uses-dependencies of proposed modules
    for (Module proposedModule : proposedModules) {

        // check uses-dependency is available
        if (options.isCheckUses()) {
            if (proposedModule.getUses() != null) {
                for (String uses : proposedModule.getUses()) {
                    if (availableModuleNames.contains(uses)) {
                        continue;
                    }
                    if (isDeployed(uses)) {
                        continue;
                    }
                    String message = "Module-dependency not found";
                    if (proposedModule.getName() != null) {
                        message += " as declared by module '" + proposedModule.getName() + "'";
                    }
                    message += " for uses-declaration '" + uses + "'";
                    throw new DeploymentOrderException(message);
                }
            }
        }

        if ((proposedModule.getName() == null) || (proposedModule.getUses() == null)) {
            continue;
        }
        Set<String> usesSet = usesPerModuleName.get(proposedModule.getName());
        if (usesSet == null) {
            usesSet = new HashSet<String>();
            usesPerModuleName.put(proposedModule.getName(), usesSet);
        }
        usesSet.addAll(proposedModule.getUses());
    }

    Map<String, SortedSet<Integer>> proposedModuleNames = new HashMap<String, SortedSet<Integer>>();
    int count = 0;
    for (Module proposedModule : proposedModules) {
        SortedSet<Integer> moduleNumbers = proposedModuleNames.get(proposedModule.getName());
        if (moduleNumbers == null) {
            moduleNumbers = new TreeSet<Integer>();
            proposedModuleNames.put(proposedModule.getName(), moduleNumbers);
        }
        moduleNumbers.add(count);
        count++;
    }

    DependencyGraph graph = new DependencyGraph(proposedModules.size(), false);
    int fromModule = 0;
    for (Module proposedModule : proposedModules) {
        if ((proposedModule.getUses() == null) || (proposedModule.getUses().isEmpty())) {
            fromModule++;
            continue;
        }
        SortedSet<Integer> dependentModuleNumbers = new TreeSet<Integer>();
        for (String use : proposedModule.getUses()) {
            SortedSet<Integer> moduleNumbers = proposedModuleNames.get(use);
            if (moduleNumbers == null) {
                continue;
            }
            dependentModuleNumbers.addAll(moduleNumbers);
        }
        dependentModuleNumbers.remove(fromModule);
        graph.addDependency(fromModule, dependentModuleNumbers);
        fromModule++;
    }

    if (options.isCheckCircularDependency()) {
        Stack<Integer> circular = graph.getFirstCircularDependency();
        if (circular != null) {
            String message = "";
            String delimiter = "";
            for (int i : circular) {
                message += delimiter;
                message += "module '" + proposedModules.get(i).getName() + "'";
                delimiter = " uses (depends on) ";
            }
            throw new DeploymentOrderException(
                    "Circular dependency detected in module uses-relationships: " + message);
        }
    }

    List<Module> reverseDeployList = new ArrayList<Module>();
    Set<Integer> ignoreList = new HashSet<Integer>();
    while (ignoreList.size() < proposedModules.size()) {

        // seconardy sort according to the order of listing
        Set<Integer> rootNodes = new TreeSet<Integer>(new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                return -1 * o1.compareTo(o2);
            }
        });
        rootNodes.addAll(graph.getRootNodes(ignoreList));

        if (rootNodes.isEmpty()) { // circular dependency could cause this
            for (int i = 0; i < proposedModules.size(); i++) {
                if (!ignoreList.contains(i)) {
                    rootNodes.add(i);
                    break;
                }
            }
        }

        for (Integer root : rootNodes) {
            ignoreList.add(root);
            reverseDeployList.add(proposedModules.get(root));
        }
    }

    Collections.reverse(reverseDeployList);
    return new DeploymentOrder(reverseDeployList);
}

From source file:com.headwire.aem.tooling.intellij.config.ServerConfiguration.java

public Module obtainModuleByName(String moduleName) {
    Module ret = null;//  w  w  w .  j a va  2s.com
    if (moduleName != null) {
        for (Module module : moduleList) {
            //AS TODO: Need to figure out who is calling this mehod to know if this is related to OSGi
            if (moduleName.equals(module.getName())) {
                ret = module;
                break;
            }
        }
    }
    return ret;
}

From source file:org.pentaho.reporting.libraries.base.boot.PackageManager.java

/**
 * Checks, whether the given module meets the requirements defined in the module information.
 *
 * @param moduleRequirement the required module specification.
 * @param module            the module that should be checked against the specification.
 * @return true, if the module meets the given specifications, false otherwise.
 *///ww  w .j a va 2s.c  o  m
private boolean acceptVersion(final ModuleInfo moduleRequirement, final Module module) {
    if (moduleRequirement.getMajorVersion() == null) {
        return true;
    }
    if (module.getMajorVersion() == null) {
        LOGGER.warn("Module " + module.getName() + " does not define a major version.");
    } else {
        final int compare = acceptVersion(moduleRequirement.getMajorVersion(), module.getMajorVersion());
        if (compare > 0) {
            return false;
        } else if (compare < 0) {
            return true;
        }
    }

    if (moduleRequirement.getMinorVersion() == null) {
        return true;
    }
    if (module.getMinorVersion() == null) {
        LOGGER.warn("Module " + module.getName() + " does not define a minor version.");
    } else {
        final int compare = acceptVersion(moduleRequirement.getMinorVersion(), module.getMinorVersion());
        if (compare > 0) {
            return false;
        } else if (compare < 0) {
            return true;
        }
    }

    if (moduleRequirement.getPatchLevel() == null) {
        return true;
    }
    if (module.getPatchLevel() == null) {
        LOGGER.debug("Module " + module.getName() + " does not define a patch level.");
    } else {
        if (acceptVersion(moduleRequirement.getPatchLevel(), module.getPatchLevel()) > 0) {
            LOGGER.debug("Did not accept patchlevel: " + moduleRequirement.getPatchLevel() + " - "
                    + module.getPatchLevel());
            return false;
        }
    }
    return true;

}

From source file:org.opendaylight.controller.sal.binding.yang.types.TypeProviderImpl.java

private void resolveTypeDefsFromContext() {
    final Set<Module> modules = schemaContext.getModules();
    if (modules == null) {
        throw new IllegalArgumentException("Sef of Modules cannot be NULL!");
    }/*from  w  w w.  jav  a 2s. c  o  m*/
    for (final Module module : modules) {
        if (module == null) {
            continue;
        }
        final String moduleName = module.getName();
        final String basePackageName = moduleNamespaceToPackageName(module);

        final Set<TypeDefinition<?>> typeDefinitions = module.getTypeDefinitions();
        final List<TypeDefinition<?>> listTypeDefinitions = sortTypeDefinitionAccordingDepth(typeDefinitions);

        final Map<String, Type> typeMap = new HashMap<>();
        genTypeDefsContextMap.put(moduleName, typeMap);

        if ((listTypeDefinitions != null) && (basePackageName != null)) {
            for (final TypeDefinition<?> typedef : listTypeDefinitions) {
                typedefToGeneratedType(basePackageName, moduleName, typedef);
            }
        }
    }
}

From source file:org.metamorphosis.core.ModuleManager.java

private void monitorRoot(final File root) {
    FileMonitor monitor = new FileMonitor(root);
    monitor.addListener(new FileListener() {

        @Override/*from ww w . j  a va 2s .c o m*/
        public void onCreated(String file) {
            File folder = new File(root + "/" + file);
            if (folder.isDirectory()) {
                logger.log(Level.INFO, "adding module  : " + folder.getName());
                final Module module = new Module();
                module.setFolder(folder);
                initModule(module);
                addModule(module);
                monitorModule(module);
            }
        }

        @Override
        public void onDeleted(String file) {
            Module module = getModuleById(file);
            if (module != null) {
                logger.log(Level.INFO, "removing module  : " + module.getName());
                removeModule(module);
            }
        }

    });
    monitor.watch();
}