InputProcessorFactory.java 3.92 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Deactivate
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 */
package com.adobe.aemfd.watchfolder.factory;

import com.adobe.aemfd.docmanager.Document;
import com.adobe.aemfd.watchfolder.config.WatchFolderConfiguration;
import com.adobe.aemfd.watchfolder.job.FileResultHandlerWrapper;
import com.adobe.aemfd.watchfolder.script.ScriptInputProcessor;
import com.adobe.aemfd.watchfolder.service.ServiceInputProcessor;
import com.adobe.aemfd.watchfolder.spi.InputProcessor;
import com.adobe.aemfd.watchfolder.workflow.WorkflowLauncherHandler;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
@Component(immediate=1)
@Service(value={InputProcessorFactory.class})
public class InputProcessorFactory {
    static final String PROCESSOR_TYPE_WORKFLOW = "workflow";
    static final String PROCESSOR_TYPE_SCRIPT = "script";
    static final String PROCESSOR_TYPE_SERVICE = "service";
    @Reference
    private WorkflowLauncherHandler workflowLauncherHandler;
    @Reference
    private ScriptInputProcessor scriptInputProcessor;
    @Reference
    private ServiceInputProcessor serviceInputProcessor;
    private Map<String, InputProcessor> processorMap = new HashMap<String, InputProcessor>();

    @Activate
    public void activate() {
        this.processorMap.put("workflow", this.workflowLauncherHandler);
        this.processorMap.put("script", this.scriptInputProcessor);
        this.processorMap.put("service", this.serviceInputProcessor);
    }

    @Deactivate
    public void deactivate() {
        this.processorMap.clear();
    }

    public Set<String> getValidProcessorTypes() {
        return this.processorMap.keySet();
    }

    public void processInputs(String jobId, WatchFolderConfiguration config, File source, Map<String, File> inputs) throws Exception {
        InputProcessor ip = this.processorMap.get(config.getInputProcessorType());
        Object resp = ip.processInputs(jobId, config, source, inputs);
        if (ip.isSynch()) {
            Map docMap = (Map)resp;
            FileResultHandlerWrapper resultHandler = new FileResultHandlerWrapper(config);
            resultHandler.handleSuccess(docMap, source, jobId);
        }
    }

    protected void bindWorkflowLauncherHandler(WorkflowLauncherHandler workflowLauncherHandler) {
        this.workflowLauncherHandler = workflowLauncherHandler;
    }

    protected void unbindWorkflowLauncherHandler(WorkflowLauncherHandler workflowLauncherHandler) {
        if (this.workflowLauncherHandler == workflowLauncherHandler) {
            this.workflowLauncherHandler = null;
        }
    }

    protected void bindScriptInputProcessor(ScriptInputProcessor scriptInputProcessor) {
        this.scriptInputProcessor = scriptInputProcessor;
    }

    protected void unbindScriptInputProcessor(ScriptInputProcessor scriptInputProcessor) {
        if (this.scriptInputProcessor == scriptInputProcessor) {
            this.scriptInputProcessor = null;
        }
    }

    protected void bindServiceInputProcessor(ServiceInputProcessor serviceInputProcessor) {
        this.serviceInputProcessor = serviceInputProcessor;
    }

    protected void unbindServiceInputProcessor(ServiceInputProcessor serviceInputProcessor) {
        if (this.serviceInputProcessor == serviceInputProcessor) {
            this.serviceInputProcessor = null;
        }
    }
}