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:com.serotonin.m2m2.module.ModuleRegistry.java

/**
 * Should not be used by client code.//from   w ww.  j  a  v  a2 s.  com
 */
public static void addModule(Module module) {
    MODULES.put(module.getName(), module);
}

From source file:cn.org.once.cstack.utils.MessageUtils.java

public static Message writeModuleMessage(User user, Module module, String type) {
    Message message = new Message();
    String body = "";
    switch (type) {
    case "CREATE":
        body = user.getFirstName() + " " + user.getLastName() + " has added a new Module : " + module.getName()
                + " for the application " + module.getApplication().getName();
        break;/*  ww w  . j  av  a  2 s  . c  o  m*/
    case "REMOVE":
        body = user.getFirstName() + " " + user.getLastName() + " has remove the Module : " + module.getName()
                + " from the application " + module.getApplication().getName();
        break;
    }

    message.setEvent(body);
    message.setType(Message.INFO);
    message.setApplicationName(module.getApplication().getName());
    message.setAuthor(user);

    return message;
}

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

/**
 * Get the diff map. Return a sorted map<version, sql statements>
 *
 * @return SortedMap<String, String>
 * @throws ModuleException//from  w ww . java2  s. co m
 */
public static SortedMap<String, String> getSqlDiffs(Module module) throws ModuleException {
    if (module == null) {
        throw new ModuleException("Module cannot be null");
    }

    SortedMap<String, String> map = new TreeMap<String, String>(new VersionComparator());

    InputStream diffStream = null;

    // get the diff stream
    JarFile jarfile = null;
    try {
        try {
            jarfile = new JarFile(module.getFile());
        } catch (IOException e) {
            throw new ModuleException("Unable to get jar file", module.getName(), e);
        }

        diffStream = ModuleUtil.getResourceFromApi(jarfile, module.getModuleId(), module.getVersion(),
                SQLDIFF_CHANGELOG_FILENAME);
        if (diffStream == null) {
            // Try the old way. Loading from the root of the omod
            ZipEntry diffEntry = jarfile.getEntry(SQLDIFF_CHANGELOG_FILENAME);
            if (diffEntry == null) {
                log.debug("No sqldiff.xml found for module: " + module.getName());
                return map;
            } else {
                try {
                    diffStream = jarfile.getInputStream(diffEntry);
                } catch (IOException e) {
                    throw new ModuleException("Unable to get sql diff file stream", module.getName(), e);
                }
            }
        }

        try {
            // turn the diff stream into an xml document
            Document diffDoc = null;
            try {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                db.setEntityResolver(new EntityResolver() {

                    @Override
                    public InputSource resolveEntity(String publicId, String systemId)
                            throws SAXException, IOException {
                        // When asked to resolve external entities (such as a DTD) we return an InputSource
                        // with no data at the end, causing the parser to ignore the DTD.
                        return new InputSource(new StringReader(""));
                    }
                });
                diffDoc = db.parse(diffStream);
            } catch (Exception e) {
                throw new ModuleException("Error parsing diff sqldiff.xml file", module.getName(), e);
            }

            Element rootNode = diffDoc.getDocumentElement();

            String diffVersion = rootNode.getAttribute("version");

            if (!validConfigVersions().contains(diffVersion)) {
                throw new ModuleException("Invalid config version: " + diffVersion, module.getModuleId());
            }

            NodeList diffNodes = getDiffNodes(rootNode, diffVersion);

            if (diffNodes != null && diffNodes.getLength() > 0) {
                int i = 0;
                while (i < diffNodes.getLength()) {
                    Element el = (Element) diffNodes.item(i++);
                    String version = getElement(el, diffVersion, "version");
                    String sql = getElement(el, diffVersion, "sql");
                    map.put(version, sql);
                }
            }
        } catch (ModuleException e) {
            if (diffStream != null) {
                try {
                    diffStream.close();
                } catch (IOException io) {
                    log.error("Error while closing config stream for module: " + module.getModuleId(), io);
                }
            }

            // rethrow the moduleException
            throw e;
        }

    } finally {
        try {
            if (jarfile != null) {
                jarfile.close();
            }
        } catch (IOException e) {
            log.warn("Unable to close jarfile: " + jarfile.getName());
        }
    }
    return map;
}

From source file:uniol.apt.module.AbstractModuleRegistry.java

/**
 * Register a module such that it's used in APT.
 *
 * @param module The module that should be registered
 *///www. j a  va 2s.  c  o m
protected void registerModule(Module module) {
    modulesEntries.put(module.getName(), module);
}

From source file:com.manydesigns.portofino.modules.ModuleRegistry.java

protected String printModule(Module module) {
    return "" + module.getName() + " (" + module.getId() + ")";
}

From source file:uniol.apt.module.AptModuleRegistry.java

private AptModuleRegistry() {
    super();/*w w w.  j  a  va  2  s . co m*/
    for (Module module : ServiceLoader.load(Module.class, getClass().getClassLoader())) {
        String moduleName = module.getClass().getCanonicalName();
        String name = module.getName();
        if (name == null || name.equals("") || !name.equals(name.toLowerCase())) {
            throw new RuntimeException(
                    String.format("Module %s reports an invalid name: %s", moduleName, name));
        }
        Module oldModule = findModule(name);
        if (oldModule != null && !oldModule.getClass().equals(module.getClass())) {
            throw new RuntimeException(String.format("Different modules claim, to have name %s:" + " %s and %s",
                    name, oldModule.getClass().getCanonicalName(), moduleName));
        }
        registerModule(module);
    }

}

