Example usage for java.lang ClassLoader getResources

List of usage examples for java.lang ClassLoader getResources

Introduction

In this page you can find the example usage for java.lang ClassLoader getResources.

Prototype

public Enumeration<URL> getResources(String name) throws IOException 

Source Link

Document

Finds all the resources with the given name.

Usage

From source file:org.activiti.idm.engine.IdmEngines.java

/**
 * Initializes all idm engines that can be found on the classpath for resources <code>activiti.idm.cfg.xml</code> and for resources
 * <code>activiti-idm-context.xml</code> (Spring style
 * configuration).//from   w  w  w  .j  av a  2s.co m
 */
public synchronized static void init() {
    if (!isInitialized()) {
        if (idmEngines == null) {
            // Create new map to store idm engines if current map is null
            idmEngines = new HashMap<String, IdmEngine>();
        }
        ClassLoader classLoader = IdmEngines.class.getClassLoader();
        Enumeration<URL> resources = null;
        try {
            resources = classLoader.getResources("activiti.idm.cfg.xml");
        } catch (IOException e) {
            throw new ActivitiException("problem retrieving activiti.idm.cfg.xml resources on the classpath: "
                    + System.getProperty("java.class.path"), e);
        }

        // Remove duplicated configuration URL's using set. Some
        // classloaders may return identical URL's twice, causing duplicate startups
        Set<URL> configUrls = new HashSet<URL>();
        while (resources.hasMoreElements()) {
            configUrls.add(resources.nextElement());
        }
        for (Iterator<URL> iterator = configUrls.iterator(); iterator.hasNext();) {
            URL resource = iterator.next();
            log.info("Initializing idm engine using configuration '{}'", resource.toString());
            initIdmEngineFromResource(resource);
        }

        try {
            resources = classLoader.getResources("activiti-idm-context.xml");
        } catch (IOException e) {
            throw new ActivitiException(
                    "problem retrieving activiti-idm-context.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }

        while (resources.hasMoreElements()) {
            URL resource = resources.nextElement();
            log.info("Initializing idm engine using Spring configuration '{}'", resource.toString());
            initIdmEngineFromSpringResource(resource);
        }

        setInitialized(true);
    } else {
        log.info("Idm engines already initialized");
    }
}

From source file:org.flowable.form.engine.FormEngines.java

/**
 * Initializes all form engines that can be found on the classpath for resources <code>flowable.form.cfg.xml</code> and for resources <code>flowable-dmn-context.xml</code> (Spring style
 * configuration).//from  w  ww.  j a v a2s .  c  o  m
 */
public synchronized static void init() {
    if (!isInitialized()) {
        if (formEngines == null) {
            // Create new map to store dmn engines if current map is null
            formEngines = new HashMap<String, FormEngine>();
        }
        ClassLoader classLoader = FormEngines.class.getClassLoader();
        Enumeration<URL> resources = null;
        try {
            resources = classLoader.getResources("flowable.form.cfg.xml");
        } catch (IOException e) {
            throw new FlowableException("problem retrieving flowable.form.cfg.xml resources on the classpath: "
                    + System.getProperty("java.class.path"), e);
        }

        // Remove duplicated configuration URL's using set. Some
        // classloaders may return identical URL's twice, causing duplicate startups
        Set<URL> configUrls = new HashSet<URL>();
        while (resources.hasMoreElements()) {
            configUrls.add(resources.nextElement());
        }
        for (Iterator<URL> iterator = configUrls.iterator(); iterator.hasNext();) {
            URL resource = iterator.next();
            log.info("Initializing form engine using configuration '{}'", resource.toString());
            initFormEngineFromResource(resource);
        }

        try {
            resources = classLoader.getResources("flowable-form-context.xml");
        } catch (IOException e) {
            throw new FlowableException(
                    "problem retrieving flowable-form-context.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }

        while (resources.hasMoreElements()) {
            URL resource = resources.nextElement();
            log.info("Initializing form engine using Spring configuration '{}'", resource.toString());
            initFormEngineFromSpringResource(resource);
        }

        setInitialized(true);
    } else {
        log.info("Form engines already initialized");
    }
}

From source file:architecture.common.model.factory.ModelTypeFactory.java

private static List<ModelList> parseLegacyXmlFile(List<ModelList> list) throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Enumeration<URL> enumeration = cl.getResources(IF_PLUGIN_PATH);
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);/*from  ww  w  .  ja  v a 2s.c o m*/
    XMLReader xmlreader = factory.newSAXParser().getXMLReader();
    ImplFactoryParsingHandler handler = new ImplFactoryParsingHandler();
    xmlreader.setContentHandler(handler);
    xmlreader.setDTDHandler(handler);
    xmlreader.setEntityResolver(handler);
    xmlreader.setErrorHandler(handler);
    System.out.println("Model Enum:");
    do {
        if (!enumeration.hasMoreElements())
            break;
        URL url = (URL) enumeration.nextElement();
        System.out.println(" - " + url);
        try {
            xmlreader.parse(new InputSource(url.openStream()));
            ModelList factorylist = new ModelList();
            factorylist.rank = handler.rank;
            factorylist.modelTypes.addAll(handler.getModels());
            list.add(factorylist);
        } catch (Exception exception) {
        }
    } while (true);

    return list;
}

From source file:org.activiti.dmn.engine.DmnEngines.java

/**
 * Initializes all dmn engines that can be found on the classpath for
 * resources <code>activiti.dmn.cfg.xml</code> and for resources
 * <code>activiti-dmn-context.xml</code> (Spring style configuration).
 *///from   w ww.  j a v a2 s .  c o m
public synchronized static void init() {
    if (!isInitialized()) {
        if (dmnEngines == null) {
            // Create new map to store dmn engines if current map is null
            dmnEngines = new HashMap<String, DmnEngine>();
        }
        ClassLoader classLoader = DmnEngines.class.getClassLoader();
        Enumeration<URL> resources = null;
        try {
            resources = classLoader.getResources("activiti.dmn.cfg.xml");
        } catch (IOException e) {
            throw new ActivitiException("problem retrieving activiti.dmn.cfg.xml resources on the classpath: "
                    + System.getProperty("java.class.path"), e);
        }

        // Remove duplicated configuration URL's using set. Some
        // classloaders may return identical URL's twice, causing duplicate startups
        Set<URL> configUrls = new HashSet<URL>();
        while (resources.hasMoreElements()) {
            configUrls.add(resources.nextElement());
        }
        for (Iterator<URL> iterator = configUrls.iterator(); iterator.hasNext();) {
            URL resource = iterator.next();
            log.info("Initializing dmn engine using configuration '{}'", resource.toString());
            initDmnEngineFromResource(resource);
        }

        try {
            resources = classLoader.getResources("activiti-dmn-context.xml");
        } catch (IOException e) {
            throw new ActivitiException(
                    "problem retrieving activiti-dmn-context.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }

        while (resources.hasMoreElements()) {
            URL resource = resources.nextElement();
            log.info("Initializing dmn engine using Spring configuration '{}'", resource.toString());
            initDmnEngineFromSpringResource(resource);
        }

        setInitialized(true);
    } else {
        log.info("DMN engines already initialized");
    }
}

From source file:org.flowable.dmn.engine.DmnEngines.java

/**
 * Initializes all dmn engines that can be found on the classpath for
 * resources <code>flowable.dmn.cfg.xml</code> and for resources
 * <code>flowable-dmn-context.xml</code> (Spring style configuration).
 *///from  w w w  .ja v a 2  s.c o  m
public synchronized static void init() {
    if (!isInitialized()) {
        if (dmnEngines == null) {
            // Create new map to store dmn engines if current map is null
            dmnEngines = new HashMap<String, DmnEngine>();
        }
        ClassLoader classLoader = DmnEngines.class.getClassLoader();
        Enumeration<URL> resources = null;
        try {
            resources = classLoader.getResources("flowable.dmn.cfg.xml");
        } catch (IOException e) {
            throw new FlowableException("problem retrieving flowable.dmn.cfg.xml resources on the classpath: "
                    + System.getProperty("java.class.path"), e);
        }

        // Remove duplicated configuration URL's using set. Some
        // classloaders may return identical URL's twice, causing duplicate startups
        Set<URL> configUrls = new HashSet<URL>();
        while (resources.hasMoreElements()) {
            configUrls.add(resources.nextElement());
        }
        for (Iterator<URL> iterator = configUrls.iterator(); iterator.hasNext();) {
            URL resource = iterator.next();
            log.info("Initializing dmn engine using configuration '{}'", resource.toString());
            initDmnEngineFromResource(resource);
        }

        try {
            resources = classLoader.getResources("flowable-dmn-context.xml");
        } catch (IOException e) {
            throw new FlowableException(
                    "problem retrieving flowable-dmn-context.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }

        while (resources.hasMoreElements()) {
            URL resource = resources.nextElement();
            log.info("Initializing dmn engine using Spring configuration '{}'", resource.toString());
            initDmnEngineFromSpringResource(resource);
        }

        setInitialized(true);
    } else {
        log.info("DMN engines already initialized");
    }
}

From source file:org.activiti.engine.ProcessEngines.java

/**
 * Initializes all process engines that can be found on the classpath for resources <code>flowable.cfg.xml</code> (plain Activiti style configuration) and for resources
 * <code>activiti-context.xml</code> (Spring style configuration).
 *///  ww  w .j  a  v a2  s .c o  m
public static synchronized void init() {
    if (!isInitialized()) {
        if (processEngines == null) {
            // Create new map to store process-engines if current map is null
            processEngines = new HashMap<>();
        }
        ClassLoader classLoader = ReflectUtil.getClassLoader();
        Enumeration<URL> resources = null;
        try {
            resources = classLoader.getResources("flowable.cfg.xml");
        } catch (IOException e) {
            throw new ActivitiIllegalArgumentException(
                    "problem retrieving flowable.cfg.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }

        // Remove duplicated configuration URL's using set. Some classloaders may return identical URL's twice, causing duplicate startups
        Set<URL> configUrls = new HashSet<>();
        while (resources.hasMoreElements()) {
            configUrls.add(resources.nextElement());
        }
        for (Iterator<URL> iterator = configUrls.iterator(); iterator.hasNext();) {
            URL resource = iterator.next();
            LOGGER.info("Initializing process engine using configuration '{}'", resource.toString());
            initProcessEngineFromResource(resource);
        }

        try {
            resources = classLoader.getResources("activiti-context.xml");
        } catch (IOException e) {
            throw new ActivitiIllegalArgumentException(
                    "problem retrieving activiti-context.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }
        while (resources.hasMoreElements()) {
            URL resource = resources.nextElement();
            LOGGER.info("Initializing process engine using Spring configuration '{}'", resource.toString());
            initProcessEngineFromSpringResource(resource);
        }

        setInitialized(true);
    } else {
        LOGGER.info("Process engines already initialized");
    }
}

From source file:org.activiti.content.engine.ContentEngines.java

/**
 * Initializes all dmn engines that can be found on the classpath for resources <code>activiti.dmn.cfg.xml</code> and for resources <code>activiti-dmn-context.xml</code> (Spring style
 * configuration).//from   w  w  w .  j  a v  a2s .  co m
 */
public synchronized static void init() {
    if (!isInitialized()) {
        if (contentEngines == null) {
            // Create new map to store content engines if current map is null
            contentEngines = new HashMap<String, ContentEngine>();
        }
        ClassLoader classLoader = ContentEngines.class.getClassLoader();
        Enumeration<URL> resources = null;
        try {
            resources = classLoader.getResources("activiti.content.cfg.xml");
        } catch (IOException e) {
            throw new ActivitiException(
                    "problem retrieving activiti.content.cfg.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }

        // Remove duplicated configuration URL's using set. Some
        // classloaders may return identical URL's twice, causing duplicate startups
        Set<URL> configUrls = new HashSet<URL>();
        while (resources.hasMoreElements()) {
            configUrls.add(resources.nextElement());
        }
        for (Iterator<URL> iterator = configUrls.iterator(); iterator.hasNext();) {
            URL resource = iterator.next();
            log.info("Initializing content engine using configuration '{}'", resource.toString());
            initContentEngineFromResource(resource);
        }

        try {
            resources = classLoader.getResources("activiti-content-context.xml");
        } catch (IOException e) {
            throw new ActivitiException(
                    "problem retrieving activiti-content-context.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }

        while (resources.hasMoreElements()) {
            URL resource = resources.nextElement();
            log.info("Initializing content engine using Spring configuration '{}'", resource.toString());
            initContentEngineFromSpringResource(resource);
        }

        setInitialized(true);
    } else {
        log.info("Content engines already initialized");
    }
}

From source file:org.flowable.content.engine.ContentEngines.java

/**
 * Initializes all dmn engines that can be found on the classpath for resources <code>flowable.content.cfg.xml</code> and for resources <code>flowable-dmn-context.xml</code> (Spring style
 * configuration)./*w  w  w.  java 2  s .  c  om*/
 */
public synchronized static void init() {
    if (!isInitialized()) {
        if (contentEngines == null) {
            // Create new map to store content engines if current map is null
            contentEngines = new HashMap<String, ContentEngine>();
        }
        ClassLoader classLoader = ContentEngines.class.getClassLoader();
        Enumeration<URL> resources = null;
        try {
            resources = classLoader.getResources("flowable.content.cfg.xml");
        } catch (IOException e) {
            throw new FlowableException(
                    "problem retrieving flowable.content.cfg.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }

        // Remove duplicated configuration URL's using set. Some
        // classloaders may return identical URL's twice, causing duplicate startups
        Set<URL> configUrls = new HashSet<URL>();
        while (resources.hasMoreElements()) {
            configUrls.add(resources.nextElement());
        }
        for (Iterator<URL> iterator = configUrls.iterator(); iterator.hasNext();) {
            URL resource = iterator.next();
            log.info("Initializing content engine using configuration '{}'", resource.toString());
            initContentEngineFromResource(resource);
        }

        try {
            resources = classLoader.getResources("flowable-content-context.xml");
        } catch (IOException e) {
            throw new FlowableException(
                    "problem retrieving flowable-content-context.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }

        while (resources.hasMoreElements()) {
            URL resource = resources.nextElement();
            log.info("Initializing content engine using Spring configuration '{}'", resource.toString());
            initContentEngineFromSpringResource(resource);
        }

        setInitialized(true);
    } else {
        log.info("Content engines already initialized");
    }
}

From source file:org.flowable.engine.ProcessEngines.java

/**
 * Initializes all process engines that can be found on the classpath for resources <code>flowable.cfg.xml</code> (plain Flowable style configuration) and for resources
 * <code>flowable-context.xml</code> (Spring style configuration).
 *//*from www .  j a  va 2s .  com*/
public static synchronized void init() {
    if (!isInitialized()) {
        if (processEngines == null) {
            // Create new map to store process-engines if current map is null
            processEngines = new HashMap<>();
        }
        ClassLoader classLoader = ReflectUtil.getClassLoader();
        Enumeration<URL> resources = null;
        try {
            resources = classLoader.getResources("flowable.cfg.xml");
        } catch (IOException e) {
            throw new FlowableIllegalArgumentException(
                    "problem retrieving flowable.cfg.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }

        // Remove duplicated configuration URL's using set. Some
        // classloaders may return identical URL's twice, causing duplicate
        // startups
        Set<URL> configUrls = new HashSet<>();
        while (resources.hasMoreElements()) {
            configUrls.add(resources.nextElement());
        }
        for (Iterator<URL> iterator = configUrls.iterator(); iterator.hasNext();) {
            URL resource = iterator.next();
            LOGGER.info("Initializing process engine using configuration '{}'", resource.toString());
            initProcessEngineFromResource(resource);
        }

        try {
            resources = classLoader.getResources("flowable-context.xml");
        } catch (IOException e) {
            throw new FlowableIllegalArgumentException(
                    "problem retrieving flowable-context.xml resources on the classpath: "
                            + System.getProperty("java.class.path"),
                    e);
        }
        while (resources.hasMoreElements()) {
            URL resource = resources.nextElement();
            LOGGER.info("Initializing process engine using Spring configuration '{}'", resource.toString());
            initProcessEngineFromSpringResource(resource);
        }

        setInitialized(true);
    } else {
        LOGGER.info("Process engines already initialized");
    }
}

From source file:com.yunrang.hadoop.app.utils.CustomizedUtil.java

/**
 * Find a jar that contains a class of the same name, if any. It will return
 * a jar file, even if that is not the first thing on the class path that
 * has a class with the same name. Looks first on the classpath and then in
 * the <code>packagedClasses</code> map.
 * //from   w  w  w .  ja v a  2  s .c om
 * @param my_class the class to find.
 * @return a jar file that contains the class, or null.
 * @throws IOException
 */
public static String findContainingJar(Class<?> my_class, Map<String, String> packagedClasses)
        throws IOException {
    ClassLoader loader = my_class.getClassLoader();
    String class_file = my_class.getName().replaceAll("\\.", "/") + ".class";
    // first search the classpath
    for (Enumeration<URL> itr = loader.getResources(class_file); itr.hasMoreElements();) {
        URL url = itr.nextElement();
        if ("jar".equals(url.getProtocol())) {
            String toReturn = url.getPath();
            if (toReturn.startsWith("file:")) {
                toReturn = toReturn.substring("file:".length());
            }
            // URLDecoder is a misnamed class, since it actually decodes
            // x-www-form-urlencoded MIME type rather than actual
            // URL encoding (which the file path has). Therefore it would
            // decode +s to ' 's which is incorrect (spaces are actually
            // either unencoded or encoded as "%20"). Replace +s first, so
            // that they are kept sacred during the decoding process.
            toReturn = toReturn.replaceAll("\\+", "%2B");
            toReturn = URLDecoder.decode(toReturn, "UTF-8");
            return toReturn.replaceAll("!.*$", "");
        }
    }
    // now look in any jars we've packaged using JarFinder. Returns null
    // when
    // no jar is found.
    return packagedClasses.get(class_file);
}