WatchFolderConfigCache.java 2.3 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Service
 */
package com.adobe.aemfd.watchfolder.config;

import com.adobe.aemfd.watchfolder.config.WatchFolderConfiguration;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
@Component(metatype=0, immediate=1)
@Service(value={WatchFolderConfigCache.class})
public class WatchFolderConfigCache {
    private Map<String, WatchFolderConfiguration> configMap = new HashMap<String, WatchFolderConfiguration>();

    public WatchFolderConfiguration getConfiguration(String wfId) throws Exception {
        WatchFolderConfiguration res = this.configMap.get(wfId);
        if (res == null) {
            throw new Exception("No configuration found for watch-folder " + wfId);
        }
        return res;
    }

    public boolean containsConfiguration(String wfId) {
        return this.configMap.containsKey(wfId);
    }

    public Collection<WatchFolderConfiguration> getAllConfigurations() {
        return this.configMap.values();
    }

    public void addConfiguration(WatchFolderConfiguration c) throws Exception {
        String cid = c.getId();
        if (this.configMap.containsKey(cid)) {
            throw new Exception("Watch-folder configuration with ID " + cid + " already registered!");
        }
        this.configMap.put(cid, c);
    }

    public WatchFolderConfiguration updateConfiguration(WatchFolderConfiguration c) throws Exception {
        String cid = c.getId();
        if (!this.configMap.containsKey(cid)) {
            throw new Exception("No watch-folder configuration found with ID " + cid);
        }
        return this.configMap.put(cid, c);
    }

    public WatchFolderConfiguration deleteConfiguration(String wfId) throws Exception {
        WatchFolderConfiguration c = this.configMap.remove(wfId);
        if (c == null) {
            throw new Exception("No watch-folder configuration found with ID " + wfId);
        }
        return c;
    }

    public void clearAllConfigurations() {
        this.configMap.clear();
    }
}