FormsIntegrationServiceImpl.java 3 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.Service
 *  org.apache.sling.commons.osgi.ServiceUtil
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.forms.service.impl;

import com.adobe.forms.service.FormsIntegrationService;
import com.adobe.forms.service.FormsIntegrationServiceProvider;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
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.Service;
import org.apache.sling.commons.osgi.ServiceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(label="Forms Integration Service", description="Provides Integration Scripts for Forms runtime", immediate=1)
@Service(value={FormsIntegrationService.class})
public class FormsIntegrationServiceImpl
implements FormsIntegrationService {
    private Logger logger = LoggerFactory.getLogger(FormsIntegrationServiceImpl.class);
    @Reference(name="FormsIntegrationServiceProvider", referenceInterface=FormsIntegrationServiceProvider.class, cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)
    private Map<Comparable<Object>, FormsIntegrationServiceProvider> providers = new ConcurrentSkipListMap(Collections.reverseOrder());

    private Collection<FormsIntegrationServiceProvider> getProviders() {
        return this.providers.values();
    }

    @Override
    public List<String> getScriptPaths() {
        HashSet<String> paths = new HashSet<String>();
        for (FormsIntegrationServiceProvider provider : this.getProviders()) {
            try {
                List<String> currentPaths = provider.getFormsIntegrationScriptPaths();
                if (currentPaths == null || currentPaths.isEmpty()) continue;
                paths.addAll(currentPaths);
            }
            catch (Exception e) {
                this.logger.error("The current provider could not give path", (Throwable)e);
            }
        }
        return new ArrayList<String>(paths);
    }

    protected void bindFormsIntegrationServiceProvider(FormsIntegrationServiceProvider provider, Map<String, Object> config) {
        this.providers.put(ServiceUtil.getComparableForServiceRanking(config), provider);
    }

    protected void unbindFormsIntegrationServiceProvider(FormsIntegrationServiceProvider provider, Map<String, Object> config) {
        this.providers.remove(ServiceUtil.getComparableForServiceRanking(config));
    }
}