From source file:org.obiba.onyx.engine.ModuleRegistrationListener.java

@SuppressWarnings("unchecked")
public void shutdown(WebApplication application) {
    Map<String, Module> modules = applicationContext.getBeansOfType(Module.class);
    if (modules != null) {
        for (Module module : modules.values()) {

            // Unregister the module from the registry.
            try {
                registry.unregisterModule(module.getName());
            } catch (RuntimeException e) {
                // Report the problem, but keep going in order to unregister the other modules if possible
                log.error("An error occurred during module unregistration.", e);
            }/*from w ww.j  a va 2  s.  com*/

            // Shutdown the module
            try {
                log.info("Shuting down module '{}'", module.getName());
                module.shutdown(application);
            } catch (RuntimeException e) {
                log.error("Could not shutdown module '{}'", module.getName());
                log.error("Module shutdown failed due to the following exception.", e);
            }
        }
    }
}

From source file:uk.co.grahamcox.yui.LanguageModuleBuilder.java

/**
 * Get the module file requested/*from   ww w  .  ja v  a  2s.c o m*/
 * @param group the group of the module
 * @param file the file of the module
 * @return the contents of the module
 * @throws java.io.IOException if an error occurs loading module content
 */
public String getModuleFile(String group, String file, String language) throws IOException {
    if (groups.containsKey(group)) {
        ModuleGroup moduleGroup = groups.get(group);
        Module module = moduleGroup.findModule(file);
        if (module != null) {
            StringBuilder moduleOutput = new StringBuilder();
            moduleOutput.append("YUI.add('lang/").append(module.getName());
            if (language != null && !language.isEmpty()) {
                moduleOutput.append("_").append(language);
            }
            moduleOutput.append("', function (Y) {\n");
            moduleOutput.append("Y.Intl.add(\n");
            moduleOutput.append("'").append(module.getName()).append("',\n");
            moduleOutput.append("'").append(language).append("',\n");
            moduleOutput.append("{\n");

            String resourceKey = module.getMessagesFile().toString();
            Locale locale;
            if (language == null || language.isEmpty()) {
                locale = Locale.getDefault();
            } else {
                locale = Locale.forLanguageTag(language);
            }

            ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceKey, locale,
                    new LanguageControl());
            Enumeration<String> keys = resourceBundle.getKeys();
            boolean isFirst = true;
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                String value = resourceBundle.getString(key);
                if (!isFirst) {
                    moduleOutput.append(",");
                }
                isFirst = false;
                moduleOutput.append("'").append(key).append("': '").append(value).append("'");
            }

            moduleOutput.append("});\n");
            moduleOutput.append("}, '").append(module.getVersion()).append("');");
            return moduleOutput.toString();
        } else {
            throw new UnknownModuleException(group, file);
        }
    } else {
        throw new UnknownGroupException(group);
    }

}

From source file:org.obiba.onyx.engine.Stage.java

public Stage(Module module, String name) {
    if (module == null)
        throw new IllegalArgumentException("module cannot be null");
    if (name == null)
        throw new IllegalArgumentException("name cannot be null");
    this.module = module.getName();
    this.name = name;
}

From source file:com.googlecode.arit.report.ReportGenerator.java

private List<Module> getSortedRootModules(Set<Module> modules, boolean leaksOnly) {
    List<Module> rootModules = new ArrayList<Module>();
    for (Module module : modules) {
        if (module != null && module.getParent() == null && (!leaksOnly || module.isStopped())) {
            rootModules.add(module);/*  w  ww. j a v a  2  s.c  o  m*/
        }
    }

    Comparator<Module> moduleComparator = new Comparator<Module>() {
        public int compare(Module o1, Module o2) {
            String name1 = o1.getName();
            String name2 = o2.getName();
            if (name1 == null && name2 == null) {
                return 0;
            } else if (name1 == null) {
                return -1;
            } else if (name2 == null) {
                return 1;
            } else {
                int c = name1.compareTo(name2);
                return c != 0 ? c : o1.getId().compareTo(o2.getId());
            }
        }
    };

    Comparator<ClassLoaderLink> classloaderLinkComparator = new Comparator<ClassLoaderLink>() {
        public int compare(ClassLoaderLink o1, ClassLoaderLink o2) {
            String name1 = o1.getDescription();
            String name2 = o2.getDescription();
            if (name1 == null && name2 == null) {
                return 0;
            } else if (name1 == null) {
                return -1;
            } else if (name2 == null) {
                return 1;
            } else {
                return name1.compareTo(name2);
            }
        }
    };

    // sort root modules on name
    Collections.sort(rootModules, moduleComparator);

    // sort child module and class loader relations on name
    for (Module module : modules) {
        Collections.sort(module.getChildren(), moduleComparator);

        // note: the resources' ordering remains between report generations, because the current program logic retrieves
        // them in a fixed order. Ordering resources can become necessary if this changes in the future.

        for (ResourcePresentation rp : module.getResources()) {
            Collections.sort(rp.getLinks(), classloaderLinkComparator);
        }
    }

    return rootModules;
}