BaseActionFactory.java 2.07 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.api.WCMException
 *  com.day.cq.wcm.msm.api.LiveAction
 *  com.day.cq.wcm.msm.api.LiveActionFactory
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ValueMap
 *  org.apache.sling.api.wrappers.ValueMapDecorator
 */
package com.day.cq.wcm.msm.commons;

import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveActionFactory;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public abstract class BaseActionFactory<ActionType extends LiveAction>
implements LiveActionFactory<ActionType> {
    protected abstract ActionType newActionInstance(ValueMap var1) throws WCMException;

    public ActionType createAction(Resource resource) throws WCMException {
        ValueMap resourceMap = null;
        if (resource != null) {
            resourceMap = (ValueMap)resource.adaptTo(ValueMap.class);
        }
        Map<String, Object> result = this.mergeConfigs(this.getFactoryConfig(), (Map<String, Object>)resourceMap);
        return this.newActionInstance((ValueMap)new ValueMapDecorator(result));
    }

    protected Dictionary getFactoryConfig() {
        return null;
    }

    private Map<String, Object> mergeConfigs(Dictionary base, Map<String, Object> overrides) {
        HashMap<String, Object> result = new HashMap<String, Object>();
        if (base != null) {
            Enumeration<K> enumeration = base.keys();
            while (enumeration.hasMoreElements()) {
                K key = enumeration.nextElement();
                result.put(key.toString(), base.get(key));
            }
        }
        if (overrides != null) {
            result.putAll(overrides);
        }
        return result;
    }
}