ConfigurationHandlerFactory.java 2.38 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Property
 *  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.watchfolder.config.WatchFolderConfiguration;
import com.adobe.aemfd.watchfolder.spi.ConfigurationHandler;
import com.adobe.aemfd.watchfolder.workflow.WorkflowConfigurationHandler;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Property;
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;

@Component(immediate=1)
@Service(value={ConfigurationHandlerFactory.class})
public class ConfigurationHandlerFactory {
    @Reference
    private WorkflowConfigurationHandler workflowConfigurationHandler;
    private Map<String, ConfigurationHandler> handlerMap = new HashMap<String, ConfigurationHandler>();

    @Activate
    public void activate() {
        this.handlerMap.put("workflow", this.workflowConfigurationHandler);
    }

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

    private ConfigurationHandler getHandler(Property p) throws Exception {
        String pName = p.getName();
        int idx = pName.indexOf(46);
        if (idx != -1) {
            String pType = pName.substring(0, idx);
            return this.handlerMap.get(pType);
        }
        return null;
    }

    public boolean enhanceConfiguration(WatchFolderConfiguration config, Property p) throws Exception {
        ConfigurationHandler ch = this.getHandler(p);
        return ch != null && ch.enhanceConfiguration(config, p);
    }

    protected void bindWorkflowConfigurationHandler(WorkflowConfigurationHandler workflowConfigurationHandler) {
        this.workflowConfigurationHandler = workflowConfigurationHandler;
    }

    protected void unbindWorkflowConfigurationHandler(WorkflowConfigurationHandler workflowConfigurationHandler) {
        if (this.workflowConfigurationHandler == workflowConfigurationHandler) {
            this.workflowConfigurationHandler = null;
        }
    }
}