CompilerProviderImpl.java 2.55 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.ReferenceCardinality
 *  org.apache.felix.scr.annotations.ReferencePolicy
 *  org.apache.felix.scr.annotations.References
 *  org.apache.felix.scr.annotations.Service
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.granite.ui.clientlibs.impl;

import com.adobe.granite.ui.clientlibs.impl.CompilerProvider;
import com.adobe.granite.ui.clientlibs.script.ScriptCompiler;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.References;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(immediate=1)
@References(value={@Reference(name="compiler", referenceInterface=ScriptCompiler.class, cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)})
@Service
public class CompilerProviderImpl
implements CompilerProvider {
    private static final Logger log = LoggerFactory.getLogger(CompilerProviderImpl.class);
    private ConcurrentHashMap<String, ScriptCompiler> compilers = new ConcurrentHashMap();

    protected void bindCompiler(ScriptCompiler compiler, Map<String, Object> props) {
        this.compilers.put(compiler.getName(), compiler);
        log.info("Registering client library compiler {}", (Object)compiler.getName());
    }

    protected void unbindCompiler(ScriptCompiler compiler, Map<String, Object> props) {
        this.compilers.remove(compiler.getName(), compiler);
        log.info("Unregistering client library compiler {}", (Object)compiler.getName());
    }

    @Override
    public ScriptCompiler getCompiler(String name) {
        return this.compilers.get(name);
    }

    @Override
    public ScriptCompiler findCompiler(String extension) {
        if ("js".equals(extension) || "css".equals(extension)) {
            log.debug("compiler for {} not supported", (Object)extension);
            return null;
        }
        for (ScriptCompiler c : this.compilers.values()) {
            if (!c.handles(extension)) continue;
            return c;
        }
        log.debug("no compiler found for {}", (Object)extension);
        return null;
    }
}