ProductAssetHandlerProviderImpl.java
3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* 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;
}
}