Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 
 package org.richfaces.javascript;
 
 import java.net.URL;
import  javax.faces.FacesException;
import  org.richfaces.log.Logger;
import  org.richfaces.log.RichfacesLogger;
import  org.richfaces.resource.ResourceKey;
import  com.google.common.base.Function;
import  com.google.common.collect.ImmutableMap;
import  com.google.common.collect.ImmutableMap.Builder;
import  com.google.common.collect.Iterables;
import  com.google.common.collect.Maps;

Author(s):
asmirnov
public final class ClientServiceConfigParser {
    private static final Logger LOG = RichfacesLogger.CONFIG.getLogger();
    private ClientServiceConfigParser() {
    }
    public static Map<Class<?>, LibraryFunction> parseConfig(String name) {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (null == loader) {
            loader = ClientServiceConfigParser.class.getClassLoader();
        }
        Builder<Class<?>, LibraryFunction> resultBuilder = ImmutableMap.builder();
        try {
            Enumeration<URLresources = loader.getResources(name);
            while (resources.hasMoreElements()) {
                URL url = (URLresources.nextElement();
                resultBuilder.putAll(parse(loaderurl));
            }
        } catch (IOException e) {
            return Collections.emptyMap();
        }
        return resultBuilder.build();
    }
    static Map<Class<?>, LibraryFunction> parse(ClassLoader loaderURL url) {
        Map<Class<?>, LibraryFunction> result = Maps.newHashMap();
        try {
            ClientSideScripts clientSideScripts = JAXB.unmarshal(urlClientSideScripts.class);
            for (Component component : clientSideScripts.getComponent()) {
                try {
                    Class<?> componentClass = loader.loadClass(component.getType());
                    Iterable<ResourceKey> resources = Iterables.transform(component.getResource(),
                        new Function<Resource, ResourceKey>() {
                            public ResourceKey apply(Resource from) {
                                return ResourceKey.create(from.getName(), from.getLibrary());
                            }
                        });
                    LibraryFunctionImplementation function = new LibraryFunctionImplementation(component.getFunction(),
                        resources);
                    result.put(componentClassfunction);
                } catch (ClassNotFoundException e) {
                    // throw new FacesException("Class for component not found", e);
                    .warn("Found JavaScript function definition for class " + component.getType()
                        + ", but that class is not presented");
                }
            }
        } catch (Exception e) {
            throw new FacesException("Error parsing config file " + urle);
        }
        return result;
    }
New to GrepCode? Check out our FAQ X