Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2010, Red Hat Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.as.weld;
 
 
 import java.net.URL;
 import java.util.Map;
A org.jboss.weld.resources.spi.ResourceLoader that can load classes from a org.jboss.modules.Module

Thread Safety: This class is thread safe, and does not require a happens before even between construction and usage

Author(s):
Stuart Douglas
 
 public class WeldModuleResourceLoader implements ResourceLoader {
 
     private final Module module;

    
Additional classes that have been added to the bean archive by the container or by a portable extension
 
     private final Map<StringClass<?>> classes;
 
     public WeldModuleResourceLoader(Module module) {
         this. = module;
         this. = new ConcurrentHashMap<StringClass<?>>();
     }

    
If the class name is found in additionalClasses then return it. Otherwise the class will be loaded from the module ClassLoader
 
     @Override
     public Class<?> classForName(String name) {
         try {
             if (.containsKey(name)) {
                 return .get(name);
             }
             final Class<?> clazz = .getClassLoader().loadClass(name);
             .put(nameclazz);
             return clazz;
         } catch (NoClassDefFoundError e) {
             throw new ResourceLoadingException(e);
         } catch (ClassNotFoundException e) {
             throw new ResourceLoadingException(e);
         } catch (LinkageError e) {
             throw new ResourceLoadingException(e);
         }
     }
 
     public void addAdditionalClass(Class<?> clazz) {
         this..put(clazz.getName(), clazz);
     }

    
Loads a resource from the module class loader
 
     @Override
     public URL getResource(String name) {
         try {
             return .getClassLoader().getResource(name);
         } catch (Exception e) {
             throw new ResourceLoadingException(e);
         }
     }

    
Loads resources from the module class loader
 
     @Override
    public Collection<URLgetResources(String name) {
        try {
            final HashSet<URLresources = new HashSet<URL>();
            Enumeration<URLurls = .getClassLoader().getResources(name);
            while (urls.hasMoreElements()) {
                resources.add(urls.nextElement());
            }
            return resources;
        } catch (Exception e) {
            throw new ResourceLoadingException(e);
        }
    }
    @Override
    public void cleanup() {
        // nop
    }
New to GrepCode? Check out our FAQ X