ProductAssetHandlerProviderImpl.java 3.18 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Property
 *  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.OsgiUtil
 *  org.osgi.service.component.ComponentContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.commerce.impl.asset;

import com.adobe.cq.commerce.api.asset.ProductAssetHandler;
import com.adobe.cq.commerce.api.asset.ProductAssetHandlerProvider;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.List;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
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.OsgiUtil;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(immediate=1, metatype=1, label="Adobe CQ Commerce Product Asset Handler Provider", description="Provides the available product assets handlers.")
@Service(value={ProductAssetHandlerProvider.class})
@Property(name="service.description", value={"Provides the available product assets handlers"})
public class ProductAssetHandlerProviderImpl
implements ProductAssetHandlerProvider {
    private static final Logger log = LoggerFactory.getLogger(ProductAssetHandlerProviderImpl.class);
    static final String DEFAULT_FALLBACK_HANDLER = "static-image";
    @Property(label="%Fallback Handler", description="%Name of the fallback handler", value={"static-image"})
    private static final String FALLBACK_HANDLER_PROP_NAME = "cq.commerce.asset.handler.fallback";
    @Reference(referenceInterface=ProductAssetHandler.class, bind="bindProductAssetHandler", unbind="unbindProductAssetHandler", cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)
    private List<ProductAssetHandler> productAssetHandlers = new ArrayList<ProductAssetHandler>();
    private String fallbackHandler;

    @Activate
    protected void activate(ComponentContext context) throws Exception {
        this.fallbackHandler = OsgiUtil.toString(context.getProperties().get("cq.commerce.asset.handler.fallback"), (String)"static-image");
    }

    protected void bindProductAssetHandler(ProductAssetHandler handler, Map<?, ?> properties) {
        this.productAssetHandlers.add(handler);
    }

    protected void unbindProductAssetHandler(ProductAssetHandler handler, Map<?, ?> properties) {
        this.productAssetHandlers.remove(handler);
    }

    @Override
    public List<ProductAssetHandler> getProductAssetHandlers() {
        return this.productAssetHandlers;
    }

    @Override
    public String getFallbackHandler() {
        return this.fallbackHandler;
    }
}