PIMAdapterFactory.java
2.12 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.adapter.AdapterFactory
* org.apache.sling.api.resource.ResourceResolver
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.commerce.pim.impl;
import com.adobe.cq.commerce.pim.api.ProductInfoManager;
import com.adobe.cq.commerce.pim.impl.JcrProductInfoManagerImpl;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(specVersion="1.1")
@Service
@Property(name="service.description", value={"Default adapter factory for commerce PIM entities"})
public class PIMAdapterFactory
implements AdapterFactory {
private final Logger log = LoggerFactory.getLogger(PIMAdapterFactory.class);
private static final Class<ProductInfoManager> PIM_CLASS = ProductInfoManager.class;
@Property(name="adapters")
protected static final String[] ADAPTER_CLASSES = new String[]{PIM_CLASS.getName()};
@Property(name="adaptables")
protected static final String[] ADAPTABLE_CLASSES = new String[]{ResourceResolver.class.getName()};
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (adaptable instanceof ResourceResolver) {
return this.getAdapter((ResourceResolver)adaptable, type);
}
this.log.warn("Unable to handle adaptable {}", (Object)adaptable.getClass().getName());
return null;
}
private <AdapterType> AdapterType getAdapter(ResourceResolver resolver, Class<AdapterType> type) {
if (type == PIM_CLASS) {
return (AdapterType)new JcrProductInfoManagerImpl(resolver);
}
this.log.warn("Unable to adapt resolver to requested type {}", (Object)type.getName());
return null;
}
